-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.yml
175 lines (174 loc) · 6.5 KB
/
github.yml
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
commands:
gcr-auth:
description: |
Configure Docker to use gcloud as a credential helper. Using this command requires the use of a 'machine' executor.
parameters:
gcloud-service-key:
default: GCLOUD_SERVICE_KEY
description: The gcloud service key
type: env_var_name
google-compute-zone:
default: GOOGLE_COMPUTE_ZONE
description: |
The Google compute zone to connect with via the gcloud CLI
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Environment variable name for the Google project ID to connect with via the gcloud CLI
type: env_var_name
steps:
- gcp-cli/install
- gcp-cli/initialize:
gcloud-service-key: <<parameters.gcloud-service-key>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<parameters.google-project-id>>
gen-k8-patch:
description: Generate kubernetes patch yaml file
parameters:
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Environment variable name for the Google project ID to connect with via the gcloud CLI
type: env_var_name
github-branch:
default: GH_BRANCH
description: Github infrastructure branch
type: env_var_name
github-owner:
default: GH_OWNER
description: Github organization/owner
type: env_var_name
github-repo:
description: Github infrastructure repo
type: string
github-email:
default: GH_EMAIL
description: Github config email
type: env_var_name
k8-container-name:
default: K8_CONTAINER_NAME
description: Kubernetes container name
type: string
steps:
- run:
command: |
if [ $CIRCLE_TAG ]; then TAG_TYPE=$CIRCLE_TAG; else TAG_TYPE=$CIRCLE_SHA1; fi
hub config --global credential.https://github.aaakk.us.kg.helper /usr/local/bin/hub-credential-helper
hub config --global hub.protocol https
hub config --global user.email $<<parameters.github-email>>
hub config --global user.name "Circle CI Builder"
hub clone "$<<parameters.github-owner>>/<<parameters.github-repo>>"
cd <<parameters.github-repo>>
hub checkout $<<parameters.github-branch>>
cat \<<EOF > patch.yaml
spec:
template:
spec:
containers:
- name: <<parameters.k8-container-name>>
image: gcr.io/$<<parameters.google-project-id>>/<<parameters.k8-container-name>>:${TAG_TYPE}
EOF
kubectl patch --local -o yaml \
-f kubernetes/deployments/<<parameters.k8-container-name>>.yaml \
-p "$(cat patch.yaml)" \
> <<parameters.k8-container-name>>.yaml
mv <<parameters.k8-container-name>>.yaml kubernetes/deployments/<<parameters.k8-container-name>>.yaml
hub add kubernetes/deployments/<<parameters.k8-container-name>>.yaml
hub commit -F- \<<EOF
Update the <<parameters.k8-container-name>>-application
This commit updates the <<parameters.k8-container-name>> deployment container image to:
gcr.io/$<<parameters.google-project-id>>/<<parameters.k8-container-name>>:${TAG_TYPE}.
Build ID: ${CIRCLE_BUILD_NUM}
EOF
hub push origin $<<parameters.github-branch>>
name: Generate kubernetes patch yaml file and push to infrastructure repo
description: |
An orb for working with Github. View this orb's source: https://github.com/carecloud-devops/orbs
examples:
create-k8-patch:
description: |
Log into Google Cloud Plaform, then clone infrastructure repo, create kubernetes patch, and push to branch
usage:
orbs:
github: carecloud/[email protected]
version: 2.1
workflows:
create-k8-patch:
jobs:
- github/create-k8-patch:
context: myContext
github-branch: dev
github-owner: CareCloud
github-repo: test-repo
github-email: [email protected]
k8-container-name: test-container-name
executors:
default:
description: Github/Kubernetes executor
docker:
- image: gcr.io/carecloud/hub
auth:
username: _json_key
password: $GCLOUD_SERVICE_KEY
environment:
HUB_CONFIG: /root/project/hub
KUBECONFIG: /root/project/config
jobs:
create-k8-patch:
description: |
Install GCP CLI, if needed, and configure. Clone infrastructure repo, create kubernetes patch, and push to branch.
executor: default
parameters:
gcloud-service-key:
default: GCLOUD_SERVICE_KEY
description: The gcloud service key
type: env_var_name
google-compute-zone:
default: GOOGLE_COMPUTE_ZONE
description: The Google compute zone to connect with via the gcloud CLI
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: The Google project ID to connect with via the gcloud CLI
type: env_var_name
google-cluster:
default: GOOGLE_CLUSTER
description: Cluster Name
type: env_var_name
github-branch:
default: GH_BRANCH
description: Github infrastructure branch
type: env_var_name
github-owner:
default: GH_OWNER
description: Github organization/owner
type: env_var_name
github-repo:
description: Github infrastructure repo
type: string
github-email:
default: GH_EMAIL
description: Github config email
type: env_var_name
k8-container-name:
default: K8_CONTAINER_NAME
description: Kubernetes Container Name
type: string
steps:
- gcr-auth:
gcloud-service-key: <<parameters.gcloud-service-key>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<parameters.google-project-id>>
- attach_workspace:
at: /root/project
- gen-k8-patch:
google-project-id: <<parameters.google-project-id>>
github-branch: <<parameters.github-branch>>
github-owner: <<parameters.github-owner>>
github-repo: <<parameters.github-repo>>
github-email: <<parameters.github-email>>
k8-container-name: <<parameters.k8-container-name>>
orbs:
gcp-cli: circleci/[email protected]
version: 2.1