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

Conversation

cpmeadors
Copy link
Contributor

@cpmeadors cpmeadors commented Sep 22, 2022

These changes add multistage docker files for both the operator and the operator bundle images. The builder stage uses the make targets to generate the necessary files to build the two images. This should fix the Prow CI image build issues and it should allow the copy of the bundle files in the midstream repo to be removed. Ultimately it means the same process is being use to build the images no matter what is building them.

Outstanding issues are the need for "go mod vendor" and the hard coding of the VERSION for the bundle.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 22, 2022
@openshift-ci
Copy link

openshift-ci bot commented Sep 22, 2022

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@cpmeadors
Copy link
Contributor Author

/test all

@cpmeadors
Copy link
Contributor Author

/test ci-index-sandboxed-containers-operator-bundle

1 similar comment
@bear-redhat
Copy link

/test ci-index-sandboxed-containers-operator-bundle

@cpmeadors cpmeadors marked this pull request as ready for review October 5, 2022 17:32
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 5, 2022
@openshift-ci openshift-ci bot requested review from jensfr and pmores October 5, 2022 17:33
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=alpha
Copy link
Contributor

Choose a reason for hiding this comment

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

should be stable-1.3?

Copy link
Contributor

@jensfr jensfr left a comment

Choose a reason for hiding this comment

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

lgtm, except for two small nits

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated
COPY go.sum go.sum
# 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
COPY ./ ./
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this change. I'm afraid it will greatly and unnecessarily increase the size of the resulting layer which might not be an issue on build machines but can be an impediment for development in my experience. I know that even without this change, when I worked on this Dockerfile it accumulated over a hundred of gigs in layer cache during just a couple of hour of work so I had to purge periodically, with the obvious bad effects on the next build time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is more efficient than doing multiple COPY to most of the dirs. Fewer commands in a dockerfile is generally a good thing. I find I have to purge docker caches/images a lot when I do any dockerfile development

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could also add .dockerignore file to limit what is copied.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd really like to make sure here that the dev cycle is not made worse unnecessarily. As is, I believe this change is practically guaranteed to cause that as the COPY ./ ./ command will create a big layer that's going to be invalidated, rebuilt and re-cached every single time since it contains the sources that are changing because they're being worked on.

You're right that fewer commands is a good thing but that's precisely for the reason of avoiding creation of unnecessary layers (the cost of the COPY commands in terms of execution time tends to be negligible and dominated by other commands in the Dockerfile by several orders of magnitude). Also, notice how the COPY commands in the original version are ordered so that things that rarely change go first - this makes sure that after an initial build these COPY commands aren't actually performed at all on subsequent builds and a cached layer is used instead.

It's true that we can achieve the same with .dockerignore although I suspect that in this case that would be more tedious than just copying only what's needed. But I don't mind either way.

@pmores
Copy link
Contributor

pmores commented Oct 6, 2022

Thanks @cpmeadors and kudos for figuring this out! I left a bunch of comments but also overall, I'd like to make sure that the efficiency of the originals (esp. in case of Dockerfile) in terms of layering and disk space requirements is preserved.

@@ -12,5 +12,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: controller
newTag: latest
newName: openshift-sandboxed-containers-operator
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change came from running:
IMAGE_TAG_BASE=registry-proxy.engineering.redhat.com/rh-osbs/ IMG=openshift-sandboxed-containers-operator make bundle
which runs:
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)

I can't quite get my head around if this should be a permanent change or if it even matters because it get substituted anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it matters much as it is being overwritten typically when you run make IMG=xxx deploy. Maybe setting it to quay.io/openshift_sandboxed_containers/openshift-sandboxed-containers-operator:latest would make sense as the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. this is again controlled by VARS in the makefile. According to the operator-sdk docs and makefile comments, we should set IMAGE_TAG_BASE to repo+imagename and then set IMG ?= $(IMAGE_TAG_BASE):$(VERSION).
This should represent our default operator repo, image name, and image version. The question is what should that be. I feel like it should be the production build. If you need a local build, you should set the IMG as mentioned in our docs. Does this logic make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that if you do a make docker-build or bundle-build with no options you would get the production version.

…custome dockerfile, updated IMAGE_TAG_BASE and IMG defaults
Makefile Outdated
@@ -231,3 +233,31 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

Copy link
Contributor

Choose a reason for hiding this comment

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

this chunk should go away when you rebase against master

Copy link
Member

Choose a reason for hiding this comment

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

this chunk should go away when you rebase against master

Yes but there is more to it. See below.

.dockerignore Outdated
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 ?

.gitignore Outdated
@@ -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 ?

Makefile Outdated Show resolved Hide resolved
@pmores
Copy link
Contributor

pmores commented Oct 7, 2022

Thanks, but why do we now have 21 commits? If this is not a target branch mess up I think this needs some clean-up and squashing.

@jensfr
Copy link
Contributor

jensfr commented Oct 7, 2022

I think bundle.Dockerfile can be removed as the Makefile is now using bundle-custom.Dockerfile. And then the bundle-clean target also needs to remove bundle-custom.Dockerfile

Dockerfile Outdated
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

Makefile Show resolved Hide resolved
@gkurz
Copy link
Member

gkurz commented Oct 7, 2022

Thanks, but why do we now have 21 commits? If this is not a target branch mess up I think this needs some clean-up and squashing.

Agreed. This PR should also be rebased on current main since #221 got merged.

I think bundle.Dockerfile can be removed as the Makefile is now using bundle-custom.Dockerfile. And then the bundle-clean target also needs to remove bundle-custom.Dockerfile

AFAICS bundle.Dockerfile is still generated by make bundle:

cd config/manager && /home/greg/Work/openshift/sandboxed-containers-operator/bin/kustomize edit set image controller=quay.io/rhgkurz/openshift-sandboxed-containers-operator
/home/greg/Work/openshift/sandboxed-containers-operator/bin/kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version 1.3.1 --channels="stable-1.3" --default-channel="stable-1.3"
INFO[0000] Creating bundle.Dockerfile                   

Just for my understanding : we're deliberately ignoring the generated bundle.Dockerfile and we're only to use the custom one from git instead from now on, right ? Not sure to fully understand the rationale for this change. Some explainations in the commit changelog would be appreciated.

EDIT: also, since we're now carrying this Dockerfile, how are we supposed to make it evolve in the future ?

And the bundle-clean target should also continue to remove bundle.Dockerfile no matter what, not bundle-custom.Dockerfile since it belongs to the repo.

Copy link
Contributor

@jensfr jensfr left a comment

Choose a reason for hiding this comment

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

see comments

# 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.

@pmores
Copy link
Contributor

pmores commented Oct 7, 2022

Just for my understanding : we're deliberately ignoring the generated bundle.Dockerfile and we're only to use the custom one from git instead from now on, right ? Not sure to fully understand the rationale for this change. Some explainations in the commit changelog would be appreciated.

That's true, and until that's added I think I can explain at least some of the rationale (I haven't realised that the original bundle.Dockerfile was generated until now which shows that my understanding isn't quite complete either).

The generated bundle.Dockerfile is basically just a couple of LABELs and a few COPY commands just to get stuff inside bundle/ into the bundle image. That stopped being adequate the moment we removed generated files (that includes bundle/*) from the repository. Since they don't come from the repo anymore, the contents of bundle/ have to be generated first by bundle.Dockerfile.

I believe/assume that's the reason for bundle-custom.Dockerfile - essentially a bundle.Dockerfile with the added ability to generate generated files first.

And the bundle-clean target should also continue to remove bundle.Dockerfile no matter what, not bundle-custom.Dockerfile since it belongs to the repo.

Yes, you're right, now I understand, bundle.Dockerfile should indeed be cleaned up (or, better yet, never generated in the first place if operator-sdk offers such an option) as the custom Dockerfile is always used to build the bundle image.

Copy link
Member

@gkurz gkurz left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @cpmeadors !

@openshift-ci
Copy link

openshift-ci bot commented Oct 7, 2022

@cpmeadors: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/4.9-sandboxed-containers-operator-e2e 0196e15 link false /test 4.9-sandboxed-containers-operator-e2e
ci/prow/sandboxed-containers-operator-e2e 0196e15 link false /test sandboxed-containers-operator-e2e

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Contributor

@jensfr jensfr left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@jensfr jensfr merged commit dd91e7c into openshift:master Oct 7, 2022
jensfr pushed a commit to jensfr/kata-operator-1 that referenced this pull request Oct 14, 2022
These changes add multistage docker files for both the operator and the
operator bundle images. The builder stage uses the make targets to
generate the necessary files to build the two images. This should fix
the Prow CI image build issues and it should allow the copy of the
bundle files in the midstream repo to be removed. Ultimately it means
the same process is being use to build the images no matter what is
building them.

Original patch by Cameron Meadors <cmeadors@redhat.com>
Backported by

Signed-off-by: Jens Freimann <jfreimann@redhat.com>
jensfr added a commit that referenced this pull request Oct 14, 2022
 Backport #219 "generate files in dockerfiles"
@cpmeadors cpmeadors deleted the generate-files-in-dockerfile branch November 10, 2022 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants