Create workflow to deploy the API on EC2
This commit is contained in:
parent
862ea1148b
commit
44288f99d1
58
.github/workflows/deploy_api.yml
vendored
Normal file
58
.github/workflows/deploy_api.yml
vendored
Normal file
|
|
@ -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
|
||||
37
.github/workflows/deploy_backend.yml
vendored
37
.github/workflows/deploy_backend.yml
vendored
|
|
@ -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
|
||||
Loading…
Reference in a new issue