-
Notifications
You must be signed in to change notification settings - Fork 68
/
cloudbuild.yaml
115 lines (96 loc) · 3.13 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
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
#
# User-defined substitutions:
# _CLOUDSDK_COMPUTE_ZONE
# _CLOUDSDK_CONTAINER_CLUSTER
# _GITHUB_USERNAME
# _KMS_KEY
# _KMS_KEYRING
#
steps:
# Build the pipeline container image.
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '-t'
- 'gcr.io/${PROJECT_ID}/pipeline:${TAG_NAME}'
- '.'
# Retrieve and decrypt the GitHub Hub configuration.
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'sh'
args:
- '-c'
- |
gsutil cp gs://${PROJECT_ID}-pipeline-configs/hub.enc hub.enc
gcloud kms decrypt \
--ciphertext-file=hub.enc \
--plaintext-file=/config/hub \
--location=global \
--keyring=${_KMS_KEYRING} \
--key=${_KMS_KEY}
volumes:
- name: 'config'
path: /config
# Generate a kubeconfig file for the given GKE cluster.
- name: 'gcr.io/cloud-builders/kubectl'
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
- 'KUBECONFIG=/kube/config'
entrypoint: 'sh'
args:
- '-c'
- |
CLUSTER=$$(gcloud config get-value container/cluster)
PROJECT=$$(gcloud config get-value core/project)
ZONE=$$(gcloud config get-value compute/zone)
gcloud container clusters get-credentials "$${CLUSTER}" \
--project "$${PROJECT}" \
--zone "$${ZONE}"
volumes:
- name: 'kube'
path: /kube
# Clone the pipeline-infrastructure repo which holds the Kubernetes
# deployment manifests.
- name: 'gcr.io/hightowerlabs/hub'
env:
- 'HUB_CONFIG=/config/hub'
- 'KUBECONFIG=/kube/config'
entrypoint: 'sh'
args:
- '-c'
- |
ACTIVE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)")
hub config --global credential.https://github.com.helper /usr/local/bin/hub-credential-helper
hub config --global hub.protocol https
hub config --global user.email "$${ACTIVE_ACCOUNT}"
hub config --global user.name "Google Container Builder"
hub clone "https://github.com/${_GITHUB_USERNAME}/pipeline-infrastructure-qa.git"
cd pipeline-infrastructure-qa
cat <<EOF > patch.yaml
spec:
template:
spec:
containers:
- name: pipeline
image: gcr.io/${PROJECT_ID}/pipeline:${TAG_NAME}
EOF
kubectl patch --local -o yaml \
-f kubernetes/deployments/pipeline.yaml \
-p "$(cat patch.yaml)" \
> pipeline.yaml
mv pipeline.yaml kubernetes/deployments/pipeline.yaml
hub add kubernetes/deployments/pipeline.yaml
hub commit -F- <<EOF
Update the pipeline-application
This commit updates the pipeline deployment container image to:
gcr.io/${PROJECT_ID}/pipeline:${TAG_NAME}.
Build ID: ${BUILD_ID}
EOF
hub push origin master
volumes:
- name: 'config'
path: /config
- name: 'kube'
path: /kube
images:
- gcr.io/${PROJECT_ID}/pipeline:${TAG_NAME}