diff --git a/README.md b/README.md index 04f6d4e..bbcd47c 100644 --- a/README.md +++ b/README.md @@ -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. | @@ -61,7 +63,7 @@ jobs: - name: Deploy id: deploy - uses: superfly/fly-pr-review-apps@1.0.0 + uses: superfly/fly-pr-review-apps@1.3.0 ``` ## Cleaning up GitHub environments @@ -89,7 +91,7 @@ jobs: - name: Deploy app id: deploy - uses: superfly/fly-pr-review-apps@1.0.0 + uses: superfly/fly-pr-review-apps@1.3.0 - name: Clean up GitHub environment uses: strumwolf/delete-deployment-environment@v2 @@ -113,7 +115,7 @@ steps: - name: Deploy app id: deploy - uses: superfly/fly-pr-review-apps@1.0.0 + uses: superfly/fly-pr-review-apps@1.3.0 with: postgres: myapp-postgres-staging-apps ``` @@ -129,7 +131,7 @@ steps: - uses: actions/checkout@v4 - name: Deploy redis - uses: superfly/fly-pr-review-apps@1.0.0 + uses: superfly/fly-pr-review-apps@1.3.0 with: update: false # Don't need to re-deploy redis when the PR is updated path: redis # Keep fly.toml in a subdirectory to avoid confusing flyctl @@ -138,7 +140,7 @@ steps: - name: Deploy app id: deploy - uses: superfly/fly-pr-review-apps@1.0.0 + uses: superfly/fly-pr-review-apps@1.3.0 with: name: pr-${{ github.event.number }}-myapp-app ``` diff --git a/action.yml b/action.yml index 0748d75..20d1d18 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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: diff --git a/entrypoint.sh b/entrypoint.sh index 6719a6f..8a958e1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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." @@ -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 @@ -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" --regions "$region" --image "$image" --strategy immediate --ha=$INPUT_HA --vm-size "$INPUT_VMSIZE" + flyctl deploy --config "$config" --app "$app" --regions "$region" --image "$image" --strategy immediate --ha=$INPUT_HA ${build_args} ${build_secrets} --vm-size "$INPUT_VMSIZE" else - flyctl deploy --config "$config" --app "$app" --regions "$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" --regions "$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.