From 186114185afe3ce7974585a3c22e4f4a407a89f0 Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Thu, 19 Mar 2020 15:24:49 -0700 Subject: [PATCH] Automate asset upload when creating a release When creating a release, the necessary assets (yaml manifests and antctl binaries) will now be added to the release automatically by a Github workflow. This reduces the potential for human error. For antctl, we build and upload the following binaries: * linux: amd64, arm64, arm (arm/v7) * darwin: amd64 * windows: amd64 Fixes #312 --- .github/workflows/build_tag.yml | 2 +- .github/workflows/upload_release_assets.yml | 108 ++++++++++++++++++++ Makefile | 22 ++-- docs/antctl.md | 7 +- docs/maintainers/release.md | 26 ++--- hack/release/prepare-assets.sh | 66 ++++++++++++ 6 files changed, 200 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/upload_release_assets.yml create mode 100755 hack/release/prepare-assets.sh diff --git a/.github/workflows/build_tag.yml b/.github/workflows/build_tag.yml index 5a34e348976..154ec790380 100644 --- a/.github/workflows/build_tag.yml +++ b/.github/workflows/build_tag.yml @@ -31,4 +31,4 @@ jobs: run: | VERSION="${TAG:10}" make octant-antrea-ubuntu echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker push antrea/octant-antrea-ubuntu:"${TAG:10}" \ No newline at end of file + docker push antrea/octant-antrea-ubuntu:"${TAG:10}" diff --git a/.github/workflows/upload_release_assets.yml b/.github/workflows/upload_release_assets.yml new file mode 100644 index 00000000000..a79776d9f3f --- /dev/null +++ b/.github/workflows/upload_release_assets.yml @@ -0,0 +1,108 @@ +name: Upload assets to release + +on: + release: + types: + - created + +jobs: + build: + runs-on: [ubuntu-18.04] + steps: + - uses: actions/checkout@v2 + - name: Build assets + env: + TAG: ${{ github.ref }} + run: | + mkdir assets + VERSION="${TAG:10}" ./hack/release/prepare-assets.sh ./assets + - name: Upload antctl-darwin-x86_64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antctl-darwin-x86_64 + asset_name: antctl-darwin-x86_64 + asset_content_type: application/octet-stream + - name: Upload antctl-linux-arm + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antctl-linux-arm + asset_name: antctl-linux-arm + asset_content_type: application/octet-stream + - name: Upload antctl-linux-arm64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antctl-linux-arm64 + asset_name: antctl-linux-arm64 + asset_content_type: application/octet-stream + - name: Upload antctl-linux-x86_64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antctl-linux-x86_64 + asset_name: antctl-linux-x86_64 + asset_content_type: application/octet-stream + - name: Upload antctl-windows-x86_64.exe + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antctl-windows-x86_64.exe + asset_name: antctl-windows-x86_64.exe + asset_content_type: application/octet-stream + - name: Upload antrea.yml + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antrea.yml + asset_name: antrea.yml + asset_content_type: application/octet-stream + - name: Upload antrea-ipsec.yml + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antrea-ipsec.yml + asset_name: antrea-ipsec.yml + asset_content_type: application/octet-stream + - name: Upload antrea-eks.yml + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antrea-eks.yml + asset_name: antrea-eks.yml + asset_content_type: application/octet-stream + - name: Upload antrea-gke.yml + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antrea-gke.yml + asset_name: antrea-gke.yml + asset_content_type: application/octet-stream + - name: Upload antrea-octant.yml + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./assets/antrea-octant.yml + asset_name: antrea-octant.yml + asset_content_type: application/octet-stream diff --git a/Makefile b/Makefile index 495319e616a..9733b62383d 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,13 @@ -SHELL := /bin/bash +SHELL := /bin/bash # go options -GO ?= go -LDFLAGS := -GOFLAGS := -BINDIR := $(CURDIR)/bin -GO_FILES := $(shell find . -type d -name '.cache' -prune -o -type f -name '*.go' -print) -GOPATH ?= $$($(GO) env GOPATH) -DOCKER_CACHE := $(CURDIR)/.cache +GO ?= go +LDFLAGS := +GOFLAGS := +BINDIR ?= $(CURDIR)/bin +GO_FILES := $(shell find . -type d -name '.cache' -prune -o -type f -name '*.go' -print) +GOPATH ?= $$($(GO) env GOPATH) +DOCKER_CACHE := $(CURDIR)/.cache +ANTCTL_BINARY_NAME ?= antctl .PHONY: all all: build @@ -94,7 +95,6 @@ docker-tidy: $(DOCKER_CACHE) .linux-bin: GOBIN=$(BINDIR) $(GO) install $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/... -# TODO: strip binary when building releases ANTCTL_BINARIES := antctl-darwin antctl-linux antctl-windows $(ANTCTL_BINARIES): antctl-%: @GOOS=$* $(GO) build -o $(BINDIR)/$@ $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antctl @@ -107,6 +107,10 @@ $(ANTCTL_BINARIES): antctl-%: .PHONY: antctl antctl: $(ANTCTL_BINARIES) +.PHONY: antctl-release +antctl-release: + @$(GO) build -o $(BINDIR)/$(ANTCTL_BINARY_NAME) $(GOFLAGS) -ldflags '-s -w $(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antctl + .PHONY: .linux-test-unit .linux-test-unit: @echo diff --git a/docs/antctl.md b/docs/antctl.md index 944d0a9f8bb..b6da7b4b831 100644 --- a/docs/antctl.md +++ b/docs/antctl.md @@ -36,11 +36,10 @@ antctl version For Linux, we also publish binaries for Arm-based systems. -On Windows: +On Windows, using PowerShell: ``` -# if you have curl / curl.exe installed (otherwise download antctl with a browser) -curl -Lo antctl.exe https://github.com/vmware-tanzu/antrea/releases/download/v0.5.0/antctl-windows-x86_64 -Move-Item .\antctl-windows-x86_64.exe c:\some-dir-in-your-PATH\kubectl.exe +Invoke-WebRequest -Uri https://github.com/vmware-tanzu/antrea/releases/download/v0.5.0/antctl-windows-x86_64.exe -Outfile antctl.exe +Move-Item .\antctl.exe c:\some-dir-in-your-PATH\antctl.exe antctl version ``` diff --git a/docs/maintainers/release.md b/docs/maintainers/release.md index 3c267c8bf88..44beef6293e 100644 --- a/docs/maintainers/release.md +++ b/docs/maintainers/release.md @@ -8,26 +8,18 @@ release. We use `` as a placeholder for the release tag (e.g. `v0.1.0`). 1. a commit to update the [CHANGELOG](/CHANGELOG.md). 2. a commit to update [VERSION](/VERSION) as needed. - * Generate the manifest files for the release: - 1. `IMG_NAME=antrea/antrea-ubuntu IMG_TAG= ./hack/generate-manifest.sh --mode release > antrea.yml` - 2. `IMG_NAME=antrea/antrea-ubuntu IMG_TAG= ./hack/generate-manifest.sh --mode release --ipsec > antrea-ipsec.yml` - 3. `IMG_NAME=antrea/antrea-ubuntu IMG_TAG= ./hack/generate-manifest-sh --mode release - --encapMode networkPolicyOnly > antrea-eks.yml` - 4. `IMG_NAME=antrea/octant-antrea-ubuntu IMG_TAG= ./hack/generate-manifest-octant.sh - --mode release > antrea-octant.yml` - * Make the release on Github with the release branch as the target: copy the relevant section of the [CHANGELOG](/CHANGELOG.md) for the release - description and upload the manifests generated in the previous step (with the - same file names, otherwise the manifest link advertised in - [getting-started.md](getting-started.md) will not work!). Check the - `pre-release` box if applicable. + description and check the `pre-release` box if applicable. There is no need + to upload any assets as this will be done automatically by a Github workflow, + after you create the release. - * Check that: - 1. after a while (time for the Github workflows to complete) the docker - image has been pushed to [dockerhub](https://hub.docker.com/u/antrea) with - the correct tag. - 2. the following link works: `https://github.com/vmware-tanzu/antrea/releases/download//antrea.yml` + * After a while (time for the Github workflows to complete), check that: + 1. the docker image has been pushed to + [dockerhub](https://hub.docker.com/u/antrea) with the correct tag. + 2. the assets have been uploaded to the release (`antctl` binaries and yaml + manifests). In particular, the following link should work: + `https://github.com/vmware-tanzu/antrea/releases/download//antrea.yml`. * Open a PR against the master branch with the following commits: 1. the commit updating the [CHANGELOG](/CHANGELOG.md), cherry-picked from diff --git a/hack/release/prepare-assets.sh b/hack/release/prepare-assets.sh new file mode 100755 index 00000000000..00649d2f012 --- /dev/null +++ b/hack/release/prepare-assets.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +# Copyright 2020 Antrea Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script generates all the assets required for an Antrea Github release to +# the provided directory. +# Usage: VERSION=v1.0.0 ./prepare-artifacts.sh + +set -eo pipefail + +function echoerr { + >&2 echo "$@" + exit 1 +} + +if [ -z "$VERSION" ]; then + echoerr "Environment variable VERSION must be set" +fi + +if [ -z "$1" ]; then + echoerr "Argument required: output directory for assets" +fi + +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +pushd $THIS_DIR/../.. > /dev/null + +ANTCTL_BUILDS=( + "linux amd64 linux-x86_64" + "linux arm64 linux-arm64" + "linux arm linux-arm" + "windows amd64 windows-x86_64.exe" + "darwin amd64 darwin-x86_64" +) + +for build in "${ANTCTL_BUILDS[@]}"; do + args=($build) + os="${args[0]}" + arch="${args[1]}" + suffix="${args[2]}" + + GOOS=$os GOARCH=$arch ANTCTL_BINARY_NAME="antctl-$suffix" BINDIR=$1/ make antctl-release +done + +export IMG_NAME=antrea/antrea-ubuntu +export IMG_TAG=$VERSION + +./hack/generate-manifest.sh --mode release > $1/antrea.yml +./hack/generate-manifest.sh --mode release --ipsec > $1/antrea-ipsec.yml +./hack/generate-manifest.sh --mode release --encap-mode networkPolicyOnly > $1/antrea-eks.yml +./hack/generate-manifest.sh --mode release --cloud GKE --encap-mode noEncap > $1/antrea-gke.yml +./hack/generate-manifest-octant.sh --mode release > $1/antrea-octant.yml + +ls $1 | cat