V1 #31
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: Deploy LEMS | |
on: | |
push: | |
branches: [main] | |
env: | |
REGISTRY: 'registry.digitalocean.com/first-israel-registry' | |
DIGITALOCEAN_KEY: ${{ secrets.DIGITALOCEAN_KEY }} | |
DIGITALOCEAN_SECRET: ${{ secrets.DIGITALOCEAN_SECRET }} | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
MONGODB_URI: ${{ secrets.MONGODB_URI }} | |
MONGO_CA_CERTIFICATE: ${{ secrets.MONGO_CA_CERTIFICATE }} | |
RECAPTCHA_SECRET_KEY: ${{ secrets.RECAPTCHA_SECRET_KEY }} | |
RECAPTCHA_SITE_KEY: ${{ secrets.RECAPTCHA_SITE_KEY }} | |
BASE_URL: ${{ vars.BASE_URL }} | |
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL }} | |
WS_URL: ${{ vars.WS_URL }} | |
NEXT_PUBLIC_WS_URL: ${{ vars.NEXT_PUBLIC_WS_URL }} | |
DIGITALOCEAN_ENDPOINT: ${{ vars.DIGITALOCEAN_ENDPOINT }} | |
DIGITALOCEAN_SPACE: ${{ vars.DIGITALOCEAN_SPACE }} | |
RECAPTCHA: ${{ vars.RECAPTCHA }} | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v3 | |
- name: Install Node Modules | |
run: npm ci | |
- name: LEMS Build | |
run: npm run build | |
- name: Set Image Tag | |
run: echo "IMAGE_TAG=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV | |
- name: Build container image | |
run: docker compose build | |
- name: Install doctl | |
uses: digitalocean/action-doctl@v2 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
- name: Log in to DigitalOcean Container Registry with short-lived credentials | |
run: doctl registry login --expiry-seconds 600 | |
- name: Remove all old images | |
run: | | |
doctl registry repository delete-manifest lems-frontend $(doctl registry repository list-tags lems-frontend | grep -o "sha.*") --force | |
doctl registry repository delete-manifest lems-backend $(doctl registry repository list-tags lems-backend | grep -o "sha.*") --force | |
- name: Push image to DigitalOcean Container Registry | |
run: docker compose push | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build_and_push | |
steps: | |
- name: Set Image Tag | |
run: echo "IMAGE_TAG=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV | |
- name: Deploy to Digital Ocean droplet via SSH action | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.SSHKEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
envs: REGISTRY,IMAGE_TAG,{{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
script: | | |
docker login -u ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} -p ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} registry.digitalocean.com | |
cd lems | |
docker compose down | |
docker compose rm | |
git pull | |
docker compose up -d |