refactorerd ci deployment for gitea
Some checks failed
Build and Deploy Backend / Run Linters and Tests (push) Failing after 1m22s
Build and Deploy Backend / Build and Deploy (push) Has been skipped

This commit is contained in:
c-d-p
2025-04-30 19:30:18 +02:00
parent 44b8760ab2
commit 1928293dc6

View File

@@ -1,13 +1,15 @@
# .github/workflows/deploy.yml # .gitea/workflows/deploy.yml
name: Build and Deploy Backend name: Build and Deploy Backend
run-name: ${{ gitea.actor }} deploying backend on Gitea Actions 🚀
on: on:
# Triggers the workflow on push events but only for the main branch # Triggers the workflow on push events but only for the main branch
push: push:
branches: [ main ] branches: [ main ]
paths: # Only run if backend code or Docker config changes paths: # Only run if backend code or Docker config changes
- 'backend/**' - 'backend/**'
- '.github/workflows/deploy.yml' - '.gitea/workflows/deploy.yml'
- 'backend/docker-compose.yml' - 'backend/docker-compose.yml'
# Allows running of this workflow manually from the Actions tab # Allows running of this workflow manually from the Actions tab
@@ -76,7 +78,6 @@ jobs:
needs: test # Ensure tests pass before deploying needs: test # Ensure tests pass before deploying
# Only run this job if triggered by a push to main or manual dispatch/schedule # Only run this job if triggered by a push to main or manual dispatch/schedule
# This prevents it running for PRs (eventually)
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
steps: steps:
@@ -91,7 +92,7 @@ jobs:
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} # GitHub username username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} # Uses the username stored in secrets
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} # Uses the PAT stored in secrets password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} # Uses the PAT stored in secrets
# ------------------------------------------------------------------ # ------------------------------------------------------------------
@@ -110,47 +111,34 @@ jobs:
file: ./backend/Dockerfile # Explicit path to Dockerfile file: ./backend/Dockerfile # Explicit path to Dockerfile
push: true # Push the image after building push: true # Push the image after building
tags: | # Use SHA for version specific, latest for general tags: | # Use SHA for version specific, latest for general
ghcr.io/${{ github.repository_owner }}/maia:${{ github.sha }} ghcr.io/${{ secrets.DOCKER_REGISTRY_USERNAME }}/maia:${{ gitea.sha }}
ghcr.io/${{ github.repository_owner }}/maia:latest ghcr.io/${{ secrets.DOCKER_REGISTRY_USERNAME }}/maia:latest
# Pull latest base image updates when building (good for scheduled runs) # Pull latest base image updates when building (good for scheduled runs)
pull: true pull: true
cache-from: type=gha # Github Actions cache
cache-to: type=gha,mode=max
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Deploy to mara via SSH # Deploy to mara
# ------------------------------------------------------------------ # ------------------------------------------------------------------
- name: Deploy to Server - name: Deploy Locally
uses: appleboy/ssh-action@v1.0.3 run: |
with: set -e # Exit script on first error
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
set -e # Exit script on first error
cd ${{ secrets.DEPLOY_PATH }}
echo "Logged into server: $(pwd)"
# Log into GHCR on mara # Set deployment path
echo "Logging into GHCR..." DEPLOY_PATH="/config/maia"
echo ${{ secrets.DOCKER_REGISTRY_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
echo "GHCR login completed." # Pull the specific image version built in this workflow
echo "Pulling image ${{ gitea.sha }}..."
docker pull ghcr.io/${{ secrets.DOCKER_REGISTRY_USERNAME }}/maia:${{ gitea.sha }}
# Change to the directory containing the compose file
cd ${{ DEPLOY_PATH }}
# Pull the latest images for other services to ensure they stay up to date
docker compose pull redis db
# Pull the specific image version built in this workflow sed -i 's|image: ghcr.io/${{ secrets.DOCKER_REGISTRY_USERNAME }}/maia:.*|image: ghcr.io/${{ secrets.DOCKER_REGISTRY_USERNAME }}/maia:${{ gitea.sha }}|g' docker-compose.yml
# Using the Git SHA ensures we deploy exactly what was just built
echo "Pulling image ${{ github.sha }}..."
docker pull ghcr.io/${{ github.repository_owner }}/maia:${{ github.sha }}
# Also pull latest for other services to keep up to date echo "Bringing compose stack down and up with new image..."
docker compose pull redis db docker compose up -d --force-recreate --remove-orphans
echo "Local deployment complete!"
# Uses sed to update the compose file with the new image tag
sed -i 's|image: ghcr.io/${{ github.repository_owner }}/maia:.*|image: ghcr.io/${{ github.repository_owner }}/maia:${{ github.sha }}|g' docker-compose.yml
echo "Updated docker-compose.yml image tag"
# Restart the services using the new image(s)
echo "Bringing compose stack down and up with new image..."
docker compose up -d --force-recreate --remove-orphans api worker db redis
echo "Deployment complete!"