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

multiarch image pushing #84

Merged
merged 5 commits into from
May 28, 2020

Conversation

pohly
Copy link
Contributor

@pohly pohly commented May 25, 2020

What type of PR is this?
/kind feature

What this PR does / why we need it:

The previous PR (#82) had an issue (make invocation) and several opens. With the changes in this PR, push-multiarch integrates better with the rest of the build rules by removing duplication:

  • the same Go environment is used for multiarch and for testing
  • BUILD_PLATFORMS determines what is getting build instead
    of hard-coding that in the make target
  • no separate Dockerfile.multiarch

Which issue(s) this PR fixes:
Related-to kubernetes-csi/csi-release-tools#86

Special notes for your reviewer:

The result of make push-multiarch PULL_BASE_REF=master REGISTRY_NAME=pohly BUILD_PLATFORMS="linux amd64; windows amd64 .exe; linux ppc64le -ppc64le; linux s390x -s390x; linux arm64 -arm64" can be found here: https://hub.docker.com/repository/docker/pohly/csi-node-driver-registrar [Update 2020-05-26: added arm64]

Does this PR introduce a user-facing change?:

Windows and multiarch Linux images are now available.
The Dockerfile must accept a "binary" build argument.

The entire parameter for make was used as target as-is because without
some outer shell, argument splitting and variable expansion is
gone.

The gcloud invocation then fits better into cloudbuild.yaml again,
where it belongs (it's only needed when pushing to GCR).
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 25, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 25, 2020
@pohly
Copy link
Contributor Author

pohly commented May 25, 2020

/cc @vitt-bagal

@k8s-ci-robot
Copy link
Contributor

@pohly: GitHub didn't allow me to request PR reviews from the following users: vitt-bagal.

Note that only kubernetes-csi members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @vitt-bagal

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.

This removes code duplication:
- the same Go environment is used for multiarch and for testing
- BUILD_PLATFORMS determines what is getting build instead
  of hard-coding that in the make target
- no separate Dockerfile.multiarch

During the actual cloud build, BUILD_PLATFORMS is taken from the
shared prow.sh. There's currently no support for overriding that per
repo.

We still need separate Dockerfiles for Linux and Windows because
Windows has special requirements.

In some lines, indention is changed to use tabs.
@pohly
Copy link
Contributor Author

pohly commented May 26, 2020

the same Go environment is used for multiarch and for testing

I need to take this back a bit: this is only true for local builds and Prow, but not for cloud build. There

- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20200421-a2bf5f8'
determines which version of Go is used.

I think we should use the same approach as for Prow and install the desired Go version if it isn't available already.

@pohly pohly changed the title multiarch image pushing WIP: multiarch image pushing May 26, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 26, 2020
pohly added 2 commits May 26, 2020 10:39
By moving the check before building binaries, users get the warning
immediately when doing sequential builds.
This introduces .cloudbuild.sh as the main entry point for building
cloud images, similar to the role that .prow.sh has for Prow testing.

The script sets up the build environment (gcloud auth, installing Go,
parsing some of the env variables) before invoking "make
push-multiarch", which (as before) is usable also outside of a cloud
build.
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 26, 2020
@pohly
Copy link
Contributor Author

pohly commented May 26, 2020

I think we should use the same approach as for Prow and install the desired Go version if it isn't available already.

I've added that.

@pohly
Copy link
Contributor Author

pohly commented May 26, 2020

/assign @msau42

@pohly pohly changed the title WIP: multiarch image pushing multiarch image pushing May 26, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 26, 2020
cloudbuild.yaml Outdated
- PULL_BASE_REF=$_PULL_BASE_REF
- GIT_TAG=${_GIT_TAG}
- PULL_BASE_REF=${_PULL_BASE_REF}
- STAGING_PROJECT=${_STAGING_PROJECT}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need a staging_project variable, or can we set REGISTRY directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, setting REGISTRY_NAME directly is cleaner. I'm not even sure why we have _STAGING_PROJECT under substitutions.

@vitt-bagal: do you remember where that came from? Isn't that always k8s-staging-csi?

Copy link
Contributor

Choose a reason for hiding this comment

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

@vitt-bagal: do you remember where that came from? Isn't that always k8s-staging-csi?

It came from this commit. I think this can be removed safely if we set REGISTRY_NAME directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we can move cloudbuild.yaml into release-tools and just symlink to it from the root directory of a project (similar to .travis.yml -> release-tools/travis.yml), then it may make sense to have the substitution because different projects might have different staging projects.

Makefile Outdated
dockerfile_linux=$$(if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi); \
dockerfile_windows=$$(if [ -e ./cmd/$*/Dockerfile.Windows ]; then echo ./cmd/$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \
build_platforms='$(BUILD_PLATFORMS)'; \
if ! [ "$$build_platforms" ]; then build_platforms="linux amd64"; fi; \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we set the default in L45?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$(BUILD_PLATFORMS) is expanded by make, so the usual shell mechanism (${var:-default}) does not work.

I've combined the two lines into one with:

if [ '$(BUILD_PLATFORMS)' ]; then build_platforms='$(BUILD_PLATFORMS)'; else build_platforms="linux amd64"; fi;

Makefile Outdated
else \
: "release image $(IMAGE_NAME):$(PULL_BASE_REF) already exists, skipping push"; \
: "release image $(IMAGE_NAME):$(PULL_BASE_REF) already exists, skipping push"; \
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be silently ignored, or return an error?

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 haven't thought about this much. The whole if/else sequence here was copied originally from the corresponding "push" target and I just kept it. The original motivation for the check was that we directly push to the final destination, and those images should never be rebuilt because someone may already have pulled them. Here the situation is a bit different.

Do we expect that the cloud image build job will run more than once per tag? If no, then we can remove the "does the image exist" check because the image should never exist already. If yes, perhaps the build job was triggered intentionally again and the goal was to rebuild the image.

I'm leaning towards removing the check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should never repush an existing tag (except for canary), even if there was some error. We would have to resolve that scenario by incrementing the tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, it's an error now.

@pohly
Copy link
Contributor Author

pohly commented May 27, 2020

@msau42: please take another look

@msau42
Copy link
Collaborator

msau42 commented May 28, 2020

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: msau42, pohly

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 28, 2020
@k8s-ci-robot k8s-ci-robot merged commit 522b79b into kubernetes-csi:master May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants