From 8c21c56db4a154fef7cad96f8afe17e653789f52 Mon Sep 17 00:00:00 2001 From: JargeZ Date: Tue, 30 Jul 2024 21:15:13 +1000 Subject: [PATCH] All the variables --- README.md | 37 +++++++++++++++++++------------------ action.yml | 6 +++++- entrypoint.sh | 34 ++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b264402..d8a8f4b 100644 --- a/README.md +++ b/README.md @@ -8,24 +8,25 @@ If you have an existing `fly.toml` in your repo, this action will copy it with a ## Inputs -| name | description | -| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| name | description | +| ---------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `name` | The name of the Fly app. Alternatively, set the env `FLY_APP`. For safety, must include the PR number. Example: `myapp-pr-${{ github.event.number }}`. Defaults to `pr-{number}-{repo_org}-{repo_name}`. | -| `image` | Optional pre-existing Docker image to use | -| `config` | Optional path to a custom Fly toml config. Config path should be relative to `path` parameter, if specified. | -| `region` | Which Fly region to run the app in. Alternatively, set the env `FLY_REGION`. Defaults to `iad`. | -| `org` | Which Fly organization to launch the app under. Alternatively, set the env `FLY_ORG`. Defaults to `personal`. | -| `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 | -| `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. | -| `memory` | Set app VM memory in megabytes. Default 256. | -| `ha` | Create spare machines that increases app availability. Default `false`. | -| `allow_unsafe_name` | Allow a name that does not contain a PR number. Useful for deploying preview environments across multiple repo with reusable pipelines. Default `false`. | -| `build_args` | Build arguments to pass to the Docker build. Separate multiple arguments with a semicolon. `FOO=bar;BAZ=qux` | +| `image` | Optional pre-existing Docker image to use | +| `config` | Optional path to a custom Fly toml config. Config path should be relative to `path` parameter, if specified. | +| `region` | Which Fly region to run the app in. Alternatively, set the env `FLY_REGION`. Defaults to `iad`. | +| `org` | Which Fly organization to launch the app under. Alternatively, set the env `FLY_ORG`. Defaults to `personal`. | +| `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 | +| `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. | +| `memory` | Set app VM memory in megabytes. Default 256. | +| `ha` | Create spare machines that increases app availability. Default `false`. | +| `allow_unsafe_name` | Allow a name that does not contain a PR number. Useful for deploying preview environments across multiple repo with reusable pipelines. Default `false`. | +| `build_args` | Optional Docker --build-arg Separate multiple arguments with a space | +| `build_secrets` | Optional Docker --build-secret | ## Required Secrets @@ -63,7 +64,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 diff --git a/action.yml b/action.yml index b5fdbb0..f8fb2d7 100644 --- a/action.yml +++ b/action.yml @@ -42,4 +42,8 @@ inputs: description: Allow a name that does not contain a PR number. Useful for deploying preview environments across multiple repo with reusable pipelines (default false) default: false build_args: - description: Build arguments to pass to the Docker build. Separate multiple arguments with a semicolon. FOO=bar;BAZ=qux + description: Optional Docker --build-arg + build_secrets: + description: Optional Docker --build-secret + environment: + description: Optional environment variables to set on the app. Separate multiple env vars with a space \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 0f734d7..e26d6e8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -24,6 +24,9 @@ region="${INPUT_REGION:-${FLY_REGION:-iad}}" org="${INPUT_ORG:-${FLY_ORG:-personal}}" image="$INPUT_IMAGE" config="${INPUT_CONFIG:-fly.toml}" +build_args="" +build_secrets="" +runtime_environment="" if ! echo "$app" | grep "$PR_NUMBER"; then if [ "$INPUT_ALLOW_UNSAFE_NAME" != "true" ]; then @@ -39,11 +42,31 @@ if [ "$EVENT_TYPE" = "closed" ]; then exit 0 fi +#from https://github.com/superfly/fly-pr-review-apps/pull/50 +# FIXME spaces, maybe split by \D+= +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 + +if [ -n "$INPUT_ENVIRONMENT" ]; then + for ARG in $(echo "$INPUT_ENVIRONMENT" | sed 's/\b\(\w\+\)=/\n\1=/g'); do + runtime_environment="$runtime_environment --env ${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} ${runtime_environment} # Restore the original config file cp "$config.bak" "$config" fi @@ -56,17 +79,12 @@ if [ -n "$INPUT_POSTGRES" ]; then flyctl postgres attach "$INPUT_POSTGRES" --app "$app" || true fi -# create --build-arg array -if [ -n "$INPUT_BUILD_ARGS" ]; then - BUILD_ARGS="--build-arg ${INPUT_BUILD_ARGS//;/ --build-arg }" -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" $BUILD_ARGS + flyctl deploy --config "$config" --app "$app" --regions "$region" --image "$image" --strategy immediate --ha=$INPUT_HA ${build_args} ${build_secrets} ${runtime_environment} --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" $BUILD_ARGS + flyctl deploy --config "$config" --app "$app" --regions "$region" --image "$image" --strategy immediate --ha=$INPUT_HA ${build_args} ${build_secrets} ${runtime_environment} --vm-cpu-kind "$INPUT_CPUKIND" --vm-cpus $INPUT_CPU --vm-memory "$INPUT_MEMORY" fi # Make some info available to the GitHub workflow.