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

Use SDK's Go toolchain #21

Merged
merged 4 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# and its dependencies. When building with `make container`, the licenses
# container image is built and provided as LICENSE_IMAGE.
ARG LICENSES_IMAGE=scratch

# GOLANG_IMAGE is the go toolchain container image used to build the update
# operator.
ARG GOLANG_IMAGE=golang:1.13

FROM $LICENSES_IMAGE as licenses
# Set WORKDIR to create /licenses/ if the directory is missing.
#
Expand All @@ -13,14 +18,15 @@ FROM $LICENSES_IMAGE as licenses
# LICENSES_IMAGE.
WORKDIR /licenses/

FROM golang:1.13 as build
ARG GO_LDFLAGS=
ARG GOARCH=
ARG SHORT_SHA=
FROM $GOLANG_IMAGE as build
USER root
ENV GOPROXY=direct
WORKDIR /src
COPY go.mod go.sum /src/
WORKDIR /src/
RUN go mod download
ARG GO_LDFLAGS=
ARG GOARCH=
ARG SHORT_SHA=
COPY ./ /src/
RUN make -e build GOBIN=/ CGO_ENABLED=0

Expand Down
33 changes: 18 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SHORT_SHA = $(shell git describe --abbrev=8 --always --dirty='-dev' --exclude '*
# image, it is appended to the IMAGE_NAME unless the name is specified.
IMAGE_ARCH_SUFFIX = $(addprefix -,$(ARCH))
# BUILDSYS_SDK_IMAGE is the Bottlerocket SDK image used for license scanning.
BUILDSYS_SDK_IMAGE ?= bottlerocket/sdk-x86_64:v0.8
BUILDSYS_SDK_IMAGE ?= bottlerocket/sdk-x86_64:v0.10.1
# LICENSES_IMAGE_NAME is the name of the container image that has LICENSE files
# for distribution.
LICENSES_IMAGE = $(IMAGE_NAME)-licenses
Expand Down Expand Up @@ -73,25 +73,27 @@ test:
container: licenses
docker build \
--network=host \
--build-arg GO_LDFLAGS \
--build-arg GOARCH \
--build-arg SHORT_SHA='$(SHORT_SHA)' \
--build-arg LICENSES_IMAGE=$(LICENSES_IMAGE) \
--target="update-operator" \
--tag $(IMAGE_NAME) \
--build-arg 'GO_LDFLAGS=$(GO_LDFLAGS)' \
--build-arg 'GOARCH=$(GOARCH)' \
--build-arg 'SHORT_SHA=$(SHORT_SHA)' \
--build-arg 'LICENSES_IMAGE=$(LICENSES_IMAGE)' \
--build-arg 'GOLANG_IMAGE=$(BUILDSYS_SDK_IMAGE)' \
--target='update-operator' \
--tag '$(IMAGE_NAME)' \
.

# Build and test in a container.
container-test: sdk-image licenses
docker build \
--network=host \
--build-arg GO_LDFLAGS='$(GO_LDFLAGS)' \
--build-arg GOARCH='$(GOARCH)' \
--build-arg SHORT_SHA='$(SHORT_SHA)' \
--build-arg NOCACHE='$(shell date +"%s")' \
--build-arg LICENSES_IMAGE=$(LICENSES_IMAGE) \
--target="test" \
--tag $(IMAGE_NAME)-test \
--build-arg 'GO_LDFLAGS=$(GO_LDFLAGS)' \
--build-arg 'GOARCH=$(GOARCH)' \
--build-arg 'SHORT_SHA=$(SHORT_SHA)' \
--build-arg 'NOCACHE=$(shell date +'%s')' \
--build-arg 'LICENSES_IMAGE=$(LICENSES_IMAGE)' \
--build-arg 'GOLANG_IMAGE=$(BUILDSYS_SDK_IMAGE)' \
--target='test' \
--tag '$(IMAGE_NAME)-test' \
.

# Build container image with debug-configured daemon.
Expand Down Expand Up @@ -192,7 +194,7 @@ get-nodes-status:
# license collection.
sdk-image: BUILDSYS_SDK_IMAGE_URL=https://cache.bottlerocket.aws/$(BUILDSYS_SDK_IMAGE).tar.gz
sdk-image:
docker inspect $(BUILDSYS_SDK_IMAGE) 2>&1 >/dev/null \
docker inspect $(BUILDSYS_SDK_IMAGE) &>/dev/null \
|| curl -# -qL $(BUILDSYS_SDK_IMAGE_URL) | docker load -i /dev/stdin

# licenses builds a container image with the LICENSE & legal files from the
Expand All @@ -205,5 +207,6 @@ licenses: sdk-image go.mod go.sum
docker build \
--network=host \
--build-arg SDK_IMAGE=$(BUILDSYS_SDK_IMAGE) \
--build-arg GOLANG_IMAGE=$(BUILDSYS_SDK_IMAGE) \
-t $(LICENSES_IMAGE) \
-f build/Dockerfile.licenses .
11 changes: 10 additions & 1 deletion build/Dockerfile.licenses
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@
#
ARG SDK_IMAGE

# GOLANG_IMAGE is the image to be used for collecting modules. This should be
# the same image used in the build. The idea is to have the same toolchain to
# avoid running into any differences between versions.
ARG GOLANG_IMAGE=golang:1.13

# Fetch dependencies into a vendor/ directory.
FROM golang:1.13 as src
#
# The first several steps should match that of the build's Dockerfile to share
# the go module package cache.
FROM $GOLANG_IMAGE as src
USER root
ENV GOPROXY=direct
WORKDIR /src
COPY go.mod go.sum /src/
Expand Down