Skip to content

Commit 6920855

Browse files
committed
Goreleaser setup for kpt
1 parent 8cb2dfe commit 6920855

File tree

2 files changed

+157
-139
lines changed

2 files changed

+157
-139
lines changed

release/tag/cloudbuild.yaml

Lines changed: 109 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -13,169 +13,147 @@
1313
# limitations under the License.
1414

1515
steps:
16+
- name: gcr.io/cloud-builders/git
17+
args: ['clone', 'https://github.com/${_GITHUB_USER}/kpt.git']
18+
19+
- name: gcr.io/cloud-builders/git
20+
dir: 'kpt'
21+
args: ['checkout', '${TAG_NAME}']
22+
1623
# Build the image that contains most of the tools we need (e.g. tar,
1724
# jq, gzip, golang, bash, etc.) to build kpt tarball. This image
1825
# (kpt-builder) is re-used on most steps.
1926
- name: 'gcr.io/cloud-builders/docker'
20-
args: ['build', '-f', '/workspace/release/Dockerfile.kpt-build', '-t', 'kpt-builder', '.']
27+
dir: 'kpt'
28+
args: ['build', '-f', '/workspace/kpt/release/Dockerfile.kpt-build', '-t', 'kpt-builder', '.']
2129

22-
# Generate and package the licenses and necessary source code.
30+
# run e2e tests and linting
2331
- name: 'kpt-builder'
24-
args: ['bash', '/workspace/scripts/create-licenses.sh']
32+
args: ['git', 'config', '--global', 'user.email', '[email protected]']
33+
dir: 'kpt'
2534
volumes:
26-
- name: go-modules
27-
path: /go
28-
35+
- name: home
36+
path: /root
2937
- name: 'kpt-builder'
30-
args: ['mkdir', '/workspace/latest']
31-
32-
# FYI: If cross-platform build issues happen, then stop caching the modules in the volume.
33-
# build windows
38+
args: ['git', 'config', '--global', 'user.name', 'Your Name']
39+
dir: 'kpt'
40+
volumes:
41+
- name: home
42+
path: /root
3443
- name: 'kpt-builder'
35-
env: ['GOOS=windows', 'GOARCH=amd64', 'CGO_ENABLED=0', 'GO111MODULE=on']
36-
args: ['go', 'build', '-ldflags', '-X github.com/GoogleContainerTools/kpt/run.version=${TAG_NAME}', '-o', '/workspace/releases/${TAG_NAME}/windows_amd64/kpt.exe', '.']
37-
dir: '/workspace/'
44+
args: ['make', 'all']
45+
env: ['GO111MODULE=on']
46+
dir: 'kpt'
3847
volumes:
3948
- name: go-modules
4049
path: /go
41-
- name: 'kpt-builder'
42-
args: ['cp', '/workspace/LICENSES.txt', '/workspace/releases/${TAG_NAME}/windows_amd64']
43-
- name: 'kpt-builder'
44-
args: ['cp', '/workspace/lib.zip', '/workspace/releases/${TAG_NAME}/windows_amd64']
45-
# Create the tarball containing the kpt binary and licenses.
46-
- name: 'kpt-builder'
47-
args: ['tar', '-cf',
48-
'/workspace/releases/${TAG_NAME}/windows_amd64/kpt_windows_amd64-${TAG_NAME}.tar',
49-
'-C', '/workspace/releases/${TAG_NAME}/windows_amd64',
50-
'kpt.exe', 'LICENSES.txt', 'lib.zip']
51-
- name: 'kpt-builder'
52-
args: ['gzip', '/workspace/releases/${TAG_NAME}/windows_amd64/kpt_windows_amd64-${TAG_NAME}.tar']
53-
54-
# copy latest
55-
- name: 'kpt-builder'
56-
args: ['mkdir', '/workspace/latest/windows_amd64/']
57-
- name: 'kpt-builder'
58-
args: ['cp', '/workspace/releases/${TAG_NAME}/windows_amd64/kpt.exe', '/workspace/latest/windows_amd64/kpt.exe']
59-
- name: 'kpt-builder'
60-
args: ['cp', '/workspace/releases/${TAG_NAME}/windows_amd64/kpt_windows_amd64-${TAG_NAME}.tar.gz', '/workspace/latest/windows_amd64/kpt_windows_amd64.tar.gz']
50+
- name: home
51+
path: /root
6152

62-
# Cleanup by removing files that have been packaged into the
63-
# tarball.
64-
- name: 'kpt-builder'
65-
args: ['rm', '-f',
66-
'/workspace/releases/${TAG_NAME}/windows_amd64/kpt.exe',
67-
'/workspace/releases/${TAG_NAME}/windows_amd64/LICENSES.txt',
68-
'/workspace/releases/${TAG_NAME}/windows_amd64/lib.zip']
53+
# remove any dirty files after running the build
54+
- name: gcr.io/cloud-builders/git
55+
dir: 'kpt'
56+
args: ['reset', '--hard']
6957

70-
# build linux
58+
# Generate and package the licenses and necessary source code.
7159
- name: 'kpt-builder'
72-
env: ['GOOS=linux', 'GOARCH=amd64', 'CGO_ENABLED=0', 'GO111MODULE=on']
73-
args: ['go', 'build', '-ldflags', '-X github.com/GoogleContainerTools/kpt/run.version=${TAG_NAME}', '-o', '/workspace/releases/${TAG_NAME}/linux_amd64/kpt', '.']
74-
dir: '/workspace/'
60+
dir: 'kpt'
61+
args: ['bash', '/workspace/scripts/create-licenses.sh']
7562
volumes:
7663
- name: go-modules
7764
path: /go
78-
- name: 'kpt-builder'
79-
args: ['cp', '/workspace/LICENSES.txt', '/workspace/releases/${TAG_NAME}/linux_amd64']
80-
- name: 'kpt-builder'
81-
args: ['cp', '/workspace/lib.zip', '/workspace/releases/${TAG_NAME}/linux_amd64']
82-
# Create the tarball containing the kpt binary and licenses.
83-
- name: 'kpt-builder'
84-
args: ['tar', '-cf',
85-
'/workspace/releases/${TAG_NAME}/linux_amd64/kpt_linux_amd64-${TAG_NAME}.tar',
86-
'-C', '/workspace/releases/${TAG_NAME}/linux_amd64',
87-
'kpt', 'LICENSES.txt', 'lib.zip']
88-
- name: 'kpt-builder'
89-
args: ['gzip', '/workspace/releases/${TAG_NAME}/linux_amd64/kpt_linux_amd64-${TAG_NAME}.tar']
9065

91-
# copy latest
92-
- name: 'kpt-builder'
93-
args: ['mkdir', '/workspace/latest/linux_amd64/']
94-
- name: 'kpt-builder'
95-
args: ['cp', '/workspace/releases/${TAG_NAME}/linux_amd64/kpt', '/workspace/latest/linux_amd64/kpt']
96-
- name: 'kpt-builder'
97-
args: ['cp', '/workspace/releases/${TAG_NAME}/linux_amd64/kpt_linux_amd64-${TAG_NAME}.tar.gz', '/workspace/latest/linux_amd64/kpt_linux_amd64.tar.gz']
66+
- name: 'gcr.io/cloud-builders/gcloud'
67+
entrypoint: 'bash'
68+
args: [ '-c', 'mkdir -p ~/.config/goreleaser && gcloud secrets versions access latest --secret=github-token > ~/.config/goreleaser/github_token' ]
69+
70+
- name: 'goreleaser/goreleaser'
71+
dir: 'kpt'
72+
args: ['release', '--skip-validate', '-f', 'release/tag/goreleaser.yaml']
73+
74+
# create a working folder for downloading release artifacts from github and pushing
75+
# them to GCS
76+
- name: 'launcher.gcr.io/google/ubuntu1604'
77+
entrypoint: 'bash'
78+
args: [ '-c', 'mkdir artifacts']
79+
80+
# download release artifacts from github
81+
- name: 'launcher.gcr.io/google/ubuntu1604'
82+
dir: 'artifacts'
83+
args: [ 'curl', '-L',
84+
'-O', 'https://github.com/${_GITHUB_USER}/kpt/releases/download/${TAG_NAME}/kpt_darwin_amd64_${_VERSION}.tar.gz',
85+
'-O', 'https://github.com/${_GITHUB_USER}/kpt/releases/download/${TAG_NAME}/kpt_linux_amd64_${_VERSION}.tar.gz',
86+
'-O', 'https://github.com/${_GITHUB_USER}/kpt/releases/download/${TAG_NAME}/kpt_windows_amd64_${_VERSION}.tar.gz'
87+
]
88+
89+
# upload the artifacts to GCS
90+
- name: 'gcr.io/cloud-builders/gsutil'
91+
dir: 'artifacts'
92+
args: [ 'cp', '-a', 'public-read', 'kpt_darwin_amd64_${_VERSION}.tar.gz', 'gs://${_GCS_BUCKET}/releases/${TAG_NAME}/darwin_amd64/kpt_darwin_amd64_${TAG_NAME}.tar.gz' ]
9893

99-
# Cleanup by removing files that have been packaged into the
100-
# tarball.
101-
- name: 'kpt-builder'
102-
args: ['rm', '-f',
103-
'/workspace/releases/${TAG_NAME}/linux_amd64/kpt',
104-
'/workspace/releases/${TAG_NAME}/linux_amd64/LICENSES.txt',
105-
'/workspace/releases/${TAG_NAME}/linux_amd64/lib.zip']
94+
- name: 'gcr.io/cloud-builders/gsutil'
95+
dir: 'artifacts'
96+
args: [ 'cp', '-a', 'public-read', 'kpt_darwin_amd64_${_VERSION}.tar.gz', 'gs://${_GCS_BUCKET}/latest/darwin_amd64/kpt_darwin_amd64.tar.gz' ]
10697

107-
# build darwin
108-
- name: 'kpt-builder'
109-
env: ['GOOS=darwin', 'GOARCH=amd64', 'CGO_ENABLED=0', 'GO111MODULE=on']
110-
args: ['go', 'build', '-ldflags', '-X github.com/GoogleContainerTools/kpt/run.version=${TAG_NAME}', '-o', '/workspace/releases/${TAG_NAME}/darwin_amd64/kpt', '.']
111-
dir: '/workspace/'
112-
volumes:
113-
- name: go-modules
114-
path: /go
115-
- name: 'kpt-builder'
116-
args: ['cp', '/workspace/LICENSES.txt', '/workspace/releases/${TAG_NAME}/darwin_amd64']
117-
- name: 'kpt-builder'
118-
args: ['cp', '/workspace/lib.zip', '/workspace/releases/${TAG_NAME}/darwin_amd64']
119-
# Create the tarball containing the kpt binary and licenses.
120-
- name: 'kpt-builder'
121-
args: ['tar', '-cf',
122-
'/workspace/releases/${TAG_NAME}/darwin_amd64/kpt_darwin_amd64-${TAG_NAME}.tar',
123-
'-C', '/workspace/releases/${TAG_NAME}/darwin_amd64',
124-
'kpt', 'LICENSES.txt', 'lib.zip']
125-
- name: 'kpt-builder'
126-
args: ['gzip', '/workspace/releases/${TAG_NAME}/darwin_amd64/kpt_darwin_amd64-${TAG_NAME}.tar']
98+
- name: 'launcher.gcr.io/google/ubuntu1604'
99+
dir: 'artifacts'
100+
entrypoint: 'bash'
101+
args: [ '-c', 'tar -xvf kpt_darwin_amd64_${_VERSION}.tar.gz kpt && mv kpt kpt_darwin_amd64' ]
127102

128-
# copy latest
129-
- name: 'kpt-builder'
130-
args: ['mkdir', '/workspace/latest/darwin_amd64/']
131-
- name: 'kpt-builder'
132-
args: ['cp', '-r', '/workspace/releases/${TAG_NAME}/darwin_amd64/kpt', '/workspace/latest/darwin_amd64/kpt']
133-
- name: 'kpt-builder'
134-
args: ['cp', '/workspace/releases/${TAG_NAME}/darwin_amd64/kpt_darwin_amd64-${TAG_NAME}.tar.gz', '/workspace/latest/darwin_amd64/kpt_darwin_amd64.tar.gz']
103+
- name: 'gcr.io/cloud-builders/gsutil'
104+
dir: 'artifacts'
105+
args: [ 'cp', '-a', 'public-read', 'kpt_darwin_amd64', 'gs://${_GCS_BUCKET}/latest/darwin_amd64/kpt' ]
135106

136-
# Cleanup by removing files that have been packaged into the
137-
# tarball.
138-
- name: 'kpt-builder'
139-
args: ['rm', '-f',
140-
'/workspace/releases/${TAG_NAME}/darwin_amd64/kpt',
141-
'/workspace/releases/${TAG_NAME}/darwin_amd64/LICENSES.txt',
142-
'/workspace/releases/${TAG_NAME}/darwin_amd64/lib.zip']
107+
- name: 'gcr.io/cloud-builders/gsutil'
108+
dir: 'artifacts'
109+
args: [ 'cp', '-a', 'public-read', 'kpt_linux_amd64_${_VERSION}.tar.gz', 'gs://${_GCS_BUCKET}/releases/${TAG_NAME}/linux_amd64/kpt_linux_amd64_${TAG_NAME}.tar.gz' ]
110+
111+
- name: 'gcr.io/cloud-builders/gsutil'
112+
dir: 'artifacts'
113+
args: [ 'cp', '-a', 'public-read', 'kpt_linux_amd64_${_VERSION}.tar.gz', 'gs://${_GCS_BUCKET}/latest/linux_amd64/kpt_linux_amd64.tar.gz' ]
114+
115+
- name: 'launcher.gcr.io/google/ubuntu1604'
116+
dir: 'artifacts'
117+
entrypoint: 'bash'
118+
args: [ '-c', 'tar -xvf kpt_linux_amd64_${_VERSION}.tar.gz kpt && mv kpt kpt_linux_amd64' ]
119+
120+
- name: 'gcr.io/cloud-builders/gsutil'
121+
dir: 'artifacts'
122+
args: [ 'cp', '-a', 'public-read', 'kpt_linux_amd64', 'gs://${_GCS_BUCKET}/latest/linux_amd64/kpt' ]
123+
124+
- name: 'gcr.io/cloud-builders/gsutil'
125+
dir: 'artifacts'
126+
args: [ 'cp', '-a', 'public-read', 'kpt_windows_amd64_${_VERSION}.tar.gz', 'gs://${_GCS_BUCKET}/releases/${TAG_NAME}/windows_amd64/kpt_windows_amd64_${TAG_NAME}.tar.gz' ]
127+
128+
- name: 'gcr.io/cloud-builders/gsutil'
129+
dir: 'artifacts'
130+
args: [ 'cp', '-a', 'public-read', 'kpt_windows_amd64_${_VERSION}.tar.gz', 'gs://${_GCS_BUCKET}/latest/windows_amd64/kpt_windows_amd64.tar.gz' ]
131+
132+
- name: 'launcher.gcr.io/google/ubuntu1604'
133+
dir: 'artifacts'
134+
entrypoint: 'bash'
135+
args: [ '-c', 'tar -xvf kpt_windows_amd64_${_VERSION}.tar.gz kpt.exe && mv kpt.exe kpt_windows_amd64.exe' ]
136+
137+
- name: 'gcr.io/cloud-builders/gsutil'
138+
dir: 'artifacts'
139+
args: [ 'cp', '-a', 'public-read', 'kpt_windows_amd64.exe', 'gs://${_GCS_BUCKET}/latest/windows_amd64/kpt.exe' ]
143140

144141
# build docker image
145142
- name: 'gcr.io/cloud-builders/docker'
143+
dir: 'kpt'
146144
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/kpt:${TAG_NAME}', '.' ]
147145

148146
- name: 'gcr.io/cloud-builders/docker'
147+
dir: 'kpt'
149148
args: [ 'tag', 'gcr.io/$PROJECT_ID/kpt:${TAG_NAME}', 'gcr.io/$PROJECT_ID/kpt:latest' ]
150149

151150
- name: 'gcr.io/cloud-builders/docker'
152-
args: [ 'build', '-t', 'gcr.io/kpt-dev/example-functions:${TAG_NAME}', '-f', 'functions/examples/Dockerfile', '.' ]
151+
dir: 'kpt'
152+
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/example-functions:${TAG_NAME}', '-f', 'functions/examples/Dockerfile', '.' ]
153153

154154
- name: 'gcr.io/cloud-builders/docker'
155-
args: [ 'tag', 'gcr.io/kpt-dev/example-functions:${TAG_NAME}', 'gcr.io/kpt-dev/example-functions:latest' ]
156-
157-
# run e2e tests and linting
158-
- name: 'kpt-builder'
159-
args: ['git', 'config', '--global', 'user.email', '[email protected]']
160-
dir: '/workspace'
161-
volumes:
162-
- name: home
163-
path: /root
164-
- name: 'kpt-builder'
165-
args: ['git', 'config', '--global', 'user.name', 'Your Name']
166-
dir: '/workspace'
167-
volumes:
168-
- name: home
169-
path: /root
170-
- name: 'kpt-builder'
171-
args: ['make', 'all']
172-
env: ['GO111MODULE=on']
173-
dir: '/workspace'
174-
volumes:
175-
- name: go-modules
176-
path: /go
177-
- name: home
178-
path: /root
155+
dir: 'kpt'
156+
args: [ 'tag', 'gcr.io/$PROJECT_ID/example-functions:${TAG_NAME}', 'gcr.io/$PROJECT_ID/example-functions:latest' ]
179157

180158
# push the container image
181159
- name: 'gcr.io/cloud-builders/docker'
@@ -187,18 +165,10 @@ steps:
187165

188166
# push the container image
189167
- name: 'gcr.io/cloud-builders/docker'
190-
args: ['push', 'gcr.io/kpt-dev/example-functions:${TAG_NAME}']
168+
args: ['push', 'gcr.io/$PROJECT_ID/example-functions:${TAG_NAME}']
191169

192170
# update latest tag on release
193171
- name: 'gcr.io/cloud-builders/docker'
194-
args: ['push', 'gcr.io/kpt-dev/example-functions:latest']
195-
196-
# push the binaries
197-
- name: 'gcr.io/cloud-builders/gsutil'
198-
args: ['cp', '-r', '-a', 'public-read', '/workspace/releases/', 'gs://kpt-dev/']
199-
200-
# update the latest binaries
201-
- name: 'gcr.io/cloud-builders/gsutil'
202-
args: ['cp', '-r', '-a', 'public-read', '/workspace/latest', 'gs://kpt-dev/']
172+
args: ['push', 'gcr.io/$PROJECT_ID/example-functions:latest']
203173

204174
timeout: '60m'

release/tag/goreleaser.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
builds:
16+
- env:
17+
- CGO_ENABLED=0
18+
- GO111MODULE=on
19+
goos:
20+
- darwin
21+
- linux
22+
- windows
23+
goarch:
24+
- amd64
25+
ldflags: -s -w -X github.com/GoogleContainerTools/kpt/run.version={{.Version}}
26+
archives:
27+
- files:
28+
- LICENSE*
29+
- README*
30+
- CHANGELOG*
31+
- lib.zip*
32+
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}_{{ .Version }}"
33+
checksum:
34+
name_template: 'checksums.txt'
35+
snapshot:
36+
name_template: "master"
37+
changelog:
38+
sort: asc
39+
filters:
40+
exclude:
41+
- '^docs:'
42+
- '^test:'
43+
- Merge pull request
44+
- Merge branch
45+
release:
46+
github:
47+
owner: GoogleContainerTools
48+
name: kpt

0 commit comments

Comments
 (0)