Merge pull request #258 from GRA0007/chore/setup-workflow

Setup API deployment workflow
This commit is contained in:
Benji Grant 2023-05-16 20:25:04 +10:00 committed by GitHub
commit 49c6281b74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 41 deletions

View file

@ -2,15 +2,15 @@ name: Deploy API
on: on:
push: push:
branches: ['main'] branches:
paths: ['api/**'] - main
paths:
env: - api/**
REGISTRY: ghcr.io - .github/workflows/deploy_api.yml
jobs: jobs:
build-and-push: build-and-push:
name: Build Docker image and push to GitHub Container Registry name: Deploy to Fly.io
runs-on: ubuntu-latest runs-on: ubuntu-latest
defaults: defaults:
@ -19,40 +19,10 @@ jobs:
permissions: permissions:
contents: read contents: read
packages: write
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: docker/login-action@v2 - uses: superfly/flyctl-actions/setup-flyctl@master
with: - run: flyctl deploy --remote-only
registry: ${{ env.REGISTRY }} env:
username: ${{ github.actor }} FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
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

View file

@ -1,4 +1,4 @@
# Crab Fit <img width="100" align="right" src="crabfit-frontend/src/res/logo.svg" alt="avatar"> # Crab Fit <img width="100" align="right" src="frontend/src/res/logo.svg" alt="avatar">
Align your schedules to find the perfect time that works for everyone. Align your schedules to find the perfect time that works for everyone.
Licensed under the GNU GPLv3. Licensed under the GNU GPLv3.

15
api/fly.toml Normal file
View file

@ -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