Skip to content
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

Merged
merged 21 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d4eb09c
generate files in dockerfiles
cpmeadors Sep 22, 2022
812fae6
Merge branch 'openshift:master' into generate-files-in-dockerfile
cpmeadors Oct 4, 2022
27e7845
fixed missing file and cleaned up dockerfile
cpmeadors Oct 5, 2022
a1f3444
Clean up of dockerfiles to make them consisten
cpmeadors Oct 5, 2022
5878da7
use make build
cpmeadors Oct 6, 2022
eba0f5d
update bundle dockerfile after update to operator-sdk 1.23
cpmeadors Oct 6, 2022
7f12296
set channel defaults
cpmeadors Oct 6, 2022
d29a93a
revert back to sdk 1.20.1
cpmeadors Oct 6, 2022
f3329b7
generate files in dockerfiles
cpmeadors Sep 22, 2022
b42328d
fixed missing file and cleaned up dockerfile
cpmeadors Oct 5, 2022
5a3ea96
Clean up of dockerfiles to make them consisten
cpmeadors Oct 5, 2022
40eff87
use make build
cpmeadors Oct 6, 2022
c671dce
update bundle dockerfile after update to operator-sdk 1.23
cpmeadors Oct 6, 2022
4a01d38
set channel defaults
cpmeadors Oct 6, 2022
1a490af
revert back to sdk 1.20.1
cpmeadors Oct 6, 2022
40ee2a3
Merge branch 'generate-files-in-dockerfile' of github.com:cpmeadors/s…
cpmeadors Oct 6, 2022
eedfe4d
add .dockerignore, use 1.20.1 operater-sdk in docker file
cpmeadors Oct 6, 2022
fa0a824
go back to only copying what is needed in dockerfiles
cpmeadors Oct 6, 2022
3821f2a
removed hardcoded version from dockerfile, pointed bundle-build to a …
cpmeadors Oct 6, 2022
8f3bbac
add trailing newlines, reorder copy lines in dockerfiles, add fixme f…
cpmeadors Oct 7, 2022
0196e15
Merge branch 'openshift:master' into generate-files-in-dockerfile
cpmeadors Oct 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
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
Copy link
Member

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 ?

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline since commit 846b467. Maybe fix this as well while here ?

23 changes: 12 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 1.3.0
VERSION ?= 1.3.1

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
CHANNELS="stable-1.3"
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
Expand All @@ -19,6 +20,7 @@ endif
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
DEFAULT_CHANNEL="stable-1.3"
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
Expand All @@ -29,7 +31,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
#
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
# example.com/memcached-operator-bundle:$VERSION and example.com/memcached-operator-catalog:$VERSION.
IMAGE_TAG_BASE ?= quay.io/openshift_sandboxed_containers/openshift-sandboxed-containers-operator
IMAGE_TAG_BASE ?= registry-proxy.engineering.redhat.com/rh-osbs/openshift-sandboxed-containers-operator
cpmeadors marked this conversation as resolved.
Show resolved Hide resolved

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
Expand All @@ -47,7 +49,7 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
endif

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23

Expand Down Expand Up @@ -185,7 +187,7 @@ bundle: manifests kustomize ## Generate bundle manifests and metadata, then vali

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
docker build -f bundle-custom.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
Expand Down
52 changes: 52 additions & 0 deletions bundle-custom.Dockerfile
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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing newline here also please.

52 changes: 52 additions & 0 deletions bundle.Dockerfile
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/
4 changes: 2 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: controller
newTag: latest
newName: registry-proxy.engineering.redhat.com/rh-osbs/openshift-sandboxed-containers-operator
cpmeadors marked this conversation as resolved.
Show resolved Hide resolved
newTag: 1.3.1
cpmeadors marked this conversation as resolved.
Show resolved Hide resolved