Skip to content

Commit

Permalink
Adding release step that runs on repository being tagged (#183)
Browse files Browse the repository at this point in the history
* Adding release step that runs on repository being tagged

* Making RELEASE-TAG a valid env variable name by using underscore

* Temporarily alter TAG logic so it works on development branch

* Syntax fix

* Adding script to allow us to upload assets built as part of a release to the github release

* Fixing asset upload script and making it be more descriptive on error

* Add building for multiple platforms using gox to makefile

* Adding make release artifacts + adding them to GitHub release to config.yml

* Passing arguments to add-checksum-summary script

* Correctly retrieving release-id in add-checksum-summary

* Correcting zip output to .zip rather than .tar.gz

* Zipping just executable

* Removing development specific release details

This will make us release to real production docker using the proper commit SHA1 as expected on master

* Adding newline at end of file

* Update scripts/add-checksum-summary.sh

Co-Authored-By: jankaspar <2270833+jankaspar@users.noreply.github.com>
  • Loading branch information
JamesMurkin and jankaspar committed Oct 22, 2019
1 parent dc474f6 commit df8b1f7
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,49 @@ jobs:
- deploy-executor:
worker-id: "5"

release:
docker:
- image: circleci/golang:1.12.6
environment:
GO111MODULE: "on"
working_directory: /go/src/github.com/G-Research/k8s-batch
steps:
- checkout
- setup_remote_docker

- run:
name: Build armadactl release artifacts
command: make build-armadactl-release RELEASE_VERSION=${CIRCLE_TAG}

- store_artifacts:
path: dist/*

- run:
name: Upload artifacts to Github release
command: |
for artifact in ./dist/*; do
./scripts/upload-github-release-asset.sh ${GITHUB_TOKEN} ${CIRCLE_TAG} $artifact
done
./scripts/add-checksum-summary.sh ${GITHUB_TOKEN} ${CIRCLE_TAG}
- run:
name: Publish images
command: |
TAG=${CIRCLE_SHA1}
RELEASE_TAG=${CIRCLE_TAG}
echo ${DOCKERHUB_PASS} | docker login -u ${DOCKERHUB_USER} --password-stdin
docker pull gresearchdev/armada-server-dev:${TAG}
docker tag gresearchdev/armada-server-dev:${TAG} gresearchdev/armada-server:${RELEASE_TAG}
docker push gresearchdev/armada-server:${RELEASE_TAG}
docker pull gresearchdev/armada-executor-dev:${TAG}
docker tag gresearchdev/armada-executor-dev:${TAG} gresearchdev/armada-executor:${RELEASE_TAG}
docker push gresearchdev/armada-executor:${RELEASE_TAG}
workflows:
version: 2
build_and_deploy:
Expand All @@ -130,3 +173,9 @@ workflows:
filters:
branches:
only: master
- release:
filters:
tags:
only: /.*/
branches:
ignore: /.*/
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/gox v1.0.1 // indirect
github.com/oklog/ulid v1.3.1
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xC
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk=
Expand Down Expand Up @@ -135,6 +137,10 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
13 changes: 13 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ build-executor:
build-armadactl:
$(gobuild) -o ./bin/armadactl cmd/armadactl/main.go

build-armadactl-multiplatform:
go run github.com/mitchellh/gox -output="./bin/{{.OS}}-{{.Arch}}/armadactl" -arch="amd64" -os="windows linux darwin" ./cmd/armadactl/

ifndef RELEASE_VERSION
override RELEASE_VERSION = UNKNOWN_VERSION
endif

build-armadactl-release: build-armadactl-multiplatform
mkdir ./dist || true
tar -czvf ./dist/armadactl-$(RELEASE_VERSION)-linux-amd64.tar.gz -C ./bin/linux-amd64/ armadactl
tar -czvf ./dist/armadactl-$(RELEASE_VERSION)-darwin-amd64.tar.gz -C ./bin/darwin-amd64/ armadactl
zip -j ./dist/armadactl-$(RELEASE_VERSION)-windows-amd64.zip ./bin/windows-amd64/armadactl.exe

build-load-tester:
$(gobuild) -o ./bin/armada-load-tester cmd/armada-load-tester/main.go

Expand Down
42 changes: 42 additions & 0 deletions scripts/add-checksum-summary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
API_TOKEN=$1
RELEASE_TAG=$2

RELEASE_INFO_REPLY=$(curl --fail -H "Authorization: token $API_TOKEN" https://api.github.com/repos/G-Research/armada/releases/tags/$RELEASE_TAG)

if [ $? -ne 0 ]; then
echo "Failed to get release information from Github"
exit -1
fi

RELEASE_ID=$(echo $RELEASE_INFO_REPLY | jq -r '.id')

if [ $RELEASE_ID = null ]; then
echo "Failed to get id of release with tag $RELEASE_TAG"
exit -1
fi

BODY=$(echo $RELEASE_INFO_REPLY | jq '.body')

if [ "$BODY" = null ]; then
echo "Failed to get body of release with tag $RELEASE_TAG"
exit -1
fi

BODY="${BODY:1:${#BODY}-2}"
echo $BODY

DETAILS="$BODY"
DETAILS="${DETAILS}\n# Checksums"

for artifact in ./dist/*; do
SHA=$(sha256sum "${artifact}" | cut -d " " -f 1)
DETAILS="${DETAILS}\n"
DETAILS="${DETAILS}* $(basename $artifact) SHA256 \`$SHA\`"
done

JSON_STRING="{\"body\" : \"$DETAILS\"}"

echo "$JSON_STRING"


curl -H "Authorization: token $API_TOKEN" -X PATCH https://api.github.com/repos/G-Research/armada/releases/$RELEASE_ID --data "$JSON_STRING"
29 changes: 29 additions & 0 deletions scripts/upload-github-release-asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
API_TOKEN=$1
RELEASE_TAG=$2
FILE=$3

if [ ! -f $FILE ]; then
echo "Could not find file to upload, $FILE is not a valid file path"
exit -1
fi

RELEASE_INFO_REPLY=$(curl --fail -H "Authorization: token $API_TOKEN" https://api.github.com/repos/G-Research/armada/releases/tags/$RELEASE_TAG)

if [ $? -ne 0 ]; then
echo "Failed to get release information from Github"
exit -1
fi

RELEASE_ID=$(echo $RELEASE_INFO_REPLY | jq -r '.id')

if [ $RELEASE_ID = null ]; then
echo "Failed to get id of release with tag $RELEASE_TAG"
exit -1
fi

curl --fail -H "Authorization: token $API_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @$FILE "https://uploads.github.com/repos/G-Research/armada/releases/$RELEASE_ID/assets?name=$(basename $FILE)"

if [ $? -ne 0 ]; then
echo "Failed to upload file to Github"
exit -1
fi

0 comments on commit df8b1f7

Please sign in to comment.