From 1f6479d879746730dec63a05173db45995187354 Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 17:15:00 +1000 Subject: [PATCH 1/7] Set docker context explicitly --- .github/workflows/deploy_api.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index 79c336e..70c928b 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -2,7 +2,7 @@ name: Deploy API on: push: - branches: ['main'] + branches: ['chore/setup-workflow'] paths: ['api/**'] env: @@ -13,10 +13,6 @@ jobs: name: Build Docker image and push to GitHub Container Registry runs-on: ubuntu-latest - defaults: - run: - working-directory: api - permissions: contents: read packages: write @@ -34,7 +30,7 @@ jobs: images: ${{ env.REGISTRY }}/${{ github.repository }}/api - uses: docker/build-push-action@v4 with: - context: . + context: ./api push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} @@ -52,7 +48,7 @@ jobs: key: ${{ secrets.EC2_SSH_KEY }} script: | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} - docker pull ${{ env.REGISTRY }}/${{ github.repository }}/api:latest + docker pull ${{ env.REGISTRY }}/${{ github.repository }}/api:main docker stop crabfit-api docker rm crabfit-api - docker run -d -p 3000:3000 --name crabfit-api --env-file ./.env ${{ env.REGISTRY }}/${{ github.repository }}/api:latest + docker run -d -p 3000:3000 --name crabfit-api --env-file ./.env ${{ env.REGISTRY }}/${{ github.repository }}/api:main From 8f2c7bb1c076411145bb97aebcd8c55823c8a769 Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 17:17:00 +1000 Subject: [PATCH 2/7] Include workflow file in deps --- .github/workflows/deploy_api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index 70c928b..10e0fb2 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -3,7 +3,7 @@ name: Deploy API on: push: branches: ['chore/setup-workflow'] - paths: ['api/**'] + paths: ['api/**', 'workflows/deploy_api.yml'] env: REGISTRY: ghcr.io From fcc72b58ea13c61b119263a5d0b63c04231ae063 Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 17:18:06 +1000 Subject: [PATCH 3/7] Use correct file path --- .github/workflows/deploy_api.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index 10e0fb2..676b701 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -2,8 +2,11 @@ name: Deploy API on: push: - branches: ['chore/setup-workflow'] - paths: ['api/**', 'workflows/deploy_api.yml'] + branches: + - chore/setup-workflow + paths: + - api/** + - .github/workflows/deploy_api.yml env: REGISTRY: ghcr.io From bc6e8dd2e0c783cb6d24e31e55650c28f51d6822 Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 17:37:35 +1000 Subject: [PATCH 4/7] Use ghcr tag directly --- .github/workflows/deploy_api.yml | 9 ++++++--- README.md | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index 676b701..32b097e 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -20,6 +20,9 @@ jobs: contents: read packages: write + outputs: + tag: ${{ steps.meta.outputs.tags[0] }} + steps: - uses: actions/checkout@v3 - uses: docker/login-action@v2 @@ -39,7 +42,7 @@ jobs: labels: ${{ steps.meta.outputs.labels }} deploy: - needs: [build-and-push] + needs: build-and-push name: Deploy to EC2 runs-on: ubuntu-latest @@ -51,7 +54,7 @@ jobs: key: ${{ secrets.EC2_SSH_KEY }} script: | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} - docker pull ${{ env.REGISTRY }}/${{ github.repository }}/api:main + docker pull ${{ needs.build-and-push.outputs.tag }} docker stop crabfit-api docker rm crabfit-api - docker run -d -p 3000:3000 --name crabfit-api --env-file ./.env ${{ env.REGISTRY }}/${{ github.repository }}/api:main + docker run -d -p 3000:3000 --name crabfit-api --env-file ./.env ${{ needs.build-and-push.outputs.tag }} diff --git a/README.md b/README.md index 8ba0b35..8526b8b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Crab Fit avatar +# Crab Fit avatar Align your schedules to find the perfect time that works for everyone. Licensed under the GNU GPLv3. From 0442d9714c833f606a748cdf1e86e7c5aa7681bb Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 18:14:14 +1000 Subject: [PATCH 5/7] Remove array index --- .github/workflows/deploy_api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index 32b097e..d3590a5 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -21,7 +21,7 @@ jobs: packages: write outputs: - tag: ${{ steps.meta.outputs.tags[0] }} + tag: ${{ steps.meta.outputs.tags }} steps: - uses: actions/checkout@v3 From 4e7ae85a353807c2e0e265c807f49feb32aa22fb Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 20:22:15 +1000 Subject: [PATCH 6/7] Reconfigure to use Fly.io, update workflow --- .github/workflows/deploy_api.yml | 50 ++++++-------------------------- api/fly.toml | 15 ++++++++++ 2 files changed, 24 insertions(+), 41 deletions(-) create mode 100644 api/fly.toml diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index d3590a5..18aeca4 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -8,53 +8,21 @@ on: - api/** - .github/workflows/deploy_api.yml -env: - REGISTRY: ghcr.io - jobs: build-and-push: - name: Build Docker image and push to GitHub Container Registry + name: Deploy to Fly.io runs-on: ubuntu-latest + defaults: + run: + working-directory: api + permissions: contents: read - packages: write - - outputs: - tag: ${{ steps.meta.outputs.tags }} steps: - uses: actions/checkout@v3 - - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - uses: docker/metadata-action@v4 - id: meta - with: - images: ${{ env.REGISTRY }}/${{ github.repository }}/api - - uses: docker/build-push-action@v4 - with: - context: ./api - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - deploy: - needs: build-and-push - name: Deploy to EC2 - runs-on: ubuntu-latest - - steps: - - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_SSH_KEY }} - script: | - docker login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} - docker pull ${{ needs.build-and-push.outputs.tag }} - docker stop crabfit-api - docker rm crabfit-api - docker run -d -p 3000:3000 --name crabfit-api --env-file ./.env ${{ needs.build-and-push.outputs.tag }} + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/api/fly.toml b/api/fly.toml new file mode 100644 index 0000000..4b35a46 --- /dev/null +++ b/api/fly.toml @@ -0,0 +1,15 @@ +# fly.toml app configuration file generated for crabfit-api on 2023-05-16T19:42:08+10:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# +# Note: this is used to deploy the production Crab Fit API to Fly.io + +app = "crabfit-api" +primary_region = "syd" + +[http_service] + internal_port = 3000 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 From 75e99e694522efaecb4520fdace49b88c9eb8ef2 Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 20:24:54 +1000 Subject: [PATCH 7/7] Update branch to main --- .github/workflows/deploy_api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index 18aeca4..45cb235 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -3,7 +3,7 @@ name: Deploy API on: push: branches: - - chore/setup-workflow + - main paths: - api/** - .github/workflows/deploy_api.yml