Skip to content

Commit adeb7eb

Browse files
author
Nicholas Thomson
committed
Migrate release Dockerfiles from community
1 parent 1e50197 commit adeb7eb

File tree

3 files changed

+112
-1
lines changed

3 files changed

+112
-1
lines changed

Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Base image to use for the final stage
2+
ARG base_image=amazonlinux:2
3+
# Build the manager binary
4+
FROM golang:1.14.1 as builder
5+
6+
ARG service_alias
7+
# The tuple of controller image version information
8+
ARG service_controller_git_version
9+
ARG service_controller_git_commit
10+
ARG build_date
11+
# The directory within the builder container into which we will copy our
12+
# service controller code.
13+
ARG work_dir=/github.com/aws-controllers-k8s/$service_alias-controller
14+
WORKDIR $work_dir
15+
# For building Go Module required
16+
ENV GOPROXY=direct
17+
ENV GO111MODULE=on
18+
ENV GOARCH=amd64
19+
ENV GOOS=linux
20+
ENV CGO_ENABLED=0
21+
ENV VERSION_PKG=github.com/aws-controllers-k8s/$service_alias-controller/pkg/version
22+
# Copy the Go Modules manifests and LICENSE/ATTRIBUTION
23+
COPY $service_alias-controller/LICENSE $work_dir/LICENSE
24+
COPY $service_alias-controller/ATTRIBUTION.md $work_dir/ATTRIBUTION.md
25+
# Copy Go mod files
26+
COPY $service_alias-controller/go.mod $work_dir/go.mod
27+
COPY $service_alias-controller/go.sum $work_dir/go.sum
28+
# cache deps before building and copying source so that we don't need to re-download as much
29+
# and so that source changes don't invalidate our downloaded layer
30+
RUN go mod download
31+
32+
# Now copy the go source code for the controller...
33+
COPY $service_alias-controller/apis $work_dir/apis
34+
COPY $service_alias-controller/cmd $work_dir/cmd
35+
COPY $service_alias-controller/pkg $work_dir/pkg
36+
# Build
37+
RUN GIT_VERSION=$service_controller_git_version && \
38+
GIT_COMMIT=$service_controller_git_commit && \
39+
BUILD_DATE=$build_date && \
40+
go build -ldflags="-X ${VERSION_PKG}.GitVersion=${GIT_VERSION} \
41+
-X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} \
42+
-X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" \
43+
-a -o $work_dir/bin/controller $work_dir/cmd/controller/main.go
44+
45+
FROM $base_image
46+
ARG service_alias
47+
ARG work_dir=/github.com/aws-controllers-k8s/$service_alias-controller
48+
WORKDIR /
49+
COPY --from=builder $work_dir/bin/controller $work_dir/LICENSE $work_dir/ATTRIBUTION.md /bin/
50+
ENTRYPOINT ["/bin/controller"]

Dockerfile.local

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Base image to use at runtime
2+
ARG base_image=amazonlinux:2
3+
# Build the manager binary
4+
FROM golang:1.14.1 as builder
5+
6+
ARG service_alias
7+
# The tuple of controller image version information
8+
ARG service_controller_git_version
9+
ARG service_controller_git_commit
10+
ARG build_date
11+
# The directory within the builder container into which we will copy our
12+
# service controller code.
13+
ARG work_dir=/github.com/aws-controllers-k8s/$service_alias-controller
14+
WORKDIR $work_dir
15+
# For building Go Module required
16+
ENV GOPROXY=https://proxy.golang.org,direct
17+
ENV GO111MODULE=on
18+
ENV GOARCH=amd64
19+
ENV GOOS=linux
20+
ENV CGO_ENABLED=0
21+
ENV VERSION_PKG=github.com/aws-controllers-k8s/$service_alias-controller/pkg/version
22+
# Copy the Go Modules manifests and LICENSE/ATTRIBUTION
23+
COPY $service_alias-controller/LICENSE $work_dir/LICENSE
24+
COPY $service_alias-controller/ATTRIBUTION.md $work_dir/ATTRIBUTION.md
25+
# use local mod files
26+
COPY $service_alias-controller/go.local.mod $work_dir/go.local.mod
27+
COPY $service_alias-controller/go.local.sum $work_dir/go.local.sum
28+
COPY $service_alias-controller/go.mod $work_dir/go.mod
29+
30+
# for local development, copy local runtime repo
31+
COPY runtime/pkg $work_dir/../runtime/pkg
32+
COPY runtime/apis $work_dir/../runtime/apis
33+
COPY runtime/go.mod $work_dir/../runtime/go.mod
34+
COPY runtime/go.sum $work_dir/../runtime/go.sum
35+
36+
# cache deps before building and copying source so that we don't need to re-download as much
37+
# and so that source changes don't invalidate our downloaded layer
38+
WORKDIR $work_dir/../runtime
39+
RUN go mod download
40+
WORKDIR $work_dir
41+
RUN go mod download
42+
43+
# Now copy the go source code for the service controller...
44+
COPY $service_alias-controller/apis $work_dir/apis
45+
COPY $service_alias-controller/cmd $work_dir/cmd
46+
COPY $service_alias-controller/pkg $work_dir/pkg
47+
# Build
48+
RUN GIT_VERSION=$service_controller_git_version && \
49+
GIT_COMMIT=$service_controller_git_commit && \
50+
BUILD_DATE=$build_date && \
51+
go build -ldflags="-X ${VERSION_PKG}.GitVersion=${GIT_VERSION} \
52+
-X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} \
53+
-X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" \
54+
-modfile="${work_dir}/go.local.mod" \
55+
-a -o $work_dir/bin/controller $work_dir/cmd/controller/main.go
56+
57+
FROM $base_image
58+
ARG service_alias
59+
ARG work_dir=/github.com/aws-controllers-k8s/$service_alias-controller
60+
WORKDIR /
61+
COPY --from=builder $work_dir/bin/controller $work_dir/LICENSE $work_dir/ATTRIBUTION.md /bin/
62+
ENTRYPOINT ["/bin/controller"]

scripts/build-controller-release.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ACK_GENERATE_OLM=${ACK_GENERATE_OLM:-"false"}
1313

1414
source "$SCRIPTS_DIR/lib/common.sh"
1515
source "$SCRIPTS_DIR/lib/k8s.sh"
16-
source "$SCRIPTS_DIR/lib/helm.sh"
1716

1817
check_is_installed controller-gen "You can install controller-gen with the helper scripts/install-controller-gen.sh"
1918
check_is_installed helm "You can install Helm with the helper scripts/install-helm.sh"

0 commit comments

Comments
 (0)