Skip to content

Commit

Permalink
Parameterize Docker image build
Browse files Browse the repository at this point in the history
This will enable keen users who can build Contour themselves to use a different golang image to support building with FIPS-validated BoringCrypto library.

Updates projectcontour#2878

Signed-off-by: Sunjay Bhatia <[email protected]>
  • Loading branch information
sunjayBhatia committed Feb 24, 2021
1 parent 046c032 commit 13e10a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG BUILDPLATFORM=linux/amd64
ARG BUILD_BASE_IMAGE

FROM --platform=$BUILDPLATFORM golang:1.15.8 AS build
FROM --platform=$BUILDPLATFORM $BUILD_BASE_IMAGE AS build
WORKDIR /contour

ENV GOPROXY=https://proxy.golang.org
Expand All @@ -16,11 +17,12 @@ COPY Makefile Makefile
ARG BUILD_BRANCH
ARG BUILD_SHA
ARG BUILD_VERSION
ARG BUILD_CGO_ENABLED
ARG TARGETOS
ARG TARGETARCH

RUN make build \
CGO_ENABLED=0 \
CGO_ENABLED=${BUILD_CGO_ENABLED}} \
GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
BUILD_VERSION=${BUILD_VERSION} \
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ endif
# Platforms to build the multi-arch image for.
IMAGE_PLATFORMS ?= linux/amd64,linux/arm64

# Base build image to use.
BUILD_BASE_IMAGE ?= golang:1.15.8

# Enable build with CGO.
BUILD_CGO_ENABLED ?= 0

# Used to supply a local Envoy docker container an IP to connect to that is running
# 'contour serve'. On MacOS this will work, but may not on other OSes. Defining
# LOCALIP as an env var before running 'make local' will solve that.
Expand Down Expand Up @@ -99,19 +105,23 @@ download: ## Download Go modules
multiarch-build-push: ## Build and push a multi-arch Contour container image to the Docker registry
docker buildx build \
--platform $(IMAGE_PLATFORMS) \
--build-arg "BUILD_BASE_IMAGE=$(BUILD_BASE_IMAGE)" \
--build-arg "BUILD_VERSION=$(BUILD_VERSION)" \
--build-arg "BUILD_BRANCH=$(BUILD_BRANCH)" \
--build-arg "BUILD_SHA=$(BUILD_SHA)" \
--build-arg "BUILD_CGO_ENABLED=$(BUILD_CGO_ENABLED)" \
$(DOCKER_BUILD_LABELS) \
$(IMAGE_TAGS) \
--push \
.

container: ## Build the Contour container image
docker build \
--build-arg "BUILD_BASE_IMAGE=$(BUILD_BASE_IMAGE)" \
--build-arg "BUILD_VERSION=$(BUILD_VERSION)" \
--build-arg "BUILD_BRANCH=$(BUILD_BRANCH)" \
--build-arg "BUILD_SHA=$(BUILD_SHA)" \
--build-arg "BUILD_CGO_ENABLED=$(BUILD_CGO_ENABLED)" \
$(DOCKER_BUILD_LABELS) \
$(shell pwd) \
--tag $(IMAGE):$(VERSION)
Expand Down

0 comments on commit 13e10a8

Please sign in to comment.