Add proxy for Image Service #32
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: Personal Blog Backend Test and Deploy CI | |
on: | |
push: | |
branches: ["main"] | |
paths: | |
- "backend/**" | |
workflow_dispatch: | |
env: | |
# Used for testing | |
API_SECRET: secret | |
APP_FOLDER: backend | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
jobs: | |
tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "21" | |
distribution: "temurin" | |
cache: maven | |
- name: Run unit tests | |
working-directory: ${{ env.APP_FOLDER }} | |
run: mvn -B test | |
- name: Run integration tests | |
working-directory: ${{ env.APP_FOLDER }} | |
run: mvn test -B -P integration-tests | |
build: | |
runs-on: ubuntu-latest | |
needs: tests | |
steps: | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: "{{defaultContext}}:${{ env.APP_FOLDER }}" | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/personalblog-api:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Deploy project to the server | |
working-directory: ${{ env.APP_FOLDER }} | |
run: | | |
eval "$(ssh-agent -s)" && \ | |
echo "$SSH_PRIVATE_KEY" | ssh-add - && \ | |
rsync -az --delete-after -e "ssh -o StrictHostKeyChecking=no" docker-compose.prod.yml *.sql *.conf "$SSH_USER@$SSH_HOST:/app/api/" && \ | |
ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" '\ | |
cd "/app/api" && \ | |
docker compose -f docker-compose.prod.yml down && \ | |
docker compose -f docker-compose.prod.yml pull && \ | |
docker compose -f docker-compose.prod.yml up -d' |