diff --git a/.gitea/workflows/up-down.yaml b/.gitea/workflows/up-down.yaml new file mode 100644 index 0000000..6ca07dc --- /dev/null +++ b/.gitea/workflows/up-down.yaml @@ -0,0 +1,53 @@ +name: Add up down workflow + +on: + push: + branches: + - add-up-down + workflow_dispatch: + inputs: + action: + description: 'Action to perform (up or down)' + required: true + default: 'up' + type: choice + options: + - up + - down + +env: + REMOTE_PREPROD_PATH: /var/app/nextcloud/preprod + + # --- SECRETS --- + SSH_HOST: ${{ secrets.SSH_HOST }} + SSH_USER: ${{ secrets.SSH_USER }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + SSH_PORT: ${{ secrets.SSH_PORT || 22 }} + +jobs: + # ------------------------------------------------------------------ + # STAGE 3.5: DEPLOY PRE-PROD + # ------------------------------------------------------------------ + up_down_preprod: + name: Up/Down (Pre-Prod) + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - name: Up/Down Remote Environment + uses: appleboy/ssh-action@0ff4204d59e8e51228ff73bce53f80d53301dee2 # v1.2.5 + with: + host: ${{ env.SSH_HOST }} + username: ${{ env.SSH_USER }} + key: ${{ env.SSH_PRIVATE_KEY }} + port: ${{ env.SSH_PORT }} + script: | + set -e + cd ${{ env.REMOTE_PREPROD_PATH }} + if ([ "${{ github.event.inputs.action }}" = "up" ]; then + docker compose -f docker-compose.yml up -d --build --remove-orphans --wait + elif [ "${{ github.event.inputs.action }}" = "down" ]; then + docker compose -f docker-compose.yml down || true + else + echo "Invalid action: ${{ github.event.inputs.action }}. Use 'up' or 'down'." + exit 1 + fi)