From 3da3dc23cc0ce5d97e0ad1baca1a9e861aca1c39 Mon Sep 17 00:00:00 2001 From: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com> Date: Mon, 2 Sep 2024 19:15:29 +0200 Subject: [PATCH] CI: Fix Fly.io review apps (#965) Signed-off-by: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com> --- .github/actions/fly-pr-review-apps/Dockerfile | 9 -- .github/actions/fly-pr-review-apps/action.yml | 44 ---------- .../actions/fly-pr-review-apps/entrypoint.sh | 86 ------------------- .../{deply-review.yml => deploy-review.yml} | 9 +- .github/workflows/{deply.yml => deploy.yml} | 0 pnpm-lock.yaml | 3 - 6 files changed, 4 insertions(+), 147 deletions(-) delete mode 100644 .github/actions/fly-pr-review-apps/Dockerfile delete mode 100644 .github/actions/fly-pr-review-apps/action.yml delete mode 100755 .github/actions/fly-pr-review-apps/entrypoint.sh rename .github/workflows/{deply-review.yml => deploy-review.yml} (85%) rename .github/workflows/{deply.yml => deploy.yml} (100%) diff --git a/.github/actions/fly-pr-review-apps/Dockerfile b/.github/actions/fly-pr-review-apps/Dockerfile deleted file mode 100644 index 6371b33a9..000000000 --- a/.github/actions/fly-pr-review-apps/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -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"] diff --git a/.github/actions/fly-pr-review-apps/action.yml b/.github/actions/fly-pr-review-apps/action.yml deleted file mode 100644 index 20d1d185e..000000000 --- a/.github/actions/fly-pr-review-apps/action.yml +++ /dev/null @@ -1,44 +0,0 @@ -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 diff --git a/.github/actions/fly-pr-review-apps/entrypoint.sh b/.github/actions/fly-pr-review-apps/entrypoint.sh deleted file mode 100755 index 8a958e166..000000000 --- a/.github/actions/fly-pr-review-apps/entrypoint.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/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 diff --git a/.github/workflows/deply-review.yml b/.github/workflows/deploy-review.yml similarity index 85% rename from .github/workflows/deply-review.yml rename to .github/workflows/deploy-review.yml index 3fa343170..24e787217 100644 --- a/.github/workflows/deply-review.yml +++ b/.github/workflows/deploy-review.yml @@ -13,7 +13,7 @@ env: jobs: review_app: - name: 🚀 Deploy app to Fly.io + name: 🚀 Deploy Review app to Fly.io runs-on: ubuntu-latest continue-on-error: true outputs: @@ -35,12 +35,11 @@ jobs: - name: Deploy PR app to Fly.io id: deploy - uses: ./.github/actions/fly-pr-review-apps + uses: suddenlyGiovanni/fly-pr-review-apps@ci/with-secrets with: - path: './apps/web' - config: ./fly.review.toml + config: ./apps/web/fly.review.toml name: suddenlygiovanni-dev-${{ github.event.number }} - secrets: GH_PACKAGES_TOKEN=${{ secrets.GH_PACKAGES_TOKEN }} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + secrets: GITHUB_TOKEN=${{ secrets.OCTOKIT_RESUME_TOKEN }} build_args: GH_PACKAGES_TOKEN=${{ secrets.GH_PACKAGES_TOKEN }} - name: 🗑 Delete deployment environment diff --git a/.github/workflows/deply.yml b/.github/workflows/deploy.yml similarity index 100% rename from .github/workflows/deply.yml rename to .github/workflows/deploy.yml diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ac8bef365..0d9680e41 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4370,7 +4370,6 @@ packages: glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} - deprecated: Glob versions prior to v9 are no longer supported globals@11.12.0: resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==} @@ -4493,7 +4492,6 @@ packages: inflight@1.0.6: resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} - deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -5824,7 +5822,6 @@ packages: rimraf@2.6.3: resolution: {integrity: sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==} - deprecated: Rimraf versions prior to v4 are no longer supported hasBin: true rollup@4.21.2: