Skip to content

Commit c882a16

Browse files
authored
Merge pull request #39 from buildkite/keithduncan/build-releases
Build and attach binaries to GitHub releases
2 parents 71e04a4 + 77cd5d8 commit c882a16

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed

.buildkite/Dockerfile-compile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM golang:1.16.5@sha256:91b3c5472d9a2ef12f3165aa8979825a5d8b059720b00412f89fc465a04aaa0c

.buildkite/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.5'
2+
3+
services:
4+
agent:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile-compile
8+
volumes:
9+
- ../:/work:cached
10+
working_dir: /work
11+
environment:
12+
- GOOS
13+
- GOARCH

.buildkite/pipeline.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,106 @@
11
steps:
2+
- wait
3+
4+
- label: ":linux: x86_64"
5+
plugins:
6+
docker-compose#v3.7.0:
7+
config: .buildkite/docker-compose.yml
8+
run: agent
9+
mount-buildkite-agent: true
10+
command: .buildkite/steps/build-binary.sh
11+
env:
12+
GOOS: linux
13+
GOARCH: amd64
14+
15+
- label: ":linux: arm64"
16+
plugins:
17+
docker-compose#v3.7.0:
18+
config: .buildkite/docker-compose.yml
19+
run: agent
20+
mount-buildkite-agent: true
21+
command: .buildkite/steps/build-binary.sh
22+
env:
23+
GOOS: linux
24+
GOARCH: arm64
25+
26+
- label: ":windows: x86_64"
27+
plugins:
28+
docker-compose#v3.7.0:
29+
config: .buildkite/docker-compose.yml
30+
run: agent
31+
mount-buildkite-agent: true
32+
command: .buildkite/steps/build-binary.sh
33+
env:
34+
GOOS: windows
35+
GOARCH: amd64
36+
37+
# Requires golang 1.17 with support for windows/arm64
38+
# https://tip.golang.org/doc/go1.17
39+
# https://github.com/golang/go/issues/36439
40+
# - label: ":windows: arm64"
41+
# plugins:
42+
# docker-compose#v3.7.0:
43+
# config: .buildkite/docker-compose.yml
44+
# run: agent
45+
# mount-buildkite-agent: true
46+
# command: .buildkite/steps/build-binary.sh
47+
# env:
48+
# GOOS: windows
49+
# GOARCH: arm64
50+
51+
- label: ":mac: x86_64"
52+
plugins:
53+
docker-compose#v3.7.0:
54+
config: .buildkite/docker-compose.yml
55+
run: agent
56+
mount-buildkite-agent: true
57+
command: .buildkite/steps/build-binary.sh
58+
env:
59+
GOOS: darwin
60+
GOARCH: amd64
61+
62+
- label: ":mac: arm64"
63+
plugins:
64+
docker-compose#v3.7.0:
65+
config: .buildkite/docker-compose.yml
66+
run: agent
67+
mount-buildkite-agent: true
68+
command: .buildkite/steps/build-binary.sh
69+
env:
70+
GOOS: darwin
71+
GOARCH: arm64
72+
73+
- wait
74+
275
- label: ":bash: :hammer:"
376
plugins:
477
docker-compose#v2.2.0:
578
run: tests
679

780
- label: "㊙️ git-credentials test"
881
command: .buildkite/test_credentials.sh
82+
83+
- wait
84+
85+
- block: ":git: tag?"
86+
prompt: "Tag this commit and attach binaries to a GitHub release?"
87+
fields:
88+
- text: "Version"
89+
hint: "The git tag to create e.g. v2.1.0"
90+
key: "version"
91+
branches:
92+
- master
93+
94+
- name: ":octocat: :rocket:"
95+
command: ".buildkite/steps/github-release.sh"
96+
branches:
97+
- master
98+
agents:
99+
queue: "deploy"
100+
plugins:
101+
- ecr#v2.0.0:
102+
login: true
103+
account-ids: "032379705303"
104+
- docker#v3.5.0:
105+
image: "032379705303.dkr.ecr.us-east-1.amazonaws.com/deploytools:2020.03"
106+
propagate-environment: true

.buildkite/steps/build-binary.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
pushd s3secrets-helper
6+
7+
mkdir -p pkg
8+
9+
binary="s3secrets-helper-${GOOS}-${GOARCH}"
10+
go build -o "pkg/${binary}"
11+
12+
buildkite-agent artifact upload "pkg/*"

.buildkite/steps/github-release.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo '--- Getting release version from buildkite meta-data'
6+
7+
VERSION=$(buildkite-agent meta-data get 'version')
8+
9+
if [ -z "${VERSION}" ]
10+
then
11+
echo "Error: Missing \$VERSION, set buildkite-agent meta-data version before invoking this step"
12+
exit 1
13+
fi
14+
15+
echo '--- Getting credentials from SSM'
16+
export GITHUB_RELEASE_ACCESS_TOKEN=$(aws ssm get-parameter --name /pipelines/elastic-ci-stack-s3-secrets-hooks/GITHUB_RELEASE_ACCESS_TOKEN --with-decryption --output text --query Parameter.Value --region us-east-1)
17+
18+
if [ -z "${GITHUB_RELEASE_ACCESS_TOKEN}" ]
19+
then
20+
echo "Error: Missing \$GITHUB_RELEASE_ACCESS_TOKEN, set AWS SSM /pipelines/elastic-ci-stack-s3-secrets-hooks/GITHUB_RELEASE_ACCESS_TOKEN in us-east-1 before invoking this step"
21+
exit 1
22+
fi
23+
24+
echo '--- Downloading releases'
25+
26+
rm -rf pkg
27+
mkdir -p pkg
28+
buildkite-agent artifact download "pkg/*"
29+
30+
echo '--- Creating GitHub Release'
31+
32+
export GITHUB_RELEASE_REPOSITORY="buildkite/elastic-ci-stack-s3-secrets-hooks"
33+
34+
github-release "${VERSION}" pkg/* --commit "$(git rev-parse HEAD)"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
if [ -z "${BUILDKITE_TAG}" ]
6+
then
7+
echo "No release steps to be uploaded"
8+
exit 0
9+
fi
10+
11+
buildkite-agent pipeline upload .buildkite/pipeline-release.yml

0 commit comments

Comments
 (0)