Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 76519df

Browse files
authored
Merge pull request #154 from fabriziopandini/production-ready-dockerfile
production ready dockerfile
2 parents a77bc0c + 5aee7c7 commit 76519df

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed

Dockerfile

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# Build the manager binary
16-
FROM golang:1.12.7
16+
FROM golang:1.12.7 as builder
1717

1818
# default the go proxy
1919
ARG goproxy=https://proxy.golang.org
@@ -22,26 +22,23 @@ ARG goproxy=https://proxy.golang.org
2222
ENV GOPROXY=$goproxy
2323

2424
WORKDIR /workspace
25+
# Copy the Go Modules manifests
2526
COPY go.mod go.mod
2627
COPY go.sum go.sum
2728
# cache deps before building and copying source so that we don't need to re-download as much
2829
# and so that source changes don't invalidate our downloaded layer
2930
RUN go mod download
3031

3132
# Copy the go source
32-
COPY main.go main.go
33-
COPY api/ api/
34-
COPY controllers/ controllers/
35-
COPY kubeadm/ kubeadm/
36-
COPY cloudinit/ cloudinit/
37-
COPY certs/ certs/
33+
COPY ./ ./
3834

39-
# Allow containerd to restart pods by calling /restart.sh (mostly for tilt + fast dev cycles)
40-
# TODO: Remove this on prod and use a multi-stage build
41-
COPY third_party/forked/rerun-process-wrapper/start.sh .
42-
COPY third_party/forked/rerun-process-wrapper/restart.sh .
35+
# Build
36+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
4337

44-
# Build and run
45-
RUN go install -v .
46-
RUN mv /go/bin/cluster-api-bootstrap-provider-kubeadm /manager
47-
ENTRYPOINT ["./start.sh", "/manager"]
38+
# Use distroless as minimal base image to package the manager binary
39+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
40+
FROM gcr.io/distroless/static:latest
41+
WORKDIR /
42+
COPY --from=builder /workspace/manager .
43+
USER nobody
44+
ENTRYPOINT ["/manager"]

Dockerfile.dev

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2019 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Build the manager binary
16+
FROM golang:1.12.7
17+
18+
# default the go proxy
19+
ARG goproxy=https://proxy.golang.org
20+
21+
# run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
22+
ENV GOPROXY=$goproxy
23+
24+
WORKDIR /workspace
25+
COPY go.mod go.mod
26+
COPY go.sum go.sum
27+
# cache deps before building and copying source so that we don't need to re-download as much
28+
# and so that source changes don't invalidate our downloaded layer
29+
RUN go mod download
30+
31+
# Copy the go source
32+
COPY main.go main.go
33+
COPY api/ api/
34+
COPY controllers/ controllers/
35+
COPY kubeadm/ kubeadm/
36+
COPY cloudinit/ cloudinit/
37+
COPY certs/ certs/
38+
39+
# Allow containerd to restart pods by calling /restart.sh (mostly for tilt + fast dev cycles)
40+
# TODO: Remove this on prod and use a multi-stage build
41+
COPY third_party/forked/rerun-process-wrapper/start.sh .
42+
COPY third_party/forked/rerun-process-wrapper/restart.sh .
43+
44+
# Build and run
45+
RUN go install -v .
46+
RUN mv /go/bin/cluster-api-bootstrap-provider-kubeadm /manager
47+
ENTRYPOINT ["./start.sh", "/manager"]

0 commit comments

Comments
 (0)