Skip to content

Commit

Permalink
All the variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JargeZ committed Jul 30, 2024
1 parent 2c6343f commit 8c21c56
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 26 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 8c21c56

Please sign in to comment.