build-and-deploy-app #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build-and-deploy-app | |
on: workflow_dispatch | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
name: Build images | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Restore cached npm dependencies | |
uses: actions/cache/restore@v3 | |
with: | |
path: | | |
node_modules | |
~/.cache/Cypress # needed for the Cypress binary | |
key: npm-dependencies-${{ hashFiles('package.json') }} | |
- name: Install dependencies | |
run: pnpm install | |
if: steps.cache.outputs.cache-hit != 'true' | |
- name: Cache npm dependencies | |
uses: actions/cache/save@v3 | |
with: | |
path: | | |
node_modules | |
~/.cache/Cypress # needed for the Cypress binary | |
key: npm-dependencies-${{ hashFiles('package.json') }} | |
- name: Build base image | |
run: npm run docker-base-linux | |
- name: Install doctl | |
uses: digitalocean/action-doctl@v2 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
- name: Log in to DO Container Registry | |
# 30min | |
run: doctl registry login --expiry-seconds 1800 | |
- name: Push image to DO Container Registry | |
run: docker push registry.digitalocean.com/maxdata/base:latest | |
- name: Build image for api-gateway | |
run: docker build -t registry.digitalocean.com/maxdata/api-gateway:latest --build-arg NEXT_PUBLIC_API_HOST=$NEXT_PUBLIC_API_HOST -f ./apps/api-gateway/Dockerfile . --platform=linux/amd64 | |
- name: Push image to DO Container Registry | |
run: docker push registry.digitalocean.com/maxdata/api-gateway:latest | |
- name: Build image for web | |
env: | |
NEXT_TELEMETRY_DISABLED: true | |
NEXT_PUBLIC_API_HOST: https://api.linkerry.com | |
run: docker build -t registry.digitalocean.com/maxdata/web:latest --build-arg NEXT_PUBLIC_API_HOST=$NEXT_PUBLIC_API_HOST -f ./apps/web/Dockerfile . --platform=linux/amd64 | |
- name: Push image to DO Container Registry | |
run: docker push registry.digitalocean.com/maxdata/web:latest | |
deploy: | |
runs-on: ubuntu-latest | |
name: Deploy apps | |
needs: ['build'] | |
steps: | |
- name: Connect to VPS and refresh docker composes | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.VPS_IP }} | |
username: root | |
key: ${{ secrets.SSH_PASSPHRASE_PRIVATE_KEY }} | |
passphrase: ${{ secrets.SSH_PASSPHRASE }} | |
port: 22 | |
script: | | |
cd api.linkerry.com/ | |
docker compose pull | |
docker compose up -d --no-deps --build api-gateway | |
cd .. | |
cd linkerry.com/ | |
docker compose pull | |
docker compose up -d --no-deps --build web | |
docker image prune -f | |
- name: Install doctl | |
uses: digitalocean/action-doctl@v2 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
- name: Log in to DO Container Registry | |
# 30min | |
run: doctl registry login --expiry-seconds 1800 | |
# - name: Clear DO container registry | |
# run: doctl registry garbage-collection start --force linkerry | |