Skip to content

Commit b9d5db3

Browse files
authored
Merge pull request #691 from droot/bugfix/v2-scaffolding-dockerfile
:bugfix: fixed docker image file for v2 scaffolding
2 parents e46e06e + 6584fcf commit b9d5db3

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

pkg/scaffold/v2/dockerfile.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,25 @@ func (c *Dockerfile) GetInput() (input.Input, error) {
3737
}
3838

3939
var dockerfileTemplate = `# Build the manager binary
40-
FROM golang:1.10.3 as builder
40+
FROM golang:1.12.5 as builder
4141
42-
# Copy in the go src
43-
WORKDIR /go/src/{{ .Repo }}
44-
COPY vendor/ vendor/
42+
WORKDIR /workspace
43+
# Copy the go source
4544
COPY main.go main.go
4645
COPY api/ api/
4746
COPY controllers/ controllers/
47+
# Copy the Go Modules manifests
48+
COPY go.mod go.mod
49+
COPY go.sum go.sum
50+
4851
4952
# Build
50-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager {{ .Repo }}/
53+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
5154
52-
# Copy the controller-manager into a thin image
53-
FROM ubuntu:latest
55+
# Use distroless as minimal base image to package the manager binary
56+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
57+
FROM gcr.io/distroless/base
5458
WORKDIR /
55-
COPY --from=builder /go/src/{{ .Repo }}/manager .
59+
COPY --from=builder /workspace/manager .
5660
ENTRYPOINT ["/manager"]
5761
`

testdata/project_v2/Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# Build the manager binary
2-
FROM golang:1.10.3 as builder
2+
FROM golang:1.12.5 as builder
33

4-
# Copy in the go src
5-
WORKDIR /go/src/sigs.k8s.io/kubebuilder/testdata/project_v2
6-
COPY vendor/ vendor/
4+
WORKDIR /workspace
5+
# Copy the go source
76
COPY main.go main.go
87
COPY api/ api/
98
COPY controllers/ controllers/
9+
# Copy the Go Modules manifests
10+
COPY go.mod go.mod
11+
COPY go.sum go.sum
12+
1013

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

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

0 commit comments

Comments
 (0)