|
| 1 | +name: CD |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + ci-docker-tags: |
| 11 | + name: CI Docker Tags |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/download-artifact@v4 |
| 15 | + with: |
| 16 | + name: docker_tags |
| 17 | + - id: docker-tags |
| 18 | + run: | |
| 19 | + activitypub=$(grep '^activitypub:' docker_tags.txt | cut -d ':' -f2- | xargs) |
| 20 | + migrations=$(grep '^migrations:' docker_tags.txt | cut -d ':' -f2- | xargs) |
| 21 | + echo "activitypub_docker_tags=$activitypub" >> $GITHUB_OUTPUT |
| 22 | + echo "migrations_docker_tags=$migrations" >> $GITHUB_OUTPUT |
| 23 | +
|
| 24 | + deploy-ephemeral-staging: |
| 25 | + name: (ephemeral staging) Deploy |
| 26 | + environment: build |
| 27 | + runs-on: ubuntu-latest |
| 28 | + env: |
| 29 | + ENVIRONMENT: stg |
| 30 | + REGION: europe-west4 |
| 31 | + steps: |
| 32 | + - name: "Auth with Google Cloud" |
| 33 | + uses: 'google-github-actions/auth@v2' |
| 34 | + with: |
| 35 | + credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }} |
| 36 | + - name: 'Set up Cloud SDK' |
| 37 | + uses: 'google-github-actions/setup-gcloud@v2' |
| 38 | + with: |
| 39 | + version: '>= 514.0.0' |
| 40 | + - name: "Check if the infrastructure is already provisioned" |
| 41 | + run: | |
| 42 | + INFRASTRUCTURE_PROVISIONED=$(gcloud run services list --filter='metadata.name=${ENVIRONMENT}-${REGION}-activitypub-api-${GITHUB_HEAD_REF}' --project ghost-activitypub --format=json) |
| 43 | + if [ "${INFRASTRUCTURE_PROVISIONED}" != "[]" ]; then |
| 44 | + echo "The infrastructure is already provisioned" |
| 45 | + echo "infrastructure_provisioned=true" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + deploy-staging: |
| 49 | + if: github.ref == 'refs/heads/main' |
| 50 | + name: (staging) Deploy |
| 51 | + environment: build |
| 52 | + runs-on: ubuntu-latest |
| 53 | + strategy: |
| 54 | + matrix: |
| 55 | + region: [europe-west4, europe-west3] |
| 56 | + steps: |
| 57 | + - name: "Auth with Google Cloud" |
| 58 | + uses: 'google-github-actions/auth@v2' |
| 59 | + with: |
| 60 | + credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }} |
| 61 | + |
| 62 | + - name: "Deploy Migrations to Cloud Run" |
| 63 | + if: ${{ matrix.region == 'europe-west4' }} |
| 64 | + uses: 'google-github-actions/deploy-cloudrun@v2' |
| 65 | + with: |
| 66 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/migrations:${{ needs.ci-docker-tags.outputs.migrations_docker_tags }} |
| 67 | + region: ${{ matrix.region }} |
| 68 | + job: stg-${{ matrix.region }}-activitypub-migrations |
| 69 | + flags: '--wait --execute-now --set-cloudsql-instances=ghost-activitypub:${{ matrix.region }}:stg-${{ matrix.region }}-activitypub-primary' |
| 70 | + |
| 71 | + - name: "Deploy ActivityPub Queue to Cloud Run" |
| 72 | + uses: 'google-github-actions/deploy-cloudrun@v2' |
| 73 | + with: |
| 74 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.ci-docker-tags.outputs.activitypub_docker_tags }} |
| 75 | + region: ${{ matrix.region }} |
| 76 | + service: stg-${{ matrix.region }}-activitypub-queue |
| 77 | + |
| 78 | + - name: "Deploy ActivityPub API to Cloud Run" |
| 79 | + uses: 'google-github-actions/deploy-cloudrun@v2' |
| 80 | + with: |
| 81 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.ci-docker-tags.outputs.activitypub_docker_tags }} |
| 82 | + region: ${{ matrix.region }} |
| 83 | + service: stg-${{ matrix.region }}-activitypub-api |
| 84 | + |
| 85 | + deploy-old: |
| 86 | + if: github.ref == 'refs/heads/main' |
| 87 | + name: Deploy (old) |
| 88 | + environment: build |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - name: "Auth with Google Cloud" |
| 92 | + uses: 'google-github-actions/auth@v2' |
| 93 | + with: |
| 94 | + credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }} |
| 95 | + |
| 96 | + - name: "Deploy Migrations to Cloud Run" |
| 97 | + uses: 'google-github-actions/deploy-cloudrun@v2' |
| 98 | + with: |
| 99 | + image: europe-west4-docker.pkg.dev/ghost-activitypub/main/migrations:${{ needs.ci-docker-tags.outputs.migrations_docker_tags }} |
| 100 | + region: europe-west4 |
| 101 | + job: migrations |
| 102 | + flags: '--wait --execute-now --set-cloudsql-instances=ghost-activitypub:europe-west4:activitypub-db' |
| 103 | + |
| 104 | + - name: "Deploy ActivityPub Queue to Cloud Run" |
| 105 | + uses: 'google-github-actions/deploy-cloudrun@v2' |
| 106 | + with: |
| 107 | + image: europe-west4-docker.pkg.dev/ghost-activitypub/main/activitypub:${{ needs.ci-docker-tags.outputs.activitypub_docker_tags }} |
| 108 | + region: europe-west4 |
| 109 | + service: activitypub-sub |
| 110 | + |
| 111 | + - name: "Deploy ActivityPub API to Cloud Run" |
| 112 | + uses: 'google-github-actions/deploy-cloudrun@v2' |
| 113 | + with: |
| 114 | + image: europe-west4-docker.pkg.dev/ghost-activitypub/main/activitypub:${{ needs.ci-docker-tags.outputs.activitypub_docker_tags }} |
| 115 | + region: europe-west4 |
| 116 | + service: activitypub |
0 commit comments