refactorerd ci deployment for gitea
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
# .github/workflows/deploy.yml
|
||||
# .gitea/workflows/deploy.yml
|
||||
|
||||
name: Build and Deploy Backend
|
||||
run-name: ${{ gitea.actor }} deploying backend on Gitea Actions 🚀
|
||||
|
||||
on:
|
||||
# Triggers the workflow on push events but only for the main branch
|
||||
push:
|
||||
branches: [ main ]
|
||||
paths: # Only run if backend code or Docker config changes
|
||||
- 'backend/**'
|
||||
- '.github/workflows/deploy.yml'
|
||||
- '.gitea/workflows/deploy.yml'
|
||||
- 'backend/docker-compose.yml'
|
||||
|
||||
# Allows running of this workflow manually from the Actions tab
|
||||
@@ -76,7 +78,6 @@ jobs:
|
||||
needs: test # Ensure tests pass before deploying
|
||||
|
||||
# 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'
|
||||
|
||||
steps:
|
||||
@@ -91,7 +92,7 @@ jobs:
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
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
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -110,47 +111,34 @@ jobs:
|
||||
file: ./backend/Dockerfile # Explicit path to Dockerfile
|
||||
push: true # Push the image after building
|
||||
tags: | # Use SHA for version specific, latest for general
|
||||
ghcr.io/${{ github.repository_owner }}/maia:${{ github.sha }}
|
||||
ghcr.io/${{ github.repository_owner }}/maia:latest
|
||||
ghcr.io/${{ secrets.DOCKER_REGISTRY_USERNAME }}/maia:${{ gitea.sha }}
|
||||
ghcr.io/${{ secrets.DOCKER_REGISTRY_USERNAME }}/maia:latest
|
||||
# Pull latest base image updates when building (good for scheduled runs)
|
||||
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
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
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)"
|
||||
- name: Deploy Locally
|
||||
run: |
|
||||
set -e # Exit script on first error
|
||||
|
||||
# Log into GHCR on mara
|
||||
echo "Logging into GHCR..."
|
||||
echo ${{ secrets.DOCKER_REGISTRY_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
|
||||
echo "GHCR login completed."
|
||||
# Set deployment path
|
||||
DEPLOY_PATH="/config/maia"
|
||||
|
||||
# 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
|
||||
# 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
|
||||
docker compose pull redis db
|
||||
|
||||
# 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!"
|
||||
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
|
||||
|
||||
echo "Bringing compose stack down and up with new image..."
|
||||
docker compose up -d --force-recreate --remove-orphans
|
||||
echo "Local deployment complete!"
|
||||
Reference in New Issue
Block a user