-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudbuild-stage.yaml
118 lines (109 loc) · 3.43 KB
/
cloudbuild-stage.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
steps:
#Fetch node_modules
- id: 'Fetch cached node_modules'
name: gcr.io/cloud-builders/gsutil
args: ['cp', 'gs://js-demo-fe-cache/node_modules.tar.gz', 'previous_node_modules.tar.gz']
- id: 'Decompress node_modules'
name: gcr.io/cloud-builders/wget
entrypoint: 'sh'
args:
- '-c'
- |
tar -xzf previous_node_modules.tar.gz node_modules
#Build app
- id: 'Install dependencies'
name: 'gcr.io/cloud-builders/npm'
args: [ 'install' ]
- id: 'Lint'
name: 'gcr.io/cloud-builders/npm'
args: [ 'run', 'lint' ]
- id: 'Unit test'
name: 'gcr.io/cloud-builders/npm'
args: [ 'test' ]
env:
- 'CI=true'
- id: 'Build'
name: 'gcr.io/cloud-builders/npm'
args: [ 'run', 'build' ]
# Deploy app
- id: 'Deploy'
name: 'gcr.io/$PROJECT_ID/firebase-builder'
entrypoint: 'bash'
args: [ '-c', 'firebase deploy -P $$FIREBASE_APP --token $$FIREBASE_TOKEN' ]
env: ['FIREBASE_APP=$_FIREBASE_APP']
secretEnv: ['FIREBASE_TOKEN']
# Cache node_modules
- id: 'Compress node_modules'
name: gcr.io/cloud-builders/wget
entrypoint: 'sh'
args:
- '-c'
- |
tar -czf node_modules.tar.gz node_modules
- id: 'Cache node_modules in GCS'
name: gcr.io/cloud-builders/gsutil
args: ['cp', 'node_modules.tar.gz', 'gs://js-demo-fe-cache/node_modules.tar.gz']
# Tag application code with commit sha
- id: 'Store commit sha'
name: 'gcr.io/cloud-builders/wget'
entrypoint: 'bash'
args:
- '-c'
- |
touch deploy-sha.txt
cat <<EOF > deploy-sha.txt
$COMMIT_SHA
EOF
- id: 'Commit sha file to repo'
name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
git add deploy-sha.txt
git -c user.email="" -c user.name="GCB Worker" commit -a -m "Update deploy-sha.txt to $$COMMIT_SHA [ci skip]" -v
git push https://$$GITHUB_TOKEN@github.com/christophersanson/js-demo-fe.git master -v
secretEnv: ['GITHUB_TOKEN']
# Push deployable app folder to GCS
- id: 'Compress dist'
name: gcr.io/cloud-builders/wget
entrypoint: 'sh'
args:
- '-c'
- |
tar -czf $COMMIT_SHA.tar.gz dist
- id: 'Push dist folder'
name: gcr.io/cloud-builders/gsutil
args: ['cp', '$COMMIT_SHA.tar.gz', 'gs://js-demo-fe-dist/$COMMIT_SHA.tar.gz']
# Submit PR
- id: 'Set hub credentials'
name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
mkdir .config
touch .config/hub
cat <<EOF > .config/hub
github.com:
- user: christophersanson
oauth_token: $$GITHUB_TOKEN
protocol: https
EOF
secretEnv: ['GITHUB_TOKEN']
- id: 'Submit PR to stable'
name: 'eroadltd/ubuntu-git-hub'
entrypoint: 'bash'
args:
- '-c'
- |
git remote set-url origin https://$$GITHUB_TOKEN@github.com/christophersanson/js-demo-fe.git
hub pull-request -f -m 'Promote to Prod' -b stable -h master
secretEnv: ['GITHUB_TOKEN']
secrets:
- kmsKeyName: projects/csanson-test/locations/global/keyRings/js-demo-be/cryptoKeys/github-token
secretEnv:
GITHUB_TOKEN: CiQAbhNgM1F4lsL8uNZHUbtwGVmGGXgv+VVxCn03Oa28xs5ccRwSUADhjamOVE7JpLxxbws/TxqECnR5BawRxUNzHNB5GCmCzP9nxA1s+1wneXmN+Z463yWoqFPpJ+ekYN0M1BZ9+QxauwTqNuSJ5G3kJJ4yy2Hl
- kmsKeyName: projects/csanson-test/locations/global/keyRings/js-demo-fe/cryptoKeys/firebase-token
secretEnv:
FIREBASE_TOKEN: CiQAOuKqqeiN5YdqfFF9qwKxVrcijz8A7ODQvjhLM0624SQKp7cSVgB+NUjs5oJ4PnARrPSbwAMDq6iDejKaht+f0mHtDJkfwsNOjTeHmwoz8p5zYXbP05cf+uQ0m+lNhxEfwTD8cxXU8nU55nzMsrsjQCsBQskQKeXB3Jun