diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index e7bf02cd..86a0e5e0 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -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 }} diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index eff5bcce..b3d090f4 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -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 }} diff --git a/Makefile b/Makefile index 3398ba99..b6d85cd2 100644 --- a/Makefile +++ b/Makefile @@ -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" @@ -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: diff --git a/build/Dockerfile.tracerunner b/build/Dockerfile.tracerunner index af42e81f..510c8d4f 100644 --- a/build/Dockerfile.tracerunner +++ b/build/Dockerfile.tracerunner @@ -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 diff --git a/build/scripts/ci-build-image.sh b/build/scripts/ci-build-image.sh new file mode 100755 index 00000000..ba954f62 --- /dev/null +++ b/build/scripts/ci-build-image.sh @@ -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 diff --git a/build/scripts/ci-release-image.sh b/build/scripts/ci-release-image.sh new file mode 100755 index 00000000..e44d2127 --- /dev/null +++ b/build/scripts/ci-release-image.sh @@ -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 diff --git a/docs/release.md b/docs/release.md index 97b212bc..9e509629 100644 --- a/docs/release.md +++ b/docs/release.md @@ -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= make release ``` - diff --git a/hack/ci-build-image.sh b/hack/ci-build-image.sh deleted file mode 100755 index 2f27d309..00000000 --- a/hack/ci-build-image.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -xeo pipefail - -make=$(command -v make) - -makeopts="" -if [[ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]]; then - makeopts="-e GIT_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH" -fi - -$make $makeopts image/build -$make $makeopts image/build-init diff --git a/hack/ci-release-image.sh b/hack/ci-release-image.sh deleted file mode 100755 index c3d340f0..00000000 --- a/hack/ci-release-image.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -set -xeo pipefail - -# Script that builds the bpftrace image and releases -# it to quay only if the request is coming from the main repo. - -make=$(command -v make) -docker=$(command -v docker) - -makeopts="" -if [[ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]]; then - makeopts="-e GIT_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH" -fi - -if [[ ! -z "$QUAY_TOKEN" ]]; then - $docker login -u="iovisor+kubectltracetravisci" -p="$QUAY_TOKEN" quay.io - $make $makeopts image/push -fi - -if [[ "$TRAVIS_BRANCH" = "master" && "$TRAVIS_PULL_REQUEST_BRANCH" = "" ]]; then - $make $makeopts image/latest -fi