Skip to content

Commit fef055e

Browse files
authored
Merge pull request #581 from Mirantis/ivan4th/release-automation
Implement release automation
2 parents 000b633 + 39c9e13 commit fef055e

File tree

6 files changed

+115
-15
lines changed

6 files changed

+115
-15
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,25 @@ jobs:
333333
push_tested:
334334
<<: *push_images
335335

336+
release:
337+
<<: *defaults
338+
steps:
339+
- run:
340+
<<: *prereqs
341+
- checkout
342+
- setup_remote_docker
343+
- run:
344+
<<: *setup_env
345+
- restore_cache:
346+
<<: *restore_image_cache
347+
- run:
348+
<<: *restore_images_and_vendor
349+
- run:
350+
name: Make a release
351+
command: |
352+
build/portforward.sh 18730&
353+
build/cmd.sh release "${CIRCLE_TAG}"
354+
336355
workflows:
337356
version: 2
338357
build-and-test:
@@ -416,3 +435,12 @@ workflows:
416435
tags:
417436
only:
418437
- /^v[0-9].*/
438+
- release:
439+
requires:
440+
- push_tested
441+
filters:
442+
branches:
443+
ignore: /.*/
444+
tags:
445+
only:
446+
- /^v[0-9].*/

build/cmd.sh

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ containers_run='.items[0].spec.template.spec.containers|=map(.volumeMounts|=map(
4141
initContainers_run='.items[0].spec.template.spec.initContainers|=map(.volumeMounts|=map(select(.name!="run"))+[{"mountPath": "/run:shared", "name": "run"}])'
4242
containers_k8s_dir='.items[0].spec.template.spec.containers[1].volumeMounts|=map(select(.name!="k8s-pods-dir"))+[{"mountPath": "/var/lib/kubelet/pods:shared", "name": "k8s-pods-dir"}]'
4343

44+
function image_tags_filter {
45+
local tag="${1}"
46+
local prefix=".items[0].spec.template.spec."
47+
local suffix="|=map(.image=\"mirantis/virtlet:${tag}\")"
48+
echo -n "${prefix}containers${suffix}|${prefix}initContainers${suffix}"
49+
}
50+
4451
# from build/common.sh in k8s
4552
function rsync_probe {
4653
# Wait unil rsync is up and running.
@@ -160,6 +167,7 @@ function ensure_build_container {
160167
-e CIRCLE_PULL_REQUEST="${CIRCLE_PULL_REQUEST:-}" \
161168
-e CIRCLE_BRANCH="${CIRCLE_PULL_REQUEST:-}" \
162169
-e VIRTLET_ON_MASTER="${VIRTLET_ON_MASTER:-}" \
170+
-e GITHUB_TOKEN="${GITHUB_TOKEN:-}" \
163171
${docker_cert_args[@]+"${docker_cert_args[@]}"} \
164172
--name virtlet-build \
165173
--tmpfs /tmp \
@@ -348,9 +356,6 @@ function build_image_internal {
348356
}
349357

350358
function install_vendor_internal {
351-
if ! hash glide 2>/dev/null; then
352-
go get github.com/Masterminds/glide
353-
fi
354359
if [ ! -d vendor ]; then
355360
glide install --strip-vendor
356361
fi
@@ -375,6 +380,47 @@ function build_internal {
375380
go test -i -c -o "${project_dir}/_output/virtlet-e2e-tests" ./tests/e2e
376381
}
377382

383+
function patch_yaml {
384+
local kubectl="${1}"
385+
local filter="${2}"
386+
"${kubectl}" convert --local -o json -f deploy/virtlet-ds.yaml |
387+
jq "${filter}" |
388+
"${kubectl}" convert --local -o yaml -f -
389+
}
390+
391+
function release_internal {
392+
local tag="${1}"
393+
local -a opts=(--user Mirantis --repo virtlet --tag "${tag}")
394+
local pre_release=
395+
# TODO: uncomment this 'if/fi' once we start making 'non-pre' releases
396+
# if [[ ${tag} =~ -(test|pre).*$ ]]; then
397+
pre_release="--pre-release"
398+
# fi
399+
if github-release --quiet delete "${opts[@]}"; then
400+
echo >&2 "Replacing the old Virtlet release"
401+
fi
402+
github-release release "${opts[@]}" \
403+
--name "$(git tag -l --format='%(contents:subject)' "${tag}")" \
404+
--description "$(git tag -l --format='%(contents:body)' "${tag}")" \
405+
${pre_release}
406+
# piping the patched yaml directly to
407+
# 'github-release upload ... --file -' causes GH API error:
408+
# "error: could not upload, status code (400 Bad Request), msg: Bad Content-Length: , errors:"
409+
mkdir -p _output
410+
patch_yaml kubectl "$(image_tags_filter "${tag}")" >_output/virtlet-ds.yaml
411+
github-release upload "${opts[@]}" \
412+
--name virtlet-ds.yaml \
413+
--replace \
414+
--file _output/virtlet-ds.yaml
415+
# use older kubectl for 1.7 to avoid making yaml
416+
# that can't be consumed by k8s 1.7
417+
patch_yaml kubectl.old "$(image_tags_filter "${tag}")|${containers_run}|${initContainers_run}|${containers_k8s_dir}" >_output/virtlet-ds-1.7.yaml
418+
github-release upload "${opts[@]}" \
419+
--name virtlet-ds-1.7.yaml \
420+
--replace \
421+
--file _output/virtlet-ds-1.7.yaml
422+
}
423+
378424
function e2e {
379425
ensure_build_container
380426
local cluster_url
@@ -395,6 +441,7 @@ function usage {
395441
echo >&2 " $0 gotest [TEST_ARGS...]"
396442
echo >&2 " $0 gobuild [BUILD_ARGS...]"
397443
echo >&2 " $0 run CMD..."
444+
echo >&2 " $0 release TAG"
398445
exit 1
399446
}
400447

@@ -470,6 +517,15 @@ case "${cmd}" in
470517
start-build-container)
471518
ensure_build_container
472519
;;
520+
release)
521+
if [[ ! ${1:-} ]]; then
522+
echo >&2 "must specify the tag"
523+
fi
524+
( vcmd "build/cmd.sh release-internal '${1}'" )
525+
;;
526+
release-internal)
527+
release_internal "$@"
528+
;;
473529
*)
474530
usage
475531
;;

images/Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# TODO: generate this tag. unfortunately can't use ARG:
22
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
33
# (but add a note about it here for the future)
4-
FROM mirantis/virtlet-build:v1-b6890e358ebebdad0ce449322a3d2646
4+
FROM mirantis/virtlet-build:v1-d9d67ed7fd827238a8f604db7e3baeaa
55
MAINTAINER Ivan Shvedunov <[email protected]>
66

77
LABEL virtlet.image="build"

images/Dockerfile.build-base

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# TODO: generate this tag. unfortunately can't use ARG:
22
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
33
# (but add a note about it here for the future)
4-
FROM mirantis/virtlet-base:v1-13deb720a48ab153ce8bbe95840af75e
4+
FROM mirantis/virtlet-base:v1-22de6b4e88a489a2c0b441e3f3d01a3e
55
MAINTAINER Ivan Shvedunov <[email protected]>
66

77
LABEL virtlet.image="build-base"
88

99
ENV DOCKER_CLIENT_VERSION 1.12.6
1010
ENV DOCKER_CLIENT_DOWNLOAD_URL_BASE https://get.docker.com/builds
1111
ENV DOCKER_CLIENT_SHA256 cce8aa52a33f007673b9c7ed0cb786359aa6f3f8a9875aaf69799c71f86e8a43
12-
ENV KUBECTL_VERSION v1.8.4
13-
ENV KUBECTL_SHA1 8e2314db816b9b4465c5f713c1152cb0603db15e
12+
ENV KUBECTL_VERSION v1.8.8
13+
ENV KUBECTL_SHA1 f6bc48e70202f168bd71e81dd1504686890cd5ed
14+
ENV OLD_KUBECTL_VERSION v1.7.12
15+
ENV OLD_KUBECTL_SHA1 385229d4189e4f7978de42f237d6c443c0534edd
1416

1517
# Go installation commands are based on official Go container:
1618
# https://github.com/docker-library/golang/blob/18ee81a2ec649dd7b3d5126b24eef86bc9c86d80/1.7/Dockerfile
@@ -35,11 +37,13 @@ RUN apt-get update && \
3537
dhcpcd5 \
3638
tcpdump \
3739
iputils-ping \
38-
mercurial && \
40+
mercurial \
41+
jq && \
3942
apt-get clean
4043

4144
# Install docker client
42-
RUN curl -sSL "${DOCKER_CLIENT_DOWNLOAD_URL_BASE}/$(uname -s)/$(uname -m)/docker-${DOCKER_CLIENT_VERSION}.tgz" | \
45+
RUN mkdir -p /usr/local/bin && \
46+
curl -sSL "${DOCKER_CLIENT_DOWNLOAD_URL_BASE}/$(uname -s)/$(uname -m)/docker-${DOCKER_CLIENT_VERSION}.tgz" | \
4347
tar -C /usr/local/bin -xz --strip-components=1 docker/docker && \
4448
echo "${DOCKER_CLIENT_SHA256} /usr/local/bin/docker" | sha256sum -c -
4549

@@ -55,11 +59,14 @@ ENV PATH /go/src/github.com/Mirantis/virtlet/_output:$GOPATH/bin:/usr/local/go/b
5559
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
5660
WORKDIR $GOPATH
5761

58-
# Install kubectl
59-
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl
60-
RUN echo "${KUBECTL_SHA1} /usr/local/bin/kubectl" |sha1sum -c
61-
RUN mkdir -p /usr/local/bin
62-
RUN chmod +x /usr/local/bin/kubectl
62+
# Install kubectl.
63+
# Also install old kubectl for v1.7 (needed to make the release yaml)
64+
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl && \
65+
echo "${KUBECTL_SHA1} /usr/local/bin/kubectl" | sha1sum -c && \
66+
chmod +x /usr/local/bin/kubectl && \
67+
curl -L https://storage.googleapis.com/kubernetes-release/release/${OLD_KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl.old && \
68+
echo "${OLD_KUBECTL_SHA1} /usr/local/bin/kubectl.old" | sha1sum -c && \
69+
chmod +x /usr/local/bin/kubectl.old
6370

6471
# TODO: update CNI ver
6572
RUN mkdir -p ~/.ssh && \
@@ -73,3 +80,8 @@ RUN mkdir -p ~/.ssh && \
7380
RUN mkdir -p /images && \
7481
curl -L https://github.com/Mirantis/virtlet/releases/download/v0.8.2/cirros.img -o /images/cirros.img && \
7582
echo "${CIRROS_SHA256} /images/cirros.img" | sha256sum -c -
83+
84+
# Install Go tooling
85+
RUN go get github.com/aktau/github-release && \
86+
go get github.com/Masterminds/glide
87+

images/Dockerfile.virtlet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# TODO: generate this tag. unfortunately can't use ARG:
22
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
33
# (but add a note about it here for the future)
4-
FROM mirantis/virtlet-base:v1-13deb720a48ab153ce8bbe95840af75e
4+
FROM mirantis/virtlet-base:v1-22de6b4e88a489a2c0b441e3f3d01a3e
55
MAINTAINER Ivan Shvedunov <[email protected]>
66

77
LABEL virtlet.image="virtlet"

images/Dockerfile.virtlet-base

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ RUN apt-get update && \
1212
netbase iproute2 iptables ebtables vncsnapshot \
1313
socat && \
1414
apt-get clean
15+
16+
# 19 Feb 2018: bump: libvirt version problem
17+
# The following packages have unmet dependencies:
18+
# libvirt-bin : Breaks: qemu-kvm (< 1:2.5+dfsg-5ubuntu10.20~) but 1:2.5+dfsg-5ubuntu10.16 is to be installed

0 commit comments

Comments
 (0)