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

fix: fix bazel-out path for rules_docker-0.23.0 #7251

Merged
merged 5 commits into from
Apr 5, 2022

Conversation

codersasha
Copy link
Contributor

@codersasha codersasha commented Mar 31, 2022

Fixes: #7228
Related: bazelbuild/rules_docker#1963
Merge before/after: Dependent or prerequisite PRs

Description

With the release of https://github.com/bazelbuild/rules_docker/releases/tag/v0.23.0, the output directory for bazel targets is calculated differently and is no longer a static path.

For example, a container_image target such as:

//foo/bar/server:server_img.tar

Previously was stored at:

bazel-out/k8-fastbuild/bin/foo/bar/server/server_img.tar

Internally, skaffold calculated this path by running bazel info bazel-bin, which returns the start of the path (e.g. /home/...../execroot/__main__/bazel-out/k8-fastbuild/bin), then appended the name of the rule with : replaced with / (e.g. foo/bar/server/server_img.tar). This results in the correct path as above.

However, with rules_docker-0.23.0, the output is now stored at a path like:

bazel-out/k8-fastbuild-ST-4a519fd6d3e4/bin/foo/bar/server/server_img.tar

So bazel info no longer returns the correct path prefix.

Using bazel cquery with a similar method to that described in https://github.com/bazelbuild/rules_pkg/tree/main/examples/where_is_my_output, as recommended in bazelbuild/rules_docker#1963 (comment), we can query Bazel for the actual output path to the target. Docker .tar output files are available in cquery as targets with a .files attribute, which contains the list of output files (there's only one), and each file has a .path attribute that gives the path to the file, which we can use internally in Skaffold. This is also backwards compatible with older versions of https://github.com/bazelbuild/rules_docker.

For example, the command:

bazel cquery //foo/bar/server:server_img.tar --output starlark --starlark:expr="target.files.to_list()[0].path"

May return:

bazel-out/k8-fastbuild/bin/foo/bar/server/server_img.tar

And with rules_docker-0.23.0, this may return something like:

bazel-out/k8-fastbuild-ST-4a519fd6d3e4/bin/foo/bar/server/server_img.tar

Which is the correct path to the target.

@codersasha codersasha requested a review from a team as a code owner March 31, 2022 08:58
@codersasha codersasha changed the title Bazel-out path fix for rules_docker-0.23.0 fix: bazel-out path for rules_docker-0.23.0 Mar 31, 2022
@codersasha codersasha changed the title fix: bazel-out path for rules_docker-0.23.0 fix: fix bazel-out path for rules_docker-0.23.0 Mar 31, 2022
@MarlonGamez
Copy link
Contributor

hi @sashamor , Thanks for opening this change! It looks like you'll have to go in and update TestBuildBazel unit test as well, but other than that these changes look good :)

@codersasha
Copy link
Contributor Author

Thanks, fixed :) Also changed the arguments to no longer use nested quotes.

Tested locally with https://github.com/bazelbuild/rules_docker v0.23.0 and v0.22.0 and can confirm they both find the output tar correctly as expected.

@Anthony-Bible
Copy link

Anthony-Bible commented Apr 5, 2022

I wanted to add another data point, I had a similar problem and it worked when running with your patch with multiple images.

@codecov
Copy link

codecov bot commented Apr 5, 2022

Codecov Report

Merging #7251 (1bab727) into main (290280e) will decrease coverage by 1.98%.
The diff coverage is 56.96%.

@@            Coverage Diff             @@
##             main    #7251      +/-   ##
==========================================
- Coverage   70.48%   68.50%   -1.99%     
==========================================
  Files         515      560      +45     
  Lines       23150    26507    +3357     
==========================================
+ Hits        16317    18158    +1841     
- Misses       5776     7095    +1319     
- Partials     1057     1254     +197     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/deploy.go 52.00% <ø> (-1.85%) ⬇️
cmd/skaffold/app/cmd/dev.go 84.61% <0.00%> (ø)
cmd/skaffold/app/cmd/render.go 36.66% <0.00%> (-4.72%) ⬇️
cmd/skaffold/skaffold.go 0.00% <0.00%> (ø)
cmd/skaffold/app/cmd/inspect_tests.go 62.50% <14.28%> (-1.14%) ⬇️
cmd/skaffold/app/cmd/lsp.go 28.12% <28.12%> (ø)
cmd/skaffold/app/cmd/fix.go 68.85% <40.00%> (-7.62%) ⬇️
cmd/skaffold/app/cmd/lint.go 42.85% <42.85%> (ø)
cmd/skaffold/app/cmd/find_configs.go 48.88% <50.00%> (+0.24%) ⬆️
cmd/skaffold/app/skaffold.go 76.19% <70.00%> (-8.43%) ⬇️
... and 224 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@MarlonGamez
Copy link
Contributor

MarlonGamez commented Apr 5, 2022

@sashamor , thanks for making the change! I have a fix open for the github action failure we're seeing

Once #7263 is merged, could you rebase this PR to retrigger the tests? I think it should be fixed then

@MarlonGamez MarlonGamez merged commit ba6ba4f into GoogleContainerTools:main Apr 5, 2022
@codersasha codersasha deleted the sashamor/fix-7228 branch April 6, 2022 05:53
@codersasha
Copy link
Contributor Author

Thanks for rebasing and merging :) Woohoo

}

tarPath := filepath.Join(bazelBin, buildTarPath(a.BuildTarget))
Copy link
Contributor

@morozov morozov May 19, 2022

Choose a reason for hiding this comment

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

It looks like this breaks the scenarios where the artifact has a non-default context and the skaffold command is executed from within a path different than the repository root.

The bazel cquery runs in the directory corresponding to the context and returns the tar path relative to that context but docker.Push() still runs in the current working directory and is now supplied with a path relative to the context, not relative to the current working directory.

Take the following example. There is a skaffold file in projects/acme/some-projects:

apiVersion: skaffold/v2beta26
kind: Config
build:
  artifacts:
  - image: quay.io/acme/some-project
    context: ../../..

If one does:

cd projects/acme/some-projects && skaffold build

It will no longer work. It will fail with an error like:

build [quay.io/acme/some-project] failed: reading image "bazel-out/darwin-fastbuild-ST-4a519fd6d3e4/bin/projects/some-project/docker.tar": open bazel-out/darwin-fastbuild-ST-4a519fd6d3e4/bin/projects/some-project//docker.tar: no such file or directory

I guess this is the same issue as reported in #7281.

copybaranaut pushed a commit to pixie-io/pixie that referenced this pull request Jun 8, 2022
Summary:
This includes the fixes from GoogleContainerTools/skaffold#7251
which makes skaffold work with the new version of rules_docker and the output
locations of built images.

Test Plan: Deployed a dev vizier with skaffold

Reviewers: michelle, zasgar

Reviewed By: zasgar

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11550

GitOrigin-RevId: fb39f7a
eap added a commit to eap/rules_docker that referenced this pull request Jul 6, 2022
The tar output location has been changed and is no longer stable. The old docs were not updated at the time of the change and the result is confusing build breakages. Until the original behavior is added back (not clear that it will happen) the README should document the new behavior.

See Issue bazelbuild#2014 for more info (this was closed as WAI), and [GoogleContainerTools PR#7251](GoogleContainerTools/skaffold#7251) for more context.
gravypod pushed a commit to bazelbuild/rules_docker that referenced this pull request Jul 7, 2022
* Update README to account for new tar build output

The tar output location has been changed and is no longer stable. The old docs were not updated at the time of the change and the result is confusing build breakages. Until the original behavior is added back (not clear that it will happen) the README should document the new behavior.

See Issue #2014 for more info (this was closed as WAI), and [GoogleContainerTools PR#7251](GoogleContainerTools/skaffold#7251) for more context.

* Update README.md

add ".tar" to the query, it is needed!
orishuss pushed a commit to orishuss/pixie that referenced this pull request Jul 14, 2022
Summary:
This includes the fixes from GoogleContainerTools/skaffold#7251
which makes skaffold work with the new version of rules_docker and the output
locations of built images.

Test Plan: Deployed a dev vizier with skaffold

Reviewers: michelle, zasgar

Reviewed By: zasgar

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11550

GitOrigin-RevId: fb39f7a
orishuss pushed a commit to orishuss/pixie that referenced this pull request Jul 14, 2022
Summary:
This includes the fixes from GoogleContainerTools/skaffold#7251
which makes skaffold work with the new version of rules_docker and the output
locations of built images.

Test Plan: Deployed a dev vizier with skaffold

Reviewers: michelle, zasgar

Reviewed By: zasgar

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11550

GitOrigin-RevId: fb39f7a
orishuss pushed a commit to orishuss/pixie that referenced this pull request Jul 14, 2022
Summary:
This includes the fixes from GoogleContainerTools/skaffold#7251
which makes skaffold work with the new version of rules_docker and the output
locations of built images.

Test Plan: Deployed a dev vizier with skaffold

Reviewers: michelle, zasgar

Reviewed By: zasgar

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11550

GitOrigin-RevId: fb39f7a
St0rmingBr4in pushed a commit to St0rmingBr4in/rules_docker that referenced this pull request Oct 17, 2022
* Update README to account for new tar build output

The tar output location has been changed and is no longer stable. The old docs were not updated at the time of the change and the result is confusing build breakages. Until the original behavior is added back (not clear that it will happen) the README should document the new behavior.

See Issue bazelbuild#2014 for more info (this was closed as WAI), and [GoogleContainerTools PR#7251](GoogleContainerTools/skaffold#7251) for more context.

* Update README.md

add ".tar" to the query, it is needed!
ericzzzzzzz pushed a commit to ericzzzzzzz/skaffold that referenced this pull request Mar 30, 2023
…ls#7251)

Co-authored-by: Marlon Gamez <marlongamez98@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatible output directory with io_bazel_rules_docker v0.23
4 participants