Skip to content

Commit d6970c0

Browse files
committed
Added ephemeral staging environments
closes https://linear.app/ghost/issue/AP-976 - Added ephemeral staging environments - Split Github Actions workflow in 2: CI and CD
1 parent 99ba914 commit d6970c0

File tree

2 files changed

+130
-69
lines changed

2 files changed

+130
-69
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: CI
33
on:
44
workflow_dispatch:
55
pull_request:
6+
types:
7+
- opened
8+
- synchronize
9+
- reopened
10+
- labeled
11+
- unlabeled
612
push:
713
branches:
814
- main
@@ -121,74 +127,13 @@ jobs:
121127
push: true
122128
tags: ${{ steps.migrations-docker-metadata.outputs.tags }}
123129

124-
deploy-staging:
125-
if: github.ref == 'refs/heads/main'
126-
name: (staging) Deploy
127-
environment: build
128-
runs-on: ubuntu-latest
129-
needs: [build-test-push]
130-
strategy:
131-
matrix:
132-
region: [europe-west4, europe-west3]
133-
steps:
134-
- name: "Auth with Google Cloud"
135-
uses: 'google-github-actions/auth@v2'
136-
with:
137-
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}
138-
139-
- name: "Deploy Migrations to Cloud Run"
140-
if: ${{ matrix.region == 'europe-west4' }}
141-
uses: 'google-github-actions/deploy-cloudrun@v2'
142-
with:
143-
image: europe-docker.pkg.dev/ghost-activitypub/activitypub/migrations:${{ needs.build-test-push.outputs.migrations_docker_version }}
144-
region: ${{ matrix.region }}
145-
job: stg-${{ matrix.region }}-activitypub-migrations
146-
flags: '--wait --execute-now --set-cloudsql-instances=ghost-activitypub:${{ matrix.region }}:stg-${{ matrix.region }}-activitypub-primary'
147-
148-
- name: "Deploy ActivityPub Queue to Cloud Run"
149-
uses: 'google-github-actions/deploy-cloudrun@v2'
150-
with:
151-
image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }}
152-
region: ${{ matrix.region }}
153-
service: stg-${{ matrix.region }}-activitypub-queue
154-
155-
- name: "Deploy ActivityPub API to Cloud Run"
156-
uses: 'google-github-actions/deploy-cloudrun@v2'
157-
with:
158-
image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }}
159-
region: ${{ matrix.region }}
160-
service: stg-${{ matrix.region }}-activitypub-api
161-
162-
deploy-old:
163-
if: github.ref == 'refs/heads/main'
164-
name: Deploy (old)
165-
environment: build
166-
runs-on: ubuntu-latest
167-
needs: [build-test-push]
168-
steps:
169-
- name: "Auth with Google Cloud"
170-
uses: 'google-github-actions/auth@v2'
171-
with:
172-
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}
173-
174-
- name: "Deploy Migrations to Cloud Run"
175-
uses: 'google-github-actions/deploy-cloudrun@v2'
176-
with:
177-
image: europe-west4-docker.pkg.dev/ghost-activitypub/main/migrations:${{ needs.build-test-push.outputs.migrations_docker_version }}
178-
region: europe-west4
179-
job: migrations
180-
flags: '--wait --execute-now --set-cloudsql-instances=ghost-activitypub:europe-west4:activitypub-db'
181-
182-
- name: "Deploy ActivityPub Queue to Cloud Run"
183-
uses: 'google-github-actions/deploy-cloudrun@v2'
184-
with:
185-
image: europe-west4-docker.pkg.dev/ghost-activitypub/main/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }}
186-
region: europe-west4
187-
service: activitypub-sub
130+
- name: "Output Docker Tags"
131+
run: |
132+
echo "activitypub: ${{ steps.activitypub-docker-metadata.outputs.tags }}" >> docker_tags.txt
133+
echo "migrations: ${{ steps.migrations-docker-metadata.outputs.tags }}" >> docker_tags.txt
188134
189-
- name: "Deploy ActivityPub API to Cloud Run"
190-
uses: 'google-github-actions/deploy-cloudrun@v2'
135+
- name: "Upload Docker Tags"
136+
uses: actions/upload-artifact@v4
191137
with:
192-
image: europe-west4-docker.pkg.dev/ghost-activitypub/main/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }}
193-
region: europe-west4
194-
service: activitypub
138+
name: docker_tags
139+
path: docker_tags.txt

.github/workflows/deploy.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)