eCourt-Doc-Edit/.forgejo/workflows/backend.yml

103 lines
3.1 KiB
YAML
Raw Permalink Normal View History

2026-09-21 19:41:26 +07:00
name: Backend CI + Docker Deploy
2026-09-21 15:55:49 +07:00
on:
push:
2026-09-21 19:41:26 +07:00
branches:
- main
- master
2026-09-21 15:55:49 +07:00
tags:
- "backend-*.*.*"
2026-09-21 19:41:26 +07:00
paths:
- "backend/**"
- "docker-compose.yml"
- ".forgejo/workflows/backend.yml"
pull_request:
paths:
- "backend/**"
- "docker-compose.yml"
- ".forgejo/workflows/backend.yml"
2026-09-21 15:55:49 +07:00
workflow_dispatch:
2026-09-21 19:41:26 +07:00
permissions:
contents: read
2026-09-21 15:55:49 +07:00
2026-09-21 19:41:26 +07:00
env:
REGISTRY: ${{ vars.CONTAINER_REGISTRY || 'ghcr.io' }}
IMAGE_NAME: ${{ vars.IMAGE_NAMESPACE }}/word-versioning-backend
IMAGE_TAG: ${{ github.ref_name || 'latest' }}
2026-09-21 15:55:49 +07:00
DEPLOY_HOST: ${{ vars.SSH_DEPLOY_HOST }}
DEPLOY_USER: ${{ vars.SSH_DEPLOY_USER }}
jobs:
build-and-test:
name: Build and test backend
runs-on: ubuntu-latest
timeout-minutes: 30
env:
2026-09-21 19:41:26 +07:00
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
2026-09-21 15:55:49 +07:00
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
2026-09-21 19:41:26 +07:00
dotnet-version: "8.0.x"
2026-09-21 15:55:49 +07:00
- name: Restore solution
run: dotnet restore backend/WordVersioning.slnx
- name: Build solution
run: dotnet build backend/WordVersioning.slnx --configuration Release --no-restore
- name: Run tests
run: dotnet test backend/WordVersioning.slnx --configuration Release --no-build --logger "trx;LogFileName=backend-tests.trx"
2026-09-21 19:41:26 +07:00
docker-build:
name: Build and push backend image
needs: build-and-test
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
- name: Build and push backend image
uses: docker/build-push-action@v6
with:
context: .
file: ./backend/WordVersioning.Api/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
deploy:
name: Deploy backend container
needs: docker-build
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Deploy over SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ env.DEPLOY_HOST }}
username: ${{ env.DEPLOY_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
set -e
echo "${{ secrets.CONTAINER_REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u "${{ vars.CONTAINER_REGISTRY_USERNAME }}" --password-stdin
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker compose -f /opt/word-versioning/docker-compose.prod.yml up -d api
docker image prune -f