@@ -20,324 +20,14 @@ working_directory: &working_directory
20
20
executors :
21
21
circleci-go :
22
22
docker :
23
- - image : cimg/go:1.16 -browsers
23
+ - image : cimg/go:1.18 -browsers
24
24
<< : *working_directory
25
25
26
26
all-tags-filter : &all-tags-filter
27
27
filters :
28
28
tags :
29
29
only : /.*/
30
30
31
-
32
- go-docker : &go-docker
33
- << : *working_directory
34
- docker :
35
- - image : cimg/go:1.16-browsers
36
-
37
-
38
- # docker-build and docker-publish jobs are not available as part of palantir/go and palantir/godel orbs.commands:
39
- # Copying go-dist commands from circle-templates to respect the go version specified in .palantir/go-version
40
- # Source: https://github.palantir.build/excavator-checks/circle-templates/blob/develop/src/test/resources/rendered/go-sls-with-gradle/config.yml
41
- # ############################################################################################
42
- # ###### START: Copy go-dist commands for custom circleci jobs for k8s-spark-scheduler #######
43
- # ############################################################################################
44
- go-dist-write-go-version-file : &go-dist-write-go-version-file
45
- run :
46
- name : Writing go version to use in CircleCI job
47
- command : |
48
- # this pattern is used to make it easier to port the code to CircleCI 2.0
49
- ### START modify for CircleCI 2
50
- # Use envrionment variable value and default value instead of parameters
51
- PARAM_GO_VERSION="$ENV_GO_VERSION"
52
- PARAM_GO_VERSION_FILE=".palantir/go-version"
53
- PARAM_GO_PREV_VERSION="$ENV_GO_PREV_VERSION"
54
- PARAM_GOPATH="/home/circleci/go"
55
- ### END modify for CircleCI 2
56
- GO_VERSION_FILE_PATH="${PARAM_GOPATH}/circleci/goversion"
57
- FALLBACK_GO_VERSION_FILE="/usr/local/go/VERSION"
58
- # set Go version
59
- GO_VERSION=${PARAM_GO_VERSION}
60
- if [ ! -z "${GO_VERSION}" ]; then
61
- echo "Go version specified as parameter is ${GO_VERSION}"
62
- elif [ -f "${PARAM_GO_VERSION_FILE}" ]; then
63
- GO_VERSION=$(cat "${PARAM_GO_VERSION_FILE}")
64
- echo "Go version specified in ${PARAM_GO_VERSION_FILE} is ${GO_VERSION}"
65
- elif [ -f "${FALLBACK_GO_VERSION_FILE}" ]; then
66
- GO_VERSION=$(cat "${FALLBACK_GO_VERSION_FILE}")
67
- echo "Go version specified in ${FALLBACK_GO_VERSION_FILE} is ${GO_VERSION}"
68
- else
69
- echo "Error: Go version was not specified as a parameter and neither ${PARAM_GO_VERSION_FILE} nor ${FALLBACK_GO_VERSION_FILE} exist"
70
- exit 1
71
- fi
72
- if (( PARAM_GO_PREV_VERSION > 0 )); then
73
- GO_MINOR_VERSION=$(echo "${GO_VERSION}" | sed 's/^go[0-9][0-9]*\.\([0-9][0-9]*\).*$/\1/')
74
- if (( GO_MINOR_VERSION == 0 )); then
75
- echo "Decrement operation not supported when minor version is 0"
76
- exit 1
77
- fi
78
- (( GO_MINOR_VERSION = GO_MINOR_VERSION - PARAM_GO_PREV_VERSION ))
79
- if (( GO_MINOR_VERSION < 0 )); then
80
- echo "Minor version cannot be less than 0; was: ${GO_MINOR_VERSION}"
81
- exit 1
82
- fi
83
- GO_MAJOR_VERSION=$(echo "${GO_VERSION}" | sed 's/^go\([0-9][0-9]*\).*$/\1/')
84
- GO_VERSION="go${GO_MAJOR_VERSION}.${GO_MINOR_VERSION}"
85
- fi
86
- mkdir -p "$(dirname "${GO_VERSION_FILE_PATH}")"
87
- echo "Writing ${GO_VERSION} to ${GO_VERSION_FILE_PATH}"
88
- printf "%s" "$GO_VERSION" > "${GO_VERSION_FILE_PATH}"
89
-
90
- go-dist-write-cache-key-file : &go-dist-write-cache-key-file
91
- run :
92
- name : Writing cache key for golang distribution
93
- command : |
94
- # this pattern is used to make it easier to port the code to CircleCI 2.0
95
- ### START modify for CircleCI 2
96
- # Use default values instead of parameters
97
- PARAM_GOPATH="/home/circleci/go"
98
- ### END modify for CircleCI 2
99
- # set Go version
100
- GO_VERSION_FILE_PATH="${PARAM_GOPATH}/circleci/goversion"
101
- GO_VERSION="$(cat ${GO_VERSION_FILE_PATH})"
102
- echo "GO_VERSION=${GO_VERSION}"
103
- # write cache key. Content is based on whether or not required data is already present and the Go version.
104
- GO_CACHE_FILE_PATH="${PARAM_GOPATH}/circleci/circleci-cache-key-golang"
105
- mkdir -p "$(dirname ${GO_CACHE_FILE_PATH})"
106
- CACHE_KEY_FILE_CONTENT=""
107
- if [ -d "${PARAM_GOPATH}/go-dists/${GO_VERSION}" ]; then
108
- CACHE_KEY_FILE_CONTENT="Empty cache"
109
- else
110
- CACHE_KEY_FILE_CONTENT="${GO_VERSION}"
111
- fi
112
- echo "Writing cache key ${CACHE_KEY_FILE_CONTENT} to file ${GO_CACHE_FILE_PATH}"
113
- echo "${CACHE_KEY_FILE_CONTENT}" > "${GO_CACHE_FILE_PATH}"
114
-
115
- go-dist-setup-cache : &go-dist-setup-cache
116
- run :
117
- name : Download go distribution and install standard libraries
118
- command : |
119
- # this pattern is used to make it easier to port the code to CircleCI 2.0
120
- ### START modify for CircleCI 2
121
- # Use default value and Artifactory download prefix
122
- PARAM_GOPATH="/home/circleci/go"
123
- PARAM_GO_DIST_DOWNLOAD_URL_PREFIX="https://golang.org/dl/"
124
- ### END modify for CircleCI 2
125
- # set Go version
126
- GO_VERSION="$(cat "${PARAM_GOPATH}/circleci/goversion")"
127
- GO_DIST_DIR="${PARAM_GOPATH}/go-dists/${GO_VERSION}"
128
- GO_DIST_CACHE_DIR="${PARAM_GOPATH}/circleci/go-dists/${GO_VERSION}"
129
- # desired distribution already exists: nothing to do
130
- if [ -d "${GO_DIST_DIR}" ]; then
131
- echo "${GO_DIST_DIR} exists: nothing to do"
132
- exit
133
- elif [ -d "${GO_DIST_CACHE_DIR}" ]; then
134
- # Desired distribution restored from cache: move to expected location
135
- echo "${GO_DIST_DIR} does not exist, but ${GO_DIST_CACHE_DIR} exists: move to expected location"
136
- mkdir -p "${PARAM_GOPATH}/go-dists"
137
- mv "${GO_DIST_CACHE_DIR}" "${GO_DIST_DIR}"
138
- exit
139
- fi
140
- # Desired distribution does not already exist and is not in cache: download and ensure that it exists in
141
- # location that will be cached and in expected location
142
- echo "Neither ${GO_DIST_DIR} nor ${GO_DIST_CACHE_DIR} exist"
143
- echo "Downloading golang distribution from ${PARAM_GO_DIST_DOWNLOAD_URL_PREFIX}${GO_VERSION}.linux-amd64.tar.gz..." && wget -q "${PARAM_GO_DIST_DOWNLOAD_URL_PREFIX}${GO_VERSION}.linux-amd64.tar.gz"
144
- echo "Expanding archive" && tar xf "${GO_VERSION}.linux-amd64.tar.gz"
145
- echo "Removing archive" && rm "${GO_VERSION}.linux-amd64.tar.gz"
146
- echo "Creating $(dirname "${GO_DIST_CACHE_DIR}")" && mkdir -p "$(dirname "${GO_DIST_CACHE_DIR}")"
147
- echo "Moving expanded Go distribution to ${GO_DIST_CACHE_DIR}" && mv go "${GO_DIST_CACHE_DIR}"
148
- echo "Creating ${PARAM_GOPATH}/go-dists directory" && mkdir -p "${PARAM_GOPATH}/go-dists"
149
- echo "Copying expanded Go distribution to ${GO_DIST_DIR}" && cp -r "${GO_DIST_CACHE_DIR}" "${GO_DIST_DIR}"
150
- echo "Setting working directory to ${PARAM_GOPATH} to ensure that 'install std' command doesn't use local go.mod file" && cd "${PARAM_GOPATH}"
151
- echo "Running go install std for linux-amd64" && GOOS=linux GOARCH=amd64 "${GO_DIST_DIR}/bin/go" install std
152
- echo "Running go install std for linux-arm64" && GOOS=linux GOARCH=arm64 "${GO_DIST_DIR}/bin/go" install std
153
- echo "Running go install std for darwin-amd64" && GOOS=darwin GOARCH=amd64 "${GO_DIST_DIR}/bin/go" install std
154
- echo "Running go install std for darwin-arm64" && GOOS=darwin GOARCH=arm64 "${GO_DIST_DIR}/bin/go" install std
155
- echo "Running go install std for windows-amd64" && GOOS=windows GOARCH=amd64 "${GO_DIST_DIR}/bin/go" install std
156
-
157
- go-dist-setup-symlink : &go-dist-setup-symlink
158
- run :
159
- name : Set up symlink from /usr/local/go -> /go/go-dists/${GO_VERSION}
160
- command : |
161
- # this pattern is used to make it easier to port the code to CircleCI 2.0
162
- ### START modify for CircleCI 2
163
- # Use default value
164
- PARAM_GOPATH="/home/circleci/go"
165
- ### END modify for CircleCI 2
166
- # set Go version
167
- GO_VERSION_FILE_PATH="${PARAM_GOPATH}/circleci/goversion"
168
- GO_VERSION="$(cat ${GO_VERSION_FILE_PATH})"
169
- echo "GO_VERSION=${GO_VERSION}"
170
- if command -v sudo &> /dev/null; then
171
- sudo rm -rf /usr/local/go
172
- sudo ln -s "${PARAM_GOPATH}/go-dists/${GO_VERSION}" /usr/local/go
173
- else
174
- rm -rf /usr/local/go
175
- ln -s "${PARAM_GOPATH}/go-dists/${GO_VERSION}" /usr/local/go
176
- fi
177
-
178
- go-build-cache-restore : &go-build-cache-restore
179
- restore_cache :
180
- name : Restoring Go build cache
181
- keys :
182
- - go-build-cache-v1-{{ .Revision }}
183
- go-build-cache-save : &go-build-cache-save
184
- save_cache :
185
- name : Saving Go build cache
186
- key : go-build-cache-v1-{{ .Revision }}
187
- paths :
188
- - /root/.cache/go-build
189
-
190
- go-mod-cache-restore : &go-mod-cache-restore
191
- restore_cache :
192
- name : Restoring Go module cache
193
- keys :
194
- - go-mod-cache-v1-{{ checksum "go.mod" }}-{{ checksum "go.sum" }}
195
- - go-mod-cache-v1-{{ checksum "go.mod" }}
196
- go-mod-cache-save : &go-mod-cache-save
197
- save_cache :
198
- name : Saving Go module cache
199
- key : go-mod-cache-v1-{{ checksum "go.mod" }}-{{ checksum "go.sum" }}
200
- paths :
201
- - /home/circleci/go/pkg/mod
202
-
203
- godel-cache-restore : &godel-cache-restore
204
- restore_cache :
205
- keys :
206
- - &godel-cache-key godel-cache-{{ checksum "godelw" }}-{{ checksum "godel/config/godel.yml" }}-v2
207
- godel-cache-save : &godel-cache-save
208
- save_cache :
209
- key : *godel-cache-key
210
- paths :
211
- - ~/.godel
212
-
213
- godel-version : &godel-version
214
- run : ./godelw version
215
- # ############################################################################################
216
- # ###### END: Copy go-dist commands for custom circleci jobs for k8s-spark-scheduler #######
217
- # ############################################################################################
218
-
219
- # Steps for publishing the ".config.tgz" artifact and the Docker image. Publishes all tags for all Docker images on
220
- # snapshots and only the tags with the key name "release" (as specified in dist-config.yml) on releases.
221
- #
222
- # Preconditions:
223
- # * Docker images to be published have been built with a blank repository name and saved to a file using "docker save" in a persisted workspace.
224
- docker-publish-steps : &docker_publish_steps
225
- - setup_remote_docker :
226
- docker_layer_caching : true
227
- - attach_workspace :
228
- at : /tmp/docker-cache/
229
- - checkout
230
- # ########################
231
- # START: palantir/[email protected]
232
- # ########################
233
- - *go-dist-write-go-version-file
234
- - *go-dist-write-cache-key-file
235
- - restore_cache :
236
- name : Restore Go distribution from cache
237
- keys :
238
- - v4-golang-docker-build-{{ checksum "/home/circleci/go/circleci/circleci-cache-key-golang" }}
239
- - *go-dist-setup-cache
240
- - *go-dist-setup-symlink
241
- - run : go version
242
- - save_cache :
243
- name : Save Go distribution to cache
244
- key : v4-golang-docker-build-{{ checksum "/home/circleci/go/circleci/circleci-cache-key-golang" }}
245
- paths :
246
- - /home/circleci/go/circleci/go-dists
247
- # ########################
248
-
249
- # ########################
250
- - *go-build-cache-restore
251
- - *go-mod-cache-restore
252
- - *godel-cache-restore
253
- - *godel-version
254
- - *godel-cache-save
255
- - run : docker load -i /tmp/docker-cache/docker-images.tar
256
- - run : docker login -u "$DOCKERHUB_USERNAME" -p "$DOCKERHUB_PASSWORD"
257
- # if release type is "release", then only push the tags with the key "release" (these tags typically include a concrete version to ensure that they are
258
- # globally unique). Required because release repository typically does not include overwrite permissions, so tags like "latest" or "snapshot" should not
259
- # be pushed on real releases (whereas it is fine for snapshots).
260
- - run : |
261
- if [ "$RELEASE_TYPE" == "release" ]; then
262
- ./godelw docker push --repository "$DOCKER_REPO" --tags=release
263
- else
264
- ./godelw docker push --repository "$DOCKER_REPO" --tags=latest
265
- fi
266
- - *go-build-cache-save
267
- - *go-mod-cache-save
268
-
269
- jobs :
270
- docker-build :
271
- << : *go-docker
272
- steps :
273
- - setup_remote_docker :
274
- docker_layer_caching : true
275
- - checkout
276
- # ########################
277
- # START: palantir/[email protected]
278
- # ########################
279
- - *go-dist-write-go-version-file
280
- - *go-dist-write-cache-key-file
281
- - restore_cache :
282
- name : Restore Go distribution from cache
283
- keys :
284
- - v4-golang-docker-build-{{ checksum "/home/circleci/go/circleci/circleci-cache-key-golang" }}
285
- - *go-dist-setup-cache
286
- - *go-dist-setup-symlink
287
- - run : go version
288
- - save_cache :
289
- name : Save Go distribution to cache
290
- key : v4-golang-docker-build-{{ checksum "/home/circleci/go/circleci/circleci-cache-key-golang" }}
291
- paths :
292
- - /home/circleci/go/circleci/go-dists
293
- # ########################
294
-
295
- # ########################
296
- - *go-build-cache-restore
297
- - *go-mod-cache-restore
298
- - *godel-cache-restore
299
- - *godel-version
300
- - *godel-cache-save
301
- - run : ./godelw docker build --verbose
302
- - run : |
303
- mkdir -p /tmp/docker-cache
304
- docker save -o /tmp/docker-cache/docker-images.tar $(./godelw artifacts docker)
305
- - persist_to_workspace :
306
- root : /tmp/docker-cache/
307
- paths :
308
- - docker-images.tar
309
- - *go-build-cache-save
310
- - *go-mod-cache-save
311
- push-docker-release :
312
- << : *go-docker
313
- environment :
314
- RELEASE_TYPE : release
315
- steps : *docker_publish_steps
316
- push-docker-snapshot :
317
- << : *go-docker
318
- steps : *docker_publish_steps
319
-
320
- # ## Workflows ###
321
- # The set of jobs that should be run on every build. All publish operations block on these jobs.
322
- requires_jobs : &requires_jobs
323
- - verify
324
- - test
325
- - docker-build
326
-
327
- # Filter that matches only release tags. Used for jobs that publish releases.
328
- release-requires-filter : &release-requires-filter
329
- requires : *requires_jobs
330
- filters :
331
- tags :
332
- only : /^v?[0-9]+(\.[0-9]+)+(-rc[0-9]+)?$/
333
- branches :
334
- ignore : /.*/
335
-
336
- # Filter that matches only the "master" branch. Used for jobs that publish snapshots.
337
- master-requires-filter : &master-requires-filter
338
- requires : *requires_jobs
339
- filters : { tags: { ignore: /.*/ }, branches: { only: /master/ } }
340
-
341
31
workflows :
342
32
version : 2
343
33
verify-test-dist-publish :
@@ -360,9 +50,3 @@ workflows:
360
50
<< : *homepath
361
51
<< : *gopath
362
52
<< : *all-tags-filter
363
- - docker-build :
364
- << : *all-tags-filter
365
- - push-docker-release :
366
- << : *release-requires-filter
367
- - push-docker-snapshot :
368
- << : *master-requires-filter
0 commit comments