Skip to content

Commit 1c5398b

Browse files
Publish Helm charts (#86)
1 parent 98b8a85 commit 1c5398b

File tree

3 files changed

+185
-10
lines changed

3 files changed

+185
-10
lines changed

.circleci/config.yml

Lines changed: 120 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ commands:
3131
- checkout
3232

3333
jobs:
34-
validate-charts:
35-
executor: deploy
36-
steps:
37-
- checkout
38-
- run:
39-
command: ./do kubeconform
40-
when: always
41-
- notify_failing_main
34+
# Images
4235
scan_postgresql:
4336
executor: ccc
4437
steps:
@@ -115,10 +108,70 @@ jobs:
115108
MAJOR_VERSION: 6.2
116109
pwd: redis/6.2/debian-10
117110

111+
# Charts
112+
validate-charts:
113+
executor: deploy
114+
steps:
115+
- checkout
116+
- run:
117+
command: ./do kubeconform
118+
when: always
119+
- notify_failing_main
120+
package-charts:
121+
executor: deploy
122+
steps:
123+
- checkout
124+
- run:
125+
name: Install signing keys
126+
command: |
127+
exec 2>/dev/null
128+
129+
echo "Importing signing keys"
130+
echo -n "${SIGNING_KEY_ENCODED}" | base64 --decode >signing_key_decoded.key
131+
gpg --batch --yes --passphrase "${SIGNING_KEY_PASSPHRASE}" --import signing_key_decoded.key
132+
rm signing_key_decoded.key
133+
curl https://keys.openpgp.org/vks/v1/by-fingerprint/"${GPG_ID}" >pub-key.asc
134+
gpg --import pub-key.asc
135+
rm pub-key.asc
136+
137+
echo "Convert to legacy gpg format per Helm requirements"
138+
gpg --export >~/.gnupg/pubring.gpg
139+
gpg --batch --yes --pinentry-mode=loopback --passphrase "${SIGNING_KEY_PASSPHRASE}" --export-secret-keys "${GPG_ID}" >~/.gnupg/secring.gpg
140+
- run:
141+
name: Package and sign chart
142+
command: |
143+
echo "${SIGNING_KEY_PASSPHRASE}" | ./do package-all-charts ./helm sign --passphrase-file -
144+
- persist_to_workspace:
145+
root: .
146+
paths: [./target]
147+
- notify_failing_main
148+
publish-chart:
149+
executor: deploy
150+
parameters:
151+
repo:
152+
type: string
153+
chart_name:
154+
type: string
155+
steps:
156+
- checkout
157+
- attach_workspace:
158+
at: .
159+
- run:
160+
name: Install package_cloud
161+
command: |
162+
sudo apt-get update && sudo apt-get install ruby-rubygems -y
163+
sudo gem install --no-document package_cloud
164+
- run:
165+
name: Publish Helm chart
166+
command: |
167+
package_cloud push circleci/<< parameters.repo >>/helm/v1 \
168+
./target/<< parameters.chart_name >>*.tgz
169+
- notify_failing_main
170+
118171
workflows:
119172
my-workflow:
120173
jobs:
121-
- validate-charts
174+
# Image jobs
122175
- scan_rabbitmq:
123176
context: "org-global"
124177
filters:
@@ -175,3 +228,61 @@ workflows:
175228
only:
176229
- main
177230
- /^server-\d\..+/
231+
232+
# Chart jobs
233+
- validate-charts
234+
- package-charts:
235+
context: releng-signing
236+
requires: [validate-charts]
237+
# Mongo chart
238+
- approve-publish-mongo-chart:
239+
type: approval
240+
filters:
241+
branches:
242+
only: [main, /^server-\d\..+/]
243+
requires: [package-charts]
244+
- publish-chart:
245+
name: publish-mongo-chart
246+
repo: server-mongo
247+
chart_name: mongodb
248+
requires: [approve-publish-mongo-chart]
249+
context: runner-package-deploy
250+
# Postgres chart
251+
- approve-publish-postgres-chart:
252+
type: approval
253+
filters:
254+
branches:
255+
only: [main, /^server-\d\..+/]
256+
requires: [package-charts, scan_postgresql]
257+
- publish-chart:
258+
name: publish-postgres-chart
259+
repo: server-postgres
260+
chart_name: postgresql
261+
requires: [approve-publish-postgres-chart]
262+
context: runner-package-deploy
263+
# RabbitMQ chart
264+
- approve-publish-rabbitmq-chart:
265+
type: approval
266+
filters:
267+
branches:
268+
only: [main, /^server-\d\..+/]
269+
requires: [package-charts, scan_rabbitmq]
270+
- publish-chart:
271+
name: publish-rabbitmq-chart
272+
repo: server-rabbitmq
273+
chart_name: rabbitmq
274+
requires: [approve-publish-rabbitmq-chart]
275+
context: runner-package-deploy
276+
# Redis chart
277+
- approve-publish-redis-chart:
278+
type: approval
279+
filters:
280+
branches:
281+
only: [main, /^server-\d\..+/]
282+
requires: [package-charts, scan_redis]
283+
- publish-chart:
284+
name: publish-redis-chart
285+
repo: server-redis
286+
chart_name: redis
287+
requires: [approve-publish-redis-chart]
288+
context: runner-package-deploy

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
charts/
1+
# File system and IDE files
2+
.DS_Store
3+
/.idea
4+
/*.iml
5+
6+
/bin
7+
/helm/*/charts/*.tgz
8+
/target

do

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,63 @@ kubeconform() {
2626
done
2727
}
2828

29+
# This variable is used, but shellcheck can't tell.
30+
# shellcheck disable=SC2034
31+
help_package_chart="Package a Helm chart"
32+
package-chart() {
33+
check-helm
34+
35+
chart_dir="${1:-.}"
36+
arg="${2:-}"
37+
if [ -n "${arg}" ]; then
38+
shift 2
39+
else
40+
shift
41+
fi
42+
43+
echo 'Updating dependencies'
44+
helm dependency update "${chart_dir}"
45+
46+
mkdir -p target
47+
48+
echo "Packaging Helm chart"
49+
case ${arg} in
50+
"sign")
51+
echo 'Signing Helm chart'
52+
# shellcheck disable=SC2086
53+
helm package --sign --key "${KEY:-<eng-on-prem@circleci.com>}" --keyring ${KEYRING:-~/.gnupg/secring.gpg} \
54+
--destination ./target "${chart_dir}" "$@"
55+
echo 'Verifying Helm chart signature'
56+
helm verify ./target/"$(basename "${chart_dir}")"*.tgz
57+
;;
58+
*)
59+
helm package --destination ./target "${chart_dir}"
60+
;;
61+
esac
62+
}
63+
64+
# This variable is used, but shellcheck can't tell.
65+
# shellcheck disable=SC2034
66+
help_package_all_charts="Package all Helm charts"
67+
package-all-charts() {
68+
charts_dir="${1:-./helm}"
69+
70+
if [ ! -d "${charts_dir}" ]; then
71+
echo "Charts directory '${charts_dir}' not found"
72+
return 1
73+
fi
74+
75+
stdin_data=$([ -t 0 ] || cat)
76+
77+
for chart_path in "${charts_dir}"/*; do
78+
if [ -d "${chart_path}" ]; then
79+
echo "Processing chart: $(basename "${chart_path}")"
80+
echo "${stdin_data}" | ./do package-chart "${chart_path}" "${@:2}"
81+
echo
82+
fi
83+
done
84+
}
85+
2986
check-helm() {
3087
if ! [ -x "$(command -v helm)" ]; then
3188
echo 'Helm is required. See: https://helm.sh/docs/intro/install/'

0 commit comments

Comments
 (0)