-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate files in dockerfiles #219
Changes from 19 commits
d4eb09c
812fae6
27e7845
a1f3444
5878da7
eba0f5d
7f12296
d29a93a
f3329b7
b42328d
5a3ea96
40eff87
c671dce
4a01d38
1a490af
40ee2a3
eedfe4d
fa0a824
3821f2a
8f3bbac
0196e15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.git | ||
vendor | ||
testbin | ||
images | ||
must-gather | ||
bin | ||
api/v1/zz_generated.deepcopy.go | ||
config/crd/bases/kataconfiguration.openshift.io_kataconfigs.yaml | ||
config/rbac/role.yaml | ||
config/webhook/manifests.yaml | ||
bundle | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,5 +85,4 @@ config/crd/bases/kataconfiguration.openshift.io_kataconfigs.yaml | |
config/rbac/role.yaml | ||
config/webhook/manifests.yaml | ||
# make bundle files | ||
bundle.Dockerfile | ||
bundle/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline since commit 846b467. Maybe fix this as well while here ? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,26 @@ FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.17-openshift-4.10 AS | |
|
||
WORKDIR /workspace | ||
|
||
# Copy the Go Modules manifests | ||
COPY Makefile Makefile | ||
COPY hack hack/ | ||
COPY PROJECT PROJECT | ||
COPY main.go main.go | ||
COPY api api/ | ||
COPY config config/ | ||
COPY controllers controllers/ | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These layers need to be sorted from less frequently changed to more frequently changed, please check out my earlier explanations or, even better, review Dockerfile best practices. Are you comfortable handling the dockerfiles optimisations, or would you prefer that I do it subsequently if necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Will move go.mod and go.sum above api in all docker files |
||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY main.go main.go | ||
COPY api/ api/ | ||
COPY controllers/ controllers/ | ||
RUN go mod download | ||
# needed for docker build but not for local builds | ||
RUN go mod vendor | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=mod -o manager main.go | ||
RUN make build | ||
|
||
# Use OpenShift base image | ||
FROM registry.ci.openshift.org/ocp/4.10:base | ||
WORKDIR / | ||
COPY --from=builder /workspace/manager . | ||
COPY --from=builder /workspace/bin/manager . | ||
|
||
RUN useradd -r -u 499 nonroot | ||
RUN getent group nonroot || groupadd -o -g 499 nonroot | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Use OpenShift golang builder image | ||
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.17-openshift-4.10 AS builder | ||
|
||
WORKDIR /workspace | ||
|
||
COPY Makefile Makefile | ||
COPY PROJECT PROJECT | ||
COPY api api/ | ||
COPY config config/ | ||
COPY controllers controllers/ | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
|
||
RUN go mod download | ||
# needed for docker build but not for local builds | ||
RUN go mod vendor | ||
|
||
# Install operator-sdk | ||
RUN export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac) \ | ||
OS=$(uname | awk '{print tolower($0)}') \ | ||
OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.20.1; \ | ||
curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}; \ | ||
mv operator-sdk_${OS}_${ARCH} operator-sdk; \ | ||
chmod +x operator-sdk | ||
|
||
# Set path to include local dir so standard make target can be used | ||
ENV PATH=$PATH:. | ||
|
||
# Unsetting VERSION here is workaround because the buildroot image sets VERSION to the golang version | ||
RUN unset VERSION; make bundle | ||
|
||
FROM scratch | ||
|
||
# Core bundle labels. | ||
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 | ||
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ | ||
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ | ||
LABEL operators.operatorframework.io.bundle.package.v1=sandboxed-containers-operator | ||
LABEL operators.operatorframework.io.bundle.channels.v1=stable-1.3 | ||
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable-1.3 | ||
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.19.0+git | ||
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 | ||
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 | ||
|
||
# Labels for testing. | ||
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 | ||
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ | ||
|
||
# Copy files to locations specified by labels. | ||
COPY --from=builder /workspace/bundle/manifests /manifests/ | ||
COPY --from=builder /workspace/bundle/metadata /metadata/ | ||
COPY --from=builder /workspace/bundle/tests/scorecard /tests/scorecard/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing newline here also please. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Use OpenShift golang builder image | ||
cpmeadors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.17-openshift-4.10 AS builder | ||
|
||
WORKDIR /workspace | ||
|
||
COPY Makefile Makefile | ||
COPY PROJECT PROJECT | ||
COPY api api/ | ||
COPY config config/ | ||
COPY controllers controllers/ | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
|
||
RUN go mod download | ||
# needed for docker build but not for local builds | ||
RUN go mod vendor | ||
|
||
# Install operator-sdk | ||
RUN export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac) \ | ||
OS=$(uname | awk '{print tolower($0)}') \ | ||
OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.20.1; \ | ||
curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}; \ | ||
mv operator-sdk_${OS}_${ARCH} operator-sdk; \ | ||
chmod +x operator-sdk | ||
|
||
# Set path to include local dir so standard make target can be used | ||
ENV PATH=$PATH:. | ||
|
||
# Unsetting VERSION here is workaround because the buildroot image sets VERSION to the golang version | ||
RUN unset VERSION; make bundle | ||
|
||
FROM scratch | ||
|
||
# Core bundle labels. | ||
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 | ||
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ | ||
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ | ||
LABEL operators.operatorframework.io.bundle.package.v1=sandboxed-containers-operator | ||
LABEL operators.operatorframework.io.bundle.channels.v1=stable-1.3 | ||
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable-1.3 | ||
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.19.0+git | ||
cpmeadors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 | ||
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 | ||
|
||
# Labels for testing. | ||
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 | ||
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ | ||
|
||
# Copy files to locations specified by labels. | ||
COPY --from=builder /workspace/bundle/manifests /manifests/ | ||
COPY --from=builder /workspace/bundle/metadata /metadata/ | ||
COPY --from=builder /workspace/bundle/tests/scorecard /tests/scorecard/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a terminating newline for a smoother
cat
experience ?