Created
August 2, 2023 20:41
-
-
Save mattslack/86d675f0553b4466ce16ab2f3cad9a0e to your computer and use it in GitHub Desktop.
Deploy to fly.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
generate_label () { | |
SHA=$(git rev-parse --short HEAD) | |
if [ -z "$(git status --porcelain | wc -l)" ]; then | |
STATE="clean" | |
else | |
STATE="dirty" | |
fi | |
LABEL="deployment-${SHA}-${STATE}" | |
} | |
generate_label | |
if [ $# -eq 1 ]; then | |
if [[ "$1" =~ ^(-)?(\?|h(elp)?) ]]; then | |
echo "" | |
echo " Deploy to fly.io. The image label will include the hash of HEAD, and either 'clean' or 'dirty' depending on if there are uncommitted changes or not." | fmt | |
echo "" | |
echo " Usage: deploy [OPTS]" | |
echo "" | |
echo " With no options passed the default is to deploy to staging." | |
echo "" | |
echo " OPTS:" | |
echo " production Deploy to production. You must be on main with no changes" | |
echo " -h, -?, -help Display this help message" | |
echo "" | |
exit 0 | |
fi | |
TARGET_ENV=$1 | |
if [ "$TARGET_ENV" == "production" ]; then | |
if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then | |
echo "Exiting: Not on main" | |
exit 1 | |
fi | |
if [ "$STATE" == "dirty" ]; then | |
echo "Exiting: You have uncommitted changes" | |
exit 1 | |
fi | |
time fly deploy --remote-only --config fly.production.toml --image-label="${LABEL}" | |
else | |
if [ -f "fly.${TARGET_ENV}.toml" ]; then | |
time fly deploy --remote-only --config "fly.${TARGET_ENV}.toml" --image-label="${LABEL}" | |
else | |
echo " Exiting: Config file 'fly.${TARGET_ENV}.toml' was not found" | |
exit 1 | |
fi | |
fi | |
else | |
echo "" | |
time fly deploy --remote-only --config fly.staging.toml --image-label="${LABEL}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment