Skip to content

Commit

Permalink
Automate asset upload when creating a release
Browse files Browse the repository at this point in the history
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
  • Loading branch information
antoninbas committed Mar 25, 2020
1 parent e3c0072 commit 47700ae
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
docker push antrea/octant-antrea-ubuntu:"${TAG:10}"
108 changes: 108 additions & 0 deletions .github/workflows/upload_release_assets.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions docs/antctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
26 changes: 9 additions & 17 deletions docs/maintainers/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,18 @@ release. We use `<TAG>` 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=<TAG> ./hack/generate-manifest.sh --mode release > antrea.yml`
2. `IMG_NAME=antrea/antrea-ubuntu IMG_TAG=<TAG> ./hack/generate-manifest.sh --mode release --ipsec > antrea-ipsec.yml`
3. `IMG_NAME=antrea/antrea-ubuntu IMG_TAG=<TAG> ./hack/generate-manifest-sh --mode release
--encapMode networkPolicyOnly > antrea-eks.yml`
4. `IMG_NAME=antrea/octant-antrea-ubuntu IMG_TAG=<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/<TAG>/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/<TAG>/antrea.yml`.

* Open a PR against the master branch with the following commits:
1. the commit updating the [CHANGELOG](/CHANGELOG.md), cherry-picked from
Expand Down
66 changes: 66 additions & 0 deletions hack/release/prepare-assets.sh
Original file line number Diff line number Diff line change
@@ -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 <output dir>

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

0 comments on commit 47700ae

Please sign in to comment.