Skip to content

Commit

Permalink
fix: Migrate release process to github actions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dalehamel authored and leodido committed Oct 28, 2020
1 parent de43b67 commit 12e937f
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 48 deletions.
33 changes: 30 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,59 @@ jobs:
# 18.04.3 release has 5.0.0 kernel
steps:
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow # We want tags

- name: Initialize workflow variables
id: vars
shell: bash
run: |
if [ -n "${QUAY_TOKEN}" ];then
echo "Quay token is set, will push an image"
echo ::set-output name=QUAY_PUBLISH::true
else
echo "Quay token not set, skipping image push"
fi
git_org=$(dirname ${{ github.repository }})
echo GIT_ORG=${git_org} >> $GITHUB_ENV
env:
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

- name: Run tests
run: |
make test
- name: Build kubectl trace binary
run: |
make _output/bin/kubectl-trace
- name: Build CI image
run: |
./hack/ci-build-image.sh
./build/scripts/ci-build-image.sh ${{ github.ref }}
- name: Run integration tests
run: |
make integration
- name: Build cross binaries
run: |
curl -LO https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_amd64.deb && sudo dpkg -i goreleaser_amd64.deb
make cross
- uses: actions/upload-artifact@v1
with:
name: ${{ matrix.os }}-kubectl-trace-dist
path: _output/bin/kubectl-trace

- uses: actions/upload-artifact@v1
with:
name: ${{ matrix.os }}-kubectl-trace-cross-dist
path: dist

- name: Upload docker image
if: >
github.ref == 'ref/head/master'
steps.vars.outputs.QUAY_PUBLISH
env:
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
run: |
./hack/ci-release-image.sh
./build/scripts/ci-release-image.sh ${{ github.ref }}
13 changes: 8 additions & 5 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
- name: Install goreleaser
run: |
curl -LO https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_amd64.deb && \
sudo dpkg -i goreleaser_amd64.deb && \
rm goreleaser_amd64.deb
- name: Create release
run: |
make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ DOCKER ?= docker

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

IMAGE_NAME_INIT ?= quay.io/iovisor/kubectl-trace-init
IMAGE_NAME ?= quay.io/iovisor/kubectl-trace-bpftrace
GIT_ORG ?= iovisor

IMAGE_NAME_INIT ?= quay.io/$(GIT_ORG)/kubectl-trace-init
IMAGE_NAME ?= quay.io/$(GIT_ORG)/kubectl-trace-bpftrace

IMAGE_TRACERUNNER_BRANCH := $(IMAGE_NAME):$(GIT_BRANCH_CLEAN)
IMAGE_TRACERUNNER_COMMIT := $(IMAGE_NAME):$(GIT_COMMIT)
IMAGE_TRACERUNNER_TAG := $(IMAGE_NAME):$(GIT_TAG)
IMAGE_TRACERUNNER_LATEST := $(IMAGE_NAME):latest

IMAGE_INITCONTAINER_BRANCH := $(IMAGE_NAME_INIT):$(GIT_BRANCH_CLEAN)
IMAGE_INITCONTAINER_COMMIT := $(IMAGE_NAME_INIT):$(GIT_COMMIT)
IMAGE_INITCONTAINER_TAG := $(IMAGE_NAME_INIT):$(GIT_TAG)
IMAGE_INITCONTAINER_LATEST := $(IMAGE_NAME_INIT):latest

IMAGE_BUILD_FLAGS ?= "--no-cache"
Expand Down Expand Up @@ -57,24 +63,29 @@ image/build-init:
-t $(IMAGE_INITCONTAINER_BRANCH) \
-f ./build/Dockerfile.initcontainer ./build
$(DOCKER) tag $(IMAGE_INITCONTAINER_BRANCH) $(IMAGE_INITCONTAINER_COMMIT)
$(DOCKER) tag $(IMAGE_INITCONTAINER_BRANCH) $(IMAGE_INITCONTAINER_TAG)

.PHONY: image/build
image/build:
$(DOCKER) build \
--build-arg bpftraceversion=$(BPFTRACEVERSION) \
--build-arg GIT_ORG=$(GIT_ORG) \
$(IMAGE_BUILD_FLAGS) \
-t "$(IMAGE_TRACERUNNER_BRANCH)" \
-f build/Dockerfile.tracerunner .
$(DOCKER) tag $(IMAGE_TRACERUNNER_BRANCH) $(IMAGE_TRACERUNNER_COMMIT)
$(DOCKER) tag "$(IMAGE_TRACERUNNER_BRANCH)" $(IMAGE_TRACERUNNER_BRANCH)
$(DOCKER) tag "$(IMAGE_TRACERUNNER_BRANCH)" $(IMAGE_TRACERUNNER_TAG)


.PHONY: image/push
image/push:
$(DOCKER) push $(IMAGE_TRACERUNNER_BRANCH)
$(DOCKER) push $(IMAGE_TRACERUNNER_COMMIT)
$(DOCKER) push $(IMAGE_TRACERUNNER_TAG)
$(DOCKER) push $(IMAGE_INITCONTAINER_BRANCH)
$(DOCKER) push $(IMAGE_INITCONTAINER_COMMIT)
$(DOCKER) push $(IMAGE_INITCONTAINER_TAG)

.PHONY: image/latest
image/latest:
Expand Down
3 changes: 2 additions & 1 deletion build/Dockerfile.tracerunner
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ ARG bpftraceversion=v0.11.1
FROM quay.io/iovisor/bpftrace:$bpftraceversion as bpftrace

FROM golang:1.15-buster as gobuilder

ARG GIT_ORG=iovisor
ENV GIT_ORG=$GIT_ORG
RUN apt-get update
RUN apt-get install -y make bash git

Expand Down
17 changes: 17 additions & 0 deletions build/scripts/ci-build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -xeo pipefail

git_ref=$1 # github.ref format: refs/REMOTE/REF
# eg, refs/heads/BRANCH
# refs/tags/v0.9.6-pre

git_base_ref=$(basename ${git_ref})

make=$(command -v make)

if [[ ! -z "${git_base_ref}" ]]; then
makeopts="-e GIT_BRANCH=${git_base_ref} ${makeopts}"
fi

$make $makeopts image/build
$make $makeopts image/build-init
31 changes: 31 additions & 0 deletions build/scripts/ci-release-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -xeo pipefail

# Script that builds and releases images to quay.io
# It is expected to be run from github actions.
# The secret "QUAY_TOKEN" is expected to be set, with access to a quay.io repository
# The environment variable "QUAY_BOT_USER" can be used to override the default bot username
GIT_ORG=${GIT_ORG:-iovisor}
QUAY_BOT_USER=${QUAY_BOT_USER:-kubectltrace_buildbot}

git_ref=$1 # github.ref format: refs/REMOTE/REF
# eg, refs/heads/BRANCH
# refs/tags/v0.9.6-pre
git_base_ref=$(basename ${git_ref})

make=$(command -v make)
docker=$(command -v docker)

makeopts=""
if [[ ! -z "${git_base_ref}" ]]; then
makeopts="-e GIT_BRANCH=${git_base_ref} ${makeopts}"
fi

if [[ ! -z "$QUAY_TOKEN" ]]; then
$docker login -u="${GIT_ORG}+${QUAY_BOT_USER}" -p="$QUAY_TOKEN" quay.io
$make $makeopts image/push

if [[ "${git_ref_id}" = "master" ]] && [[ "${git_base_ref}" = "" ]]; then
$make $makeopts image/latest
fi
fi
8 changes: 5 additions & 3 deletions docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ When we release we do the following process:

## Release commands

Tag the version
Tag the version:

```bash
git tag -a v0.1.0-rc.0 -m "v0.1.0-rc.0"
git push origin v0.1.0-rc.0
```

Run goreleaser, make sure to export your GitHub token first.
From there, github actions should automatically create the release, as it sets
the `GITHUB_TOKEN`.

In case you need to run a release manually, so long as you are an administrator:

```
export GITHUB_TOKEN=<YOUR_GH_TOKEN>
make release
```

12 changes: 0 additions & 12 deletions hack/ci-build-image.sh

This file was deleted.

22 changes: 0 additions & 22 deletions hack/ci-release-image.sh

This file was deleted.

0 comments on commit 12e937f

Please sign in to comment.