Skip to content

Commit

Permalink
:bugfix: fixed docker image file for v2 scaffolding
Browse files Browse the repository at this point in the history
Main changes:
  - use Go 1.12.5 with Go modules to build the manager binary
  - use distroless (stripped down image)
  • Loading branch information
droot committed May 12, 2019
1 parent e46e06e commit 6584fcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
20 changes: 12 additions & 8 deletions pkg/scaffold/v2/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,25 @@ func (c *Dockerfile) GetInput() (input.Input, error) {
}

var dockerfileTemplate = `# Build the manager binary
FROM golang:1.10.3 as builder
FROM golang:1.12.5 as builder
# Copy in the go src
WORKDIR /go/src/{{ .Repo }}
COPY vendor/ vendor/
WORKDIR /workspace
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager {{ .Repo }}/
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
# Copy the controller-manager into a thin image
FROM ubuntu:latest
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/base
WORKDIR /
COPY --from=builder /go/src/{{ .Repo }}/manager .
COPY --from=builder /workspace/manager .
ENTRYPOINT ["/manager"]
`
20 changes: 12 additions & 8 deletions testdata/project_v2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Build the manager binary
FROM golang:1.10.3 as builder
FROM golang:1.12.5 as builder

# Copy in the go src
WORKDIR /go/src/sigs.k8s.io/kubebuilder/testdata/project_v2
COPY vendor/ vendor/
WORKDIR /workspace
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum


# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager sigs.k8s.io/kubebuilder/testdata/project_v2/
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go

# Copy the controller-manager into a thin image
FROM ubuntu:latest
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/base
WORKDIR /
COPY --from=builder /go/src/sigs.k8s.io/kubebuilder/testdata/project_v2/manager .
COPY --from=builder /workspace/manager .
ENTRYPOINT ["/manager"]

0 comments on commit 6584fcf

Please sign in to comment.