ci: add GitHub Actions workflow for automated build and deployment
This commit is contained in:
parent
5f32ec05af
commit
44f64e22cb
1 changed files with 111 additions and 0 deletions
111
.github/workflows/deploy.yml
vendored
Normal file
111
.github/workflows/deploy.yml
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
name: 🚀 Deploy
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request: {}
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
typecheck:
|
||||||
|
name: ʦ TypeScript
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 🛑 Cancel Previous Runs
|
||||||
|
uses: styfle/cancel-workflow-action@0.12.1
|
||||||
|
|
||||||
|
- name: ⬇️ Checkout repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: ⎔ Setup node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: 📥 Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: 🔎 Type check
|
||||||
|
run: npm run typecheck
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: 🐳 Build
|
||||||
|
# only build/deploy main branch on pushes
|
||||||
|
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 🛑 Cancel Previous Runs
|
||||||
|
uses: styfle/cancel-workflow-action@0.12.1
|
||||||
|
|
||||||
|
- name: ⬇️ Checkout repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: 🐳 Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
# Setup cache
|
||||||
|
- name: ⚡️ Cache Docker layers
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/.buildx-cache
|
||||||
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-buildx-
|
||||||
|
|
||||||
|
- name: 🔓 Login to Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ vars.CONTAINER_REGISTRY }}
|
||||||
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: 🗄️ Build and Push to Container Registry
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ vars.CONTAINER_REGISTRY }}/brackt:latest
|
||||||
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
|
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
||||||
|
build-args: |
|
||||||
|
DATABASE_URL=${{ secrets.PROD_DATABASE_URL }}
|
||||||
|
|
||||||
|
# This ugly bit is necessary if you don't want your cache to grow forever
|
||||||
|
# till it hits GitHub's limit of 10GB.
|
||||||
|
# Temp fix
|
||||||
|
# https://github.com/docker/build-push-action/issues/252
|
||||||
|
# https://github.com/moby/buildkit/issues/1896
|
||||||
|
- name: 🚚 Move cache
|
||||||
|
run: |
|
||||||
|
rm -rf /tmp/.buildx-cache
|
||||||
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
name: 🚀 Deploy
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [typecheck, build]
|
||||||
|
# only deploy main/dev branch on pushes
|
||||||
|
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: 🚀 Deploy app to server
|
||||||
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
|
env:
|
||||||
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
CONTAINER_REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
port: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
username: ${{ secrets.DEPLOY_USER }}
|
||||||
|
key: ${{ secrets.DEPLOY_KEY }}
|
||||||
|
envs: REGISTRY_USERNAME,REGISTRY_PASSWORD,CONTAINER_REGISTRY
|
||||||
|
script: |
|
||||||
|
docker login $CONTAINER_REGISTRY -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD
|
||||||
|
cd brackt
|
||||||
|
docker compose pull
|
||||||
|
docker compose up -d
|
||||||
Loading…
Add table
Reference in a new issue