Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Commit 64fbbc5

Browse files
authored
Merge pull request #277 from crowdbotics/PLAT-5519
PLAT-5519 Support for GCP deployment
2 parents 0061e24 + a2b7c98 commit 64fbbc5

File tree

7 files changed

+488
-12
lines changed

7 files changed

+488
-12
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2.1
2+
setup: true
3+
orbs:
4+
continuation: circleci/continuation@0.1.0
5+
jobs:
6+
setup:
7+
executor: continuation/default
8+
steps:
9+
- checkout
10+
- run:
11+
name: Generate Pipeline generated_config.yml file
12+
command: |
13+
bash .circleci/generate_gcp_config.sh
14+
- continuation/continue:
15+
parameters: '{}'
16+
configuration_path: configs/generated_config.yml
17+
workflows:
18+
setup-workflow:
19+
jobs:
20+
- setup
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
4+
BACKEND_PATH=$1
5+
6+
mkdir configs/
7+
cat << EOF > configs/generated_config.yml
8+
version: 2.1
9+
10+
orbs:
11+
cloudrun: circleci/gcp-cloud-run@1.0.2
12+
13+
jobs:
14+
build_and_deploy:
15+
docker:
16+
- image: 'cimg/base:stable'
17+
steps:
18+
- checkout
19+
- cloudrun/init
20+
- cloudrun/build:
21+
tag: 'gcr.io/${GOOGLE_PROJECT_ID}/${GOOGLE_SERVICE_NAME}'
22+
source: "$BACKEND_PATH"
23+
24+
- run:
25+
name: Run collectstatic and migrations
26+
command: |
27+
gcloud builds submit --config "$BACKEND_PATH.cloudbuild/migrate_collectstatic.yaml" \
28+
--substitutions _INSTANCE_NAME=${GOOGLE_PROJECT_ID},_REGION=${GOOGLE_REGION},_SERVICE_NAME=${GOOGLE_PROJECT_ID}
29+
30+
- cloudrun/deploy:
31+
image: 'gcr.io/${GOOGLE_PROJECT_ID}/${GOOGLE_SERVICE_NAME}'
32+
platform: managed
33+
region: ${GOOGLE_REGION}
34+
service-name: '${GOOGLE_PROJECT_ID}'
35+
unauthenticated: true
36+
37+
- run:
38+
name: Webhook Success
39+
command: bash "$BACKEND_PATH.circleci/webhook_callback.sh" "success"
40+
when: on_success
41+
42+
- run:
43+
name: Webhook Failed
44+
command: bash "$BACKEND_PATH.circleci/webhook_callback.sh" "failure"
45+
when: on_fail
46+
47+
workflows:
48+
build_and_deploy_to_managed_workflow:
49+
jobs:
50+
- build_and_deploy
51+
EOF
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
url="https://$WEBHOOK_HOSTNAME/api/v1/github-repos/$PROJECT_ID/circleci_webhook/"
2+
3+
payload=$(
4+
cat <<EOM
5+
{
6+
"status": "$1",
7+
"job": "$CIRCLE_JOB",
8+
"build_num": "$CIRCLE_BUILD_NUM",
9+
"repo": "$CIRCLE_REPOSITORY_URL",
10+
"branch": "$CIRCLE_BRANCH",
11+
"build_url": "$CIRCLE_BUILD_URL",
12+
"compare_url": "$CIRCLE_COMPARE_URL",
13+
"sha1": "$CIRCLE_SHA1",
14+
"platform_id": "$PLATFORM_ID",
15+
"app_url": "$GCP_DEPLOY_ENDPOINT"
16+
}
17+
EOM
18+
)
19+
20+
curl -X POST -H "Content-Type: application/json" -H "Authorization: Api-Key $WEBHOOK_API_KEY" --data "$payload" $url
21+
echo "Webhook call completed"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
steps:
2+
- id: "collect static"
3+
name: "gcr.io/google-appengine/exec-wrapper"
4+
args:
5+
[
6+
"-i",
7+
"gcr.io/$PROJECT_ID/${_SERVICE_NAME}",
8+
"-s",
9+
"${PROJECT_ID}:${_REGION}:${_INSTANCE_NAME}",
10+
"-e",
11+
"SETTINGS_NAME=${_SECRET_SETTINGS_NAME}",
12+
"--",
13+
"python3",
14+
"manage.py",
15+
"collectstatic",
16+
"--verbosity",
17+
"2",
18+
"--no-input",
19+
]
20+
21+
- id: "apply migrations"
22+
name: "gcr.io/google-appengine/exec-wrapper"
23+
args:
24+
[
25+
"-i",
26+
"gcr.io/$PROJECT_ID/${_SERVICE_NAME}",
27+
"-s",
28+
"${PROJECT_ID}:${_REGION}:${_INSTANCE_NAME}",
29+
"-e",
30+
"SETTINGS_NAME=${_SECRET_SETTINGS_NAME}",
31+
"--",
32+
"python3",
33+
"manage.py",
34+
"migrate",
35+
]
36+
37+
images:
38+
- "gcr.io/${PROJECT_ID}/${_SERVICE_NAME}"
39+
40+
substitutions:
41+
_INSTANCE_NAME: django-instance
42+
_REGION: us-east4
43+
_SERVICE_NAME: service-name
44+
_SECRET_SETTINGS_NAME: django_settings

{{cookiecutter.project_slug}}/Pipfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ pyyaml = "~=6.0"
2828
pillow = "~=8.4.0"
2929
pytest = "==6.2.5"
3030
factory-boy = "==3.2.1"
31+
google-cloud-secret-manager = "==2.7.0"
32+
google-auth = "==1.34.0"
33+
google-cloud-storage = "==1.41.1"
34+

0 commit comments

Comments
 (0)