Skip to content

Commit 12e937f

Browse files
dalehamelleodido
authored andcommitted
fix: Migrate release process to github actions
This completely replaces the existing Travis-based scripts with Github Actions. - Images now built by CI will receive a docker tag corresponding to their git tag - Go release is called when any tag is pushed, which will use Github Actions to create the Github Release, and uploads cross-compiled Go binaries to it.
1 parent de43b67 commit 12e937f

9 files changed

+106
-48
lines changed

.github/workflows/build-and-test.yml

+30-3
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,59 @@ jobs:
1111
# 18.04.3 release has 5.0.0 kernel
1212
steps:
1313
- uses: actions/checkout@v2
14+
- run: git fetch --prune --unshallow # We want tags
15+
16+
- name: Initialize workflow variables
17+
id: vars
18+
shell: bash
19+
run: |
20+
if [ -n "${QUAY_TOKEN}" ];then
21+
echo "Quay token is set, will push an image"
22+
echo ::set-output name=QUAY_PUBLISH::true
23+
else
24+
echo "Quay token not set, skipping image push"
25+
fi
26+
27+
git_org=$(dirname ${{ github.repository }})
28+
echo GIT_ORG=${git_org} >> $GITHUB_ENV
29+
env:
30+
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
31+
1432
- name: Run tests
1533
run: |
1634
make test
35+
1736
- name: Build kubectl trace binary
1837
run: |
1938
make _output/bin/kubectl-trace
39+
2040
- name: Build CI image
2141
run: |
22-
./hack/ci-build-image.sh
42+
./build/scripts/ci-build-image.sh ${{ github.ref }}
43+
2344
- name: Run integration tests
2445
run: |
2546
make integration
47+
2648
- name: Build cross binaries
2749
run: |
2850
curl -LO https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_amd64.deb && sudo dpkg -i goreleaser_amd64.deb
2951
make cross
52+
3053
- uses: actions/upload-artifact@v1
3154
with:
3255
name: ${{ matrix.os }}-kubectl-trace-dist
3356
path: _output/bin/kubectl-trace
57+
3458
- uses: actions/upload-artifact@v1
3559
with:
3660
name: ${{ matrix.os }}-kubectl-trace-cross-dist
3761
path: dist
62+
3863
- name: Upload docker image
3964
if: >
40-
github.ref == 'ref/head/master'
65+
steps.vars.outputs.QUAY_PUBLISH
66+
env:
67+
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
4168
run: |
42-
./hack/ci-release-image.sh
69+
./build/scripts/ci-release-image.sh ${{ github.ref }}

.github/workflows/goreleaser.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ jobs:
1717
uses: actions/setup-go@v2
1818
with:
1919
go-version: 1.15
20-
- name: Run GoReleaser
21-
uses: goreleaser/goreleaser-action@v2
22-
with:
23-
version: latest
24-
args: release --rm-dist
20+
- name: Install goreleaser
21+
run: |
22+
curl -LO https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_amd64.deb && \
23+
sudo dpkg -i goreleaser_amd64.deb && \
24+
rm goreleaser_amd64.deb
25+
- name: Create release
26+
run: |
27+
make release
2528
env:
2629
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@ DOCKER ?= docker
55

66
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
77
GIT_COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
8+
GIT_TAG ?= $(shell git describe 2> /dev/null)
89
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
910
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
1011

11-
IMAGE_NAME_INIT ?= quay.io/iovisor/kubectl-trace-init
12-
IMAGE_NAME ?= quay.io/iovisor/kubectl-trace-bpftrace
12+
GIT_ORG ?= iovisor
13+
14+
IMAGE_NAME_INIT ?= quay.io/$(GIT_ORG)/kubectl-trace-init
15+
IMAGE_NAME ?= quay.io/$(GIT_ORG)/kubectl-trace-bpftrace
1316

1417
IMAGE_TRACERUNNER_BRANCH := $(IMAGE_NAME):$(GIT_BRANCH_CLEAN)
1518
IMAGE_TRACERUNNER_COMMIT := $(IMAGE_NAME):$(GIT_COMMIT)
19+
IMAGE_TRACERUNNER_TAG := $(IMAGE_NAME):$(GIT_TAG)
20+
IMAGE_TRACERUNNER_LATEST := $(IMAGE_NAME):latest
1621

1722
IMAGE_INITCONTAINER_BRANCH := $(IMAGE_NAME_INIT):$(GIT_BRANCH_CLEAN)
1823
IMAGE_INITCONTAINER_COMMIT := $(IMAGE_NAME_INIT):$(GIT_COMMIT)
24+
IMAGE_INITCONTAINER_TAG := $(IMAGE_NAME_INIT):$(GIT_TAG)
1925
IMAGE_INITCONTAINER_LATEST := $(IMAGE_NAME_INIT):latest
2026

2127
IMAGE_BUILD_FLAGS ?= "--no-cache"
@@ -57,24 +63,29 @@ image/build-init:
5763
-t $(IMAGE_INITCONTAINER_BRANCH) \
5864
-f ./build/Dockerfile.initcontainer ./build
5965
$(DOCKER) tag $(IMAGE_INITCONTAINER_BRANCH) $(IMAGE_INITCONTAINER_COMMIT)
66+
$(DOCKER) tag $(IMAGE_INITCONTAINER_BRANCH) $(IMAGE_INITCONTAINER_TAG)
6067

6168
.PHONY: image/build
6269
image/build:
6370
$(DOCKER) build \
6471
--build-arg bpftraceversion=$(BPFTRACEVERSION) \
72+
--build-arg GIT_ORG=$(GIT_ORG) \
6573
$(IMAGE_BUILD_FLAGS) \
6674
-t "$(IMAGE_TRACERUNNER_BRANCH)" \
6775
-f build/Dockerfile.tracerunner .
6876
$(DOCKER) tag $(IMAGE_TRACERUNNER_BRANCH) $(IMAGE_TRACERUNNER_COMMIT)
6977
$(DOCKER) tag "$(IMAGE_TRACERUNNER_BRANCH)" $(IMAGE_TRACERUNNER_BRANCH)
78+
$(DOCKER) tag "$(IMAGE_TRACERUNNER_BRANCH)" $(IMAGE_TRACERUNNER_TAG)
7079

7180

7281
.PHONY: image/push
7382
image/push:
7483
$(DOCKER) push $(IMAGE_TRACERUNNER_BRANCH)
7584
$(DOCKER) push $(IMAGE_TRACERUNNER_COMMIT)
85+
$(DOCKER) push $(IMAGE_TRACERUNNER_TAG)
7686
$(DOCKER) push $(IMAGE_INITCONTAINER_BRANCH)
7787
$(DOCKER) push $(IMAGE_INITCONTAINER_COMMIT)
88+
$(DOCKER) push $(IMAGE_INITCONTAINER_TAG)
7889

7990
.PHONY: image/latest
8091
image/latest:

build/Dockerfile.tracerunner

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ ARG bpftraceversion=v0.11.1
22
FROM quay.io/iovisor/bpftrace:$bpftraceversion as bpftrace
33

44
FROM golang:1.15-buster as gobuilder
5-
5+
ARG GIT_ORG=iovisor
6+
ENV GIT_ORG=$GIT_ORG
67
RUN apt-get update
78
RUN apt-get install -y make bash git
89

build/scripts/ci-build-image.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -xeo pipefail
3+
4+
git_ref=$1 # github.ref format: refs/REMOTE/REF
5+
# eg, refs/heads/BRANCH
6+
# refs/tags/v0.9.6-pre
7+
8+
git_base_ref=$(basename ${git_ref})
9+
10+
make=$(command -v make)
11+
12+
if [[ ! -z "${git_base_ref}" ]]; then
13+
makeopts="-e GIT_BRANCH=${git_base_ref} ${makeopts}"
14+
fi
15+
16+
$make $makeopts image/build
17+
$make $makeopts image/build-init

build/scripts/ci-release-image.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -xeo pipefail
3+
4+
# Script that builds and releases images to quay.io
5+
# It is expected to be run from github actions.
6+
# The secret "QUAY_TOKEN" is expected to be set, with access to a quay.io repository
7+
# The environment variable "QUAY_BOT_USER" can be used to override the default bot username
8+
GIT_ORG=${GIT_ORG:-iovisor}
9+
QUAY_BOT_USER=${QUAY_BOT_USER:-kubectltrace_buildbot}
10+
11+
git_ref=$1 # github.ref format: refs/REMOTE/REF
12+
# eg, refs/heads/BRANCH
13+
# refs/tags/v0.9.6-pre
14+
git_base_ref=$(basename ${git_ref})
15+
16+
make=$(command -v make)
17+
docker=$(command -v docker)
18+
19+
makeopts=""
20+
if [[ ! -z "${git_base_ref}" ]]; then
21+
makeopts="-e GIT_BRANCH=${git_base_ref} ${makeopts}"
22+
fi
23+
24+
if [[ ! -z "$QUAY_TOKEN" ]]; then
25+
$docker login -u="${GIT_ORG}+${QUAY_BOT_USER}" -p="$QUAY_TOKEN" quay.io
26+
$make $makeopts image/push
27+
28+
if [[ "${git_ref_id}" = "master" ]] && [[ "${git_base_ref}" = "" ]]; then
29+
$make $makeopts image/latest
30+
fi
31+
fi

docs/release.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ When we release we do the following process:
1212

1313
## Release commands
1414

15-
Tag the version
15+
Tag the version:
1616

1717
```bash
1818
git tag -a v0.1.0-rc.0 -m "v0.1.0-rc.0"
1919
git push origin v0.1.0-rc.0
2020
```
2121

22-
Run goreleaser, make sure to export your GitHub token first.
22+
From there, github actions should automatically create the release, as it sets
23+
the `GITHUB_TOKEN`.
24+
25+
In case you need to run a release manually, so long as you are an administrator:
2326

2427
```
2528
export GITHUB_TOKEN=<YOUR_GH_TOKEN>
2629
make release
2730
```
28-

hack/ci-build-image.sh

-12
This file was deleted.

hack/ci-release-image.sh

-22
This file was deleted.

0 commit comments

Comments
 (0)