-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild.yaml
68 lines (67 loc) · 2.72 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
substitutions:
_CLOUDSDK_COMPUTE_ZONE: europe-west1-b
_GS_NAME: wannplay-enjoy-dev
_REMOTE_SERVER: wannaenjoy-dev-01
steps:
- id: 'Restore Maven Repository from GS'
name: 'gcr.io/cloud-builders/gsutil'
args: ['cp', '-c', 'gs://${_GS_NAME}/m2.tgz', 'm2.tgz']
- id: 'Restore Maven Repository'
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'sh'
args:
- '-c'
- |
tar xzf m2.tgz -C /root
volumes:
- name: 'm2'
path: /root/.m2
- id: 'Compile project'
name: maven:3-jdk-14
entrypoint: 'mvn'
args: ['-s', '.settings.xml', '-Dmaven.wagon.http.ssl.insecure=true', 'clean', 'install']
secretEnv: ['NEXUS_PASSWORD']
env:
- 'NEXUS_USERNAME=${_NEXUS_USERNAME}'
volumes:
- name: 'm2'
path: /root/.m2
- id: 'Backup Maven Repository'
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'sh'
args:
- '-c'
- |
rm -rf /root/.m2/repository/org/wannagoframework
tar czf m2.tgz -C /root .m2
volumes:
- name: 'm2'
path: /root/.m2
- id: 'Copy Maven Repository to GS'
name: 'gcr.io/cloud-builders/gsutil'
args: ['cp', 'm2.tgz', 'gs://${_GS_NAME}/m2.tgz']
- id: 'Get Docker cached image'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker pull eu.gcr.io/$PROJECT_ID/${_ARTIFACT_ID}:latest || exit 0
- id: 'Build image'
name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'eu.gcr.io/$PROJECT_ID/${_ARTIFACT_ID}:latest', '--cache-from', 'eu.gcr.io/$PROJECT_ID/${_ARTIFACT_ID}:latest', '.']
- id: 'Push image'
name: 'gcr.io/cloud-builders/docker'
args: ['push', 'eu.gcr.io/$PROJECT_ID/${_ARTIFACT_ID}:latest']
- id: 'Update the image'
name: 'gcr.io/cloud-builders/gcloud'
args: ['beta', 'compute', '--project', '$PROJECT_ID', 'ssh', '--zone', "$_CLOUDSDK_COMPUTE_ZONE", "clavaud@$_REMOTE_SERVER", "--command", "docker service update --force --with-registry-auth --image eu.gcr.io/$PROJECT_ID/${_ARTIFACT_ID}:latest wannaenjoy_${_ARTIFACT_ID}"]
- id: 'Update the backup image'
name: 'gcr.io/cloud-builders/gcloud'
args: ['beta', 'compute', '--project', '$PROJECT_ID', 'ssh', '--zone', "$_CLOUDSDK_COMPUTE_ZONE", "clavaud@$_REMOTE_SERVER", "--command", "docker service update --force --with-registry-auth --image eu.gcr.io/$PROJECT_ID/${_ARTIFACT_ID}:latest wannaenjoy_${_ARTIFACT_ID}-backup"]
images:
- 'eu.gcr.io/$PROJECT_ID/${_ARTIFACT_ID}:latest'
secrets:
- kmsKeyName: projects/wanna-enjoy/locations/global/keyRings/NEXUS_ACCESS/cryptoKeys/NEXUS_PASSWORD
secretEnv:
NEXUS_PASSWORD: CiQA7KCiyxvVWTKmRC3rGAAuzO4+YIs7y5m32LzFuhRv933LlgMSMgA2Y3W52qiYnnObkWtCcLx+Njo9wrMjybRNCFfb0htqMO761GBUMsVpy1QjeWE5QIx1