From 44288f99d1a7e4b63e7f90718ecf854c62e336fd Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Tue, 16 May 2023 16:57:19 +1000 Subject: [PATCH] Create workflow to deploy the API on EC2 --- .github/workflows/deploy_api.yml | 58 +++++++++++++++++++ .github/workflows/deploy_backend.yml | 37 ------------ .../public/i18n/hu-HU/privacy.json | 0 3 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/deploy_api.yml delete mode 100644 .github/workflows/deploy_backend.yml rename {crabfit-frontend => frontend}/public/i18n/hu-HU/privacy.json (100%) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml new file mode 100644 index 0000000..79c336e --- /dev/null +++ b/.github/workflows/deploy_api.yml @@ -0,0 +1,58 @@ +name: Deploy API + +on: + push: + branches: ['main'] + paths: ['api/**'] + +env: + REGISTRY: ghcr.io + +jobs: + build-and-push: + name: Build Docker image and push to GitHub Container Registry + runs-on: ubuntu-latest + + defaults: + run: + working-directory: api + + permissions: + contents: read + packages: write + + 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: . + 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 ${{ env.REGISTRY }}/${{ github.repository }}/api:latest + 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 diff --git a/.github/workflows/deploy_backend.yml b/.github/workflows/deploy_backend.yml deleted file mode 100644 index e9e34c5..0000000 --- a/.github/workflows/deploy_backend.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Deploy Backend - -on: - push: - branches: ['main'] - paths: ['backend/**'] - -jobs: - deploy: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: backend - - permissions: - contents: read - id-token: write - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 17 - cache: yarn - cache-dependency-path: '**/yarn.lock' - - run: yarn install --immutable - - run: yarn build - - id: auth - uses: google-github-actions/auth@v0 - with: - credentials_json: '${{ secrets.GCP_SA_KEY }}' - - id: deploy - uses: google-github-actions/deploy-appengine@v0 - with: - working_directory: backend - version: v1 diff --git a/crabfit-frontend/public/i18n/hu-HU/privacy.json b/frontend/public/i18n/hu-HU/privacy.json similarity index 100% rename from crabfit-frontend/public/i18n/hu-HU/privacy.json rename to frontend/public/i18n/hu-HU/privacy.json