Skip to content

Commit

Permalink
Add --build-arg and --build-secret
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericrous committed Mar 30, 2024
1 parent 280ea61 commit 5e9c40f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ If you have an existing `fly.toml` in your repo, this action will copy it with a
| `path` | Path to run the `flyctl` commands from. Useful if you have an existing `fly.toml` in a subdirectory. |
| `postgres` | Optional name of an existing Postgres cluster to `flyctl postgres attach` to. |
| `update` | Whether or not to update this Fly app when the PR is updated. Default `true`. |
| `secrets` | Secrets to be set on the app. Separate multiple secrets with a space |
| `secrets` | Secrets to be set on the app at runtime. Separate multiple secrets with a space |
| build_args | Optional Docker --build-arg |
| build_secrets | Optional Docker --build-secret |
| `vmsize` | Set app VM to a named size, eg. shared-cpu-1x, dedicated-cpu-1x, dedicated-cpu-2x etc. Takes precedence over cpu, cpu kind, and memory inputs. |
| `cpu` | Set app VM CPU (defaults to 1 cpu). Default 1. |
| `cpukind` | Set app VM CPU kind - shared or performance. Default shared. |
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
description: Optional pre-existing Docker image to use
config:
description: Optional path to a custom Fly toml config. Config path should be relative to `path` parameter, if specified.
build_args:
description: Optional Docker --build-arg
build_secrets:
description: Optional Docker --build-secret
region:
description: Region to launch the app in (alternatively, set the env FLY_REGION)
org:
Expand All @@ -23,7 +27,7 @@ inputs:
postgres:
description: Optionally attach the app to a pre-existing Postgres cluster on Fly
secrets:
description: Secrets to be set on the app. Separate multiple secrets with a space
description: Secrets to be set on the app at runtime. Separate multiple secrets with a space
vmsize:
description: Set app VM to a named size, eg. shared-cpu-1x, dedicated-cpu-1x, dedicated-cpu-2x etc. Takes precedence over cpu, cpu kind, and memory inputs.
cpu:
Expand Down
21 changes: 18 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ region="${INPUT_REGION:-${FLY_REGION:-iad}}"
org="${INPUT_ORG:-${FLY_ORG:-personal}}"
image="$INPUT_IMAGE"
config="${INPUT_CONFIG:-fly.toml}"
build_args=""
build_secrets=""

if ! echo "$app" | grep "$PR_NUMBER"; then
echo "For safety, this action requires the app's name to contain the PR number."
Expand All @@ -36,14 +38,27 @@ if [ "$EVENT_TYPE" = "closed" ]; then
exit 0
fi

if [ -n "$INPUT_BUILD_ARGS" ]; then
for ARG in $(echo "$INPUT_BUILD_ARGS" | tr " " "\n"); do
build_args="$build_args --build-arg ${ARG}"
done
fi

if [ -n "$INPUT_BUILD_SECRETS" ]; then
for ARG in $(echo "$INPUT_BUILD_SECRETS" | tr " " "\n"); do
build_secrets="$build_secrets --build-secret ${ARG}"
done
fi

# Deploy the Fly app, creating it first if needed.
if ! flyctl status --app "$app"; then
# Backup the original config file since 'flyctl launch' messes up the [build.args] section
cp "$config" "$config.bak"
flyctl launch --no-deploy --copy-config --name "$app" --image "$image" --region "$region" --org "$org"
flyctl launch --no-deploy --copy-config --name "$app" --image "$image" --region "$region" --org "$org" ${build_args} ${build_secrets}
# Restore the original config file
cp "$config.bak" "$config"
fi

if [ -n "$INPUT_SECRETS" ]; then
echo $INPUT_SECRETS | tr " " "\n" | flyctl secrets import --app "$app"
fi
Expand All @@ -56,9 +71,9 @@ fi
# Trigger the deploy of the new version.
echo "Contents of config $config file: " && cat "$config"
if [ -n "$INPUT_VM" ]; then
flyctl deploy --config "$config" --app "$app" --region "$region" --image "$image" --strategy immediate --ha=$INPUT_HA --vm-size "$INPUT_VMSIZE"
flyctl deploy --config "$config" --app "$app" --region "$region" --image "$image" --strategy immediate --ha=$INPUT_HA ${build_args} ${build_secrets} --vm-size "$INPUT_VMSIZE"
else
flyctl deploy --config "$config" --app "$app" --region "$region" --image "$image" --strategy immediate --ha=$INPUT_HA --vm-cpu-kind "$INPUT_CPUKIND" --vm-cpus $INPUT_CPU --vm-memory "$INPUT_MEMORY"
flyctl deploy --config "$config" --app "$app" --region "$region" --image "$image" --strategy immediate --ha=$INPUT_HA ${build_args} ${build_secrets} --vm-cpu-kind "$INPUT_CPUKIND" --vm-cpus $INPUT_CPU --vm-memory "$INPUT_MEMORY"
fi

# Make some info available to the GitHub workflow.
Expand Down

0 comments on commit 5e9c40f

Please sign in to comment.