Skip to content

Backend Deploy

Backend Deploy #23

Workflow file for this run

name: Backend Deploy
on:
workflow_dispatch:
push:
branches:
- main
paths:
- backend/**
- server/docker/docker-compose-be.yaml
- server/docker/docker-compose-db.yaml
jobs:
deploy:
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: gradle
- name: Build
working-directory: backend
run: |
chmod +x gradlew
./gradlew build -x test
- name: Copy jar
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: backend/build/libs/, server/
target: ~/${{ github.event.repository.name }}
- name: Setup environment variables
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd ~/${{ github.event.repository.name }}/server/docker
echo "JASYPT_PASSWORD=${{ secrets.JASYPT_PASSWORD }}" > .env
echo "MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}" >> .env
- name: Update db and be
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd ~/${{ github.event.repository.name }}/server/docker
docker compose -f docker-compose-be.yaml pull
docker compose -f docker-compose-db.yaml pull
export `cat .env`
REPO_NAME = `${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]'`
docker compose -f docker-compose-db.yaml up -d
docker service ls | grep -iw ${REPO_NAME}_be \
&& docker service update --force ${REPO_NAME}_be \
|| docker stack deploy -c docker-compose-be.yaml ${REPO_NAME}
docker image prune -af