-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54b1134
commit 49142ef
Showing
11 changed files
with
206 additions
and
121 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM alpine | ||
|
||
RUN apk add --no-cache curl jq | ||
|
||
RUN curl -L https://fly.io/install.sh | FLYCTL_INSTALL=/usr/local sh | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: "PR Review Apps on fly.io" | ||
description: "Deploy temporary apps from pull requests on Fly.io" | ||
author: Fly | ||
branding: | ||
icon: "upload-cloud" | ||
color: "purple" | ||
runs: | ||
using: "docker" | ||
image: "Dockerfile" | ||
inputs: | ||
name: | ||
description: Fly app name | ||
image: | ||
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: | ||
description: Organization to launch the app in (alternatively, set the env FLY_ORG) | ||
path: | ||
description: path to a directory containing a fly.toml to clone | ||
postgres: | ||
description: Optionally attach the app to a pre-existing Postgres cluster on Fly | ||
secrets: | ||
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: | ||
description: Set app VM CPU (defaults to 1 cpu) | ||
default: 1 | ||
cpukind: | ||
description: Set app VM CPU kind - shared or performance. (defaults to shared) | ||
default: shared | ||
memory: | ||
description: Set app VM memory in megabytes (defaults to 256 megabytes) | ||
default: 256 | ||
ha: | ||
description: Create spare machines that increases app availability (default false) | ||
default: false |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/sh -l | ||
|
||
set -ex | ||
|
||
if [ -n "$INPUT_PATH" ]; then | ||
# Allow user to change directories in which to run Fly commands. | ||
cd "$INPUT_PATH" || exit | ||
fi | ||
|
||
PR_NUMBER=$(jq -r .number /github/workflow/event.json) | ||
if [ -z "$PR_NUMBER" ]; then | ||
echo "This action only supports pull_request actions." | ||
exit 1 | ||
fi | ||
|
||
GITHUB_REPOSITORY_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/} | ||
EVENT_TYPE=$(jq -r .action /github/workflow/event.json) | ||
|
||
# Default the Fly app name to pr-{number}-{repo_owner}-{repo_name} | ||
app="${INPUT_NAME:-pr-$PR_NUMBER-$GITHUB_REPOSITORY_OWNER-$GITHUB_REPOSITORY_NAME}" | ||
# Change underscores to hyphens. | ||
app="${app//_/-}" | ||
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." | ||
exit 1 | ||
fi | ||
|
||
# PR was closed - remove the Fly app if one exists and exit. | ||
if [ "$EVENT_TYPE" = "closed" ]; then | ||
flyctl apps destroy "$app" -y || true | ||
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" ${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 | ||
|
||
# Attach postgres cluster to the app if specified. | ||
if [ -n "$INPUT_POSTGRES" ]; then | ||
flyctl postgres attach "$INPUT_POSTGRES" --app "$app" || true | ||
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 ${build_args} ${build_secrets} --vm-size "$INPUT_VMSIZE" | ||
else | ||
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. | ||
flyctl status --app "$app" --json >status.json | ||
hostname=$(jq -r .Hostname status.json) | ||
appid=$(jq -r .ID status.json) | ||
echo "hostname=$hostname" >> $GITHUB_OUTPUT | ||
echo "url=https://$hostname" >> $GITHUB_OUTPUT | ||
echo "id=$appid" >> $GITHUB_OUTPUT | ||
echo "name=$app" >> $GITHUB_OUTPUT |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: 💉Setup the project | ||
description: Perform standard setup and install dependencies using pnpm. | ||
inputs: | ||
github_token: | ||
description: 'GitHub token' | ||
required: true | ||
runs: | ||
using: composite | ||
steps: | ||
- name: 🗂️ Install pnpm | ||
uses: pnpm/action-setup@v3 | ||
with: | ||
package_json_file: 'package.json' | ||
run_install: false | ||
|
||
- name: 🛠️ Install node | ||
uses: actions/setup-node@v4 | ||
with: | ||
cache: 'pnpm' | ||
node-version-file: '.nvmrc' | ||
registry-url: 'https://npm.pkg.github.com' | ||
|
||
- name: 🧩 Install dependencies | ||
shell: bash | ||
env: | ||
NODE_AUTH_TOKEN: ${{ inputs.github_token }} | ||
run: pnpm install --frozen-lockfile --prod=false |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.