Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and publish multi-arch docker images on tag #323

Merged
merged 12 commits into from
Oct 1, 2021
42 changes: 24 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ version: 2.1

orbs:
aws-cli: circleci/aws-cli@1.3.0
docker: circleci/docker@1.3.0

executors:
linuxgo:
parameters:
docker:
- image: cimg/go:1.15
- image: cimg/go:1.16
- image: redis:6

commands:
Expand Down Expand Up @@ -124,6 +123,25 @@ jobs:
if [[ -z "$version" ]] ; then version=${CIRCLE_SHA1:0:7}; fi
aws s3 sync ~/artifacts s3://honeycomb-builds/honeycombio/refinery/$version/

publish_docker:
executor: linuxgo
steps:
- restore_cache:
keys:
googleko
- run: go install github.com/google/ko@latest
- save_cache:
key: googleko
paths:
- $GOPATH/bin/ko
- checkout
- setup_remote_docker
- run:
name: "Publish multi-arch docker image"
command: |
echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin;
build/build_docker.sh

workflows:
build:
jobs:
Expand Down Expand Up @@ -155,23 +173,11 @@ workflows:
only: /^v.*/
branches:
ignore: /.*/
- docker/publish:
tag: latest
extra_build_args: --build-arg BUILD_ID=${CIRCLE_SHA1:0:7}
image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME
requires:
- build
filters:
branches:
only: main
- docker/publish:
tag: latest,${CIRCLE_TAG:1}
extra_build_args: --build-arg BUILD_ID=${CIRCLE_TAG:1}
image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME
- publish_docker:
context: Honeycomb Secrets for Public Repos
requires:
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
only: /.*/

24 changes: 24 additions & 0 deletions build/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set -o nounset
set -o pipefail
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
set -o xtrace

TAGS="latest"
VERSION=${CIRCLE_TAG:-dev}
REPO=${KO_DOCKER_REPO:-ko.local}
if [[ $VERSION != "dev" ]]; then
# set docker username and add version tag
REPO="honeycombio"
TAGS+=",$VERSION"
fi

unset GOOS
unset GOARCH
export KO_DOCKER_REPO=$REPO
export GOFLAGS="-ldflags=-X=main.BuildID=$VERSION"
export SOURCE_DATE_EPOCH=$(date +%s)
# shellcheck disable=SC2086
ko publish \
--tags "${TAGS}" \
--base-import-paths \
--platform "linux/amd64,linux/arm64" \
./cmd/refinery
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/honeycombio/refinery

go 1.14
go 1.16

require (
github.com/davecgh/go-spew v1.1.1
Expand Down