elearning/.forgejo/workflows/deploy-backend.yaml

73 lines
2 KiB
YAML
Raw Normal View History

2026-02-09 16:56:12 +07:00
name: Build and Deploy Backend
on:
push:
branches:
- main
- dev
paths:
- 'Backend/**'
workflow_dispatch:
env:
REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
2026-02-09 16:56:12 +07:00
jobs:
build:
name: Build Backend Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}
2026-02-09 16:56:12 +07:00
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[registry."${{ env.REGISTRY }}"]
ca=["/etc/ssl/certs/ca-certificates.crt"]
2026-02-09 16:56:12 +07:00
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/elearning-backend
2026-02-09 16:56:12 +07:00
tags: |
type=ref,event=branch
type=sha,prefix=
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/dev' }}
2026-02-09 16:56:12 +07:00
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./Backend
file: ./Backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: Deploy Backend to Server
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/dev'
2026-02-09 16:56:12 +07:00
steps:
- name: Remote Deploy
uses: appleboy/ssh-action@v1.2.1
with:
host: ${{ vars.SSH_DEPLOY_HOST }}
port: ${{ vars.SSH_DEPLOY_PORT }}
username: ${{ secrets.SSH_DEPLOY_USER }}
password: ${{ secrets.SSH_DEPLOY_PASSWORD }}
script: eval "${{ secrets.SSH_DEPLOY_BACKEND_CMD }}"