-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpreview.cloudbuild.yaml
50 lines (43 loc) · 1.68 KB
/
preview.cloudbuild.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This build config deploys a per-PR preview environment for all pull requests.
# To set it up, see `docs/pr-previews.md`
steps:
# install Test requirements
- name: "docker.io/library/python:3.8"
args: ['pip', 'install', '-t', '/workspace/lib', '-r', 'requirements.txt']
# TODO: Make tests work again
- name: 'docker.io/library/python:3.8'
args: ["python", "tests/main.py"]
env: ["PYTHONPATH=/workspace/lib"]
# build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/instapuller:$SHORT_SHA', '.']
# push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/instapuller:$SHORT_SHA']
# deploy container image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
args: [
'alpha', 'run', 'deploy', 'instapuller-preview',
'--image', 'gcr.io/$PROJECT_ID/instapuller:$SHORT_SHA',
'--region', '${_RUN_REGION}',
'--platform', 'managed',
'--allow-unauthenticated',
'--tag=preview-$SHORT_SHA',
'--no-traffic',
'--quiet'
]
# add preview URL as a comment on Pull Request
- name: gcr.io/cloud-builders/gcloud
entrypoint: bash
args:
- '-eEuo'
- 'pipefail'
- '-c'
- |-
PREVIEW_BASE_URL=$(gcloud run services list --platform=managed --filter="SERVICE:instapuller-preview" --format='value(URL)' | sed 's/https:\/\///g') && \
./tools/pr_comment_post.sh ${_GH_USERNAME}/instapuller ${_PR_NUMBER} \
"Preview this revision: https://preview-${SHORT_SHA}---$${PREVIEW_BASE_URL}" \
$(gcloud secrets versions access latest --secret=github_token)
substitutions:
_RUN_REGION: 'us-central1'
_GH_USERNAME: 'davidstanke'