Skip to content

Commit

Permalink
Do go mod download once on docker multiplatform builds
Browse files Browse the repository at this point in the history
  • Loading branch information
maraino committed Jan 27, 2023
1 parent b2087cc commit 44aca4b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
20 changes: 19 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
FROM golang:alpine AS builder
# On multiplatform builds, cache holds the source code and all the Go modules.
FROM --platform=$BUILDPLATFORM golang:alpine AS cache

# Use go.mod go.sum only to avoid invalidating cache if the source code changes
# on local development.
WORKDIR /src
COPY go.mod go.sum /src/
RUN go mod download

# Copy all the source code.
COPY . .

# The builder will be platform specific.
FROM golang:alpine AS builder

COPY --from=cache /go/pkg /go/pkg
COPY --from=cache /src /src

RUN apk add --no-cache git make
RUN apk add --no-cache gcc musl-dev pkgconf pcsc-lite-dev

WORKDIR /src
RUN make V=1 build

# step-cli will be the base image.
FROM smallstep/step-cli:latest

COPY --from=builder /src/bin/step-kms-plugin /usr/local/bin/step-kms-plugin

USER root
RUN apk add --no-cache pcsc-lite pcsc-lite-libs
RUN mkdir -p /run/pcscd
RUN chown step:step /run/pcscd
USER step

CMD ["/bin/bash"]
18 changes: 17 additions & 1 deletion docker/Dockerfile.cloud
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
FROM golang:alpine AS builder
# On multiplatform builds, cache holds the source code and all the Go modules.
FROM --platform=$BUILDPLATFORM golang:alpine AS cache

# Use go.mod go.sum only to avoid invalidating cache if the source code changes
# on local development.
WORKDIR /src
COPY go.mod go.sum /src/
RUN go mod download

# Copy all the source code.
COPY . .

# The builder will be platform specific.
FROM golang:alpine AS builder

COPY --from=cache /go/pkg /go/pkg
COPY --from=cache /src /src

RUN apk add --no-cache git make

WORKDIR /src
RUN make V=1 CGO_ENABLED=0 build

# step-cli will be the base image.
FROM smallstep/step-cli:latest

COPY --from=builder /src/bin/step-kms-plugin /usr/local/bin/step-kms-plugin
Expand Down

0 comments on commit 44aca4b

Please sign in to comment.