From 1928293dc60b10b8c8856fdd0d484d1755a143cc Mon Sep 17 00:00:00 2001 From: c-d-p Date: Wed, 30 Apr 2025 19:30:18 +0200 Subject: [PATCH] refactorerd ci deployment for gitea --- {.github => .gitea}/workflows/deploy.yml | 68 ++++++++++-------------- 1 file changed, 28 insertions(+), 40 deletions(-) rename {.github => .gitea}/workflows/deploy.yml (66%) diff --git a/.github/workflows/deploy.yml b/.gitea/workflows/deploy.yml similarity index 66% rename from .github/workflows/deploy.yml rename to .gitea/workflows/deploy.yml index 6777f4f..a1903f0 100644 --- a/.github/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -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!" \ No newline at end of file + 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!"