Pular para conteúdo

GitHub Actions

marie_ai (Backend)

Arquivo: .github/workflows/deploy.yml

name: Build & Deploy

on:
  push:
    branches: [main]

env:
  IMAGE_NAME: ghcr.io/the-cmos/marie_ai

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    environment: marie_ai_swarm_manager_01
    permissions:
      contents: read
      packages: write

    steps:
      - uses: actions/checkout@v4

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: |
            ${{ env.IMAGE_NAME }}:latest
            ${{ env.IMAGE_NAME }}:${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

      - name: Deploy to Docker Swarm
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.DEPLOY_HOST_MARIE_AI_BACKEND }}
          username: ${{ secrets.DEPLOY_USER_MARIE_AI_BACKEND }}
          key: ${{ secrets.DEPLOY_SSH_KEY_MARIE_AI_BACKEND }}
          script: |
            echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
            docker pull ${{ env.IMAGE_NAME }}:${{ github.sha }}
            SERVICE_NAME="${{ secrets.SWARM_SERVICE_NAME_MARIE_AI_BACKEND }}"
            if docker service inspect "$SERVICE_NAME" > /dev/null 2>&1; then
              docker service update --image ${{ env.IMAGE_NAME }}:${{ github.sha }} --with-registry-auth "$SERVICE_NAME"
            else
              docker service create --name "$SERVICE_NAME" --with-registry-auth --network network_swarm_01 --publish 3000:3000 --env-file /opt/marie_ai_backend/.env ${{ env.IMAGE_NAME }}:${{ github.sha }}
            fi

marie_frontend (Frontend)

Arquivo: .github/workflows/deploy.yml

Mesmo padrao do backend, com adicao de build-args para NEXT_PUBLIC_API_URL:

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: |
            ${{ env.IMAGE_NAME }}:latest
            ${{ env.IMAGE_NAME }}:${{ github.sha }}
          build-args: |
            NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

whatsapp_webhook_sqs (Webhook Bridge)

Arquivo: .github/workflows/build.yml

Mesmo padrao do backend.