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(docker): Checkov installation silently fails on docker build in arm64. Workaround till issue will be fixed in checkov itself #635

Merged
Merged
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5cf0ca5
fix-workaround: Checkov install fails aarch64. Awaiting checkov versi…
antm-pp Feb 23, 2024
63f4bef
fix: Docker Checkov - Keep libgcc and remove gcc for compatibility wi…
antm-pp Feb 23, 2024
7014fa0
fix:checkob install - pinned apk versions
antm-pp Feb 23, 2024
3d85490
Add comments on package dependencies and re-order
antm-pp Feb 23, 2024
a13a983
fix: Docker Checkov install: Added gcc container check
antm-pp Feb 23, 2024
42d77d9
fix: Docker checkov install: reorder values and comments on package i…
antm-pp Feb 24, 2024
f46e8f8
fix: Docker Checkov Install: Container structure test: regex excape c…
antm-pp Feb 24, 2024
9b58092
Update .github/.container-structure-test-config.yaml
antm-pp Feb 24, 2024
3e0d679
fix: Docker Checkov Install: Use git fetch for crates for consistency…
antm-pp Feb 24, 2024
b5c6379
Merge branch 'master' into fix/docker-checkov-install-aarch64
MaxymVlasov Feb 26, 2024
54e5ea2
fix(dockerfile): Deal with "successful silent fails" during `docker b…
MaxymVlasov Mar 7, 2024
8798d3b
fix Checkov?
MaxymVlasov Mar 7, 2024
c3322d0
Try use checkov binary. Checkov still needs all deps installed by pip
MaxymVlasov Mar 7, 2024
875999c
Revert "Try use checkov binary. Checkov still needs all deps installe…
MaxymVlasov Mar 7, 2024
3481201
Revert "fix Checkov?"
MaxymVlasov Mar 7, 2024
c4c1b16
Merge remote-tracking branch 'upstream/fix/dockerfile' into fix/docke…
MaxymVlasov Mar 7, 2024
2f00dcf
fix silent fail
MaxymVlasov Mar 7, 2024
5e98ae3
test
MaxymVlasov Mar 7, 2024
1ca976a
Apply suggestions from code review
MaxymVlasov Mar 8, 2024
01d0868
Apply suggestions from code review
MaxymVlasov Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ RUN if [ "$INSTALL_ALL" != "false" ]; then \
RUN . /.env && \
if [ "$CHECKOV_VERSION" != "false" ]; then \
( \
apk add --no-cache gcc=~12 libffi-dev=~3 musl-dev=~1; \
apk add --no-cache gcc=~12 libffi-dev=~3 musl-dev=~1 libgcc=~12 rust=~1 cargo=~1; \
Copy link
Collaborator

Choose a reason for hiding this comment

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

A few questions: Did you try to remove each of these dependencies, build an image, and confirm that is a minimal setup?

Please add check for GCC in https://github.com/antonbabenko/pre-commit-terraform/blob/master/.github/.container-structure-test-config.yaml

Also, I think that we need to find a way to run these tests on arm64 too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is minimal dependencies. So gcc was already present in the failing build, as used for same approach by cffi compile. Tried adding only rust, and it errored cargo still missing.

Guidance for rustworkx indicates need for compiler including rust and cargo (or to use rustup a cross platform installer).

Noticed when the pre-existing purge of gcc occurred it caused exception in running checkov in the build container, therefore applied libgcc seperately to minimise that dependency and it executes ok (for the version check). When referring to the final image I noted that gcc in full is already a dependency for the pre-commit hooks. I couldn't see obviously where it's documented what hook that dependency is for. I could add a further comment to highlight it's at least needed for checkov.

Happy to add a gcc check as requested, although I've not added the gcc dependency in the final image.

Just to note, the linux/arm64 builds have been failing for sometime, an example from 2 months ago: https://github.com/antonbabenko/pre-commit-terraform/actions/runs/7183944518/job/19563861227#step:9:741

I'm just running through some tests, it looks like the linux/arm64 build is failing because it can't pull crates.io. I tried one recommended test saying to set env-var CARGO_NET_GIT_FETCH_WITH_CLI=true which then created a dependency on git (which again is already in the final image but not the builder). Just trying a run with that, so that darwin/arm64 and linux/arm64 can both compile.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Happy to add a gcc check as requested, although I've not added the gcc dependency in the final image.

Ah, really? I see removal of rust and cargo, but not libgcc. How it works then 🤔

If there no package at the end - then there nothing to test

Copy link
Collaborator

Choose a reason for hiding this comment

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

Happy to add a gcc check as requested, although I've not added the gcc dependency in the final image.

Ah, really? I see removal of rust and cargo, but not libgcc. How it works then 🤔

Apologies if I'm missing some bits of context: gcc != libcc. The former is the compiler collection and the latter is runtime libs only — https://pkgs.alpinelinux.org/package/edge/main/x86/gcc vs https://pkgs.alpinelinux.org/package/edge/main/x86/libgcc

Copy link
Collaborator

Choose a reason for hiding this comment

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

Btw, we can't just add tests for macos, as Structure Test currently not support macos
#636

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I think the issue is the structure of the '||' command for the install. When the rust compiler call fails it generates a false allowing the other part of the command to run (intended for managing checkov==latest vs checkov==). The 2nd part has its own failure mode that doesn't actually generated an exit1. So the error gets buried and the build passes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So all these combinations should be rewritten to vanilla if-then-else statements? @yermulnik

[ "$CHECKOV_VERSION" = "latest" ] && pip3 install --no-cache-dir checkov \
|| pip3 install --no-cache-dir checkov==${CHECKOV_VERSION}; \

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, yep, that sort of "ternary" in Bash is not vanilla if/else and has this kind of "discomfortable" hiccups 😿
And, yes, these need to be re-written 😢 Either using vanilla if/else, or like below:

 [ "$CHECKOV_VERSION" = "latest" ] && pip3 install --no-cache-dir checkov; \ 
 [ "$CHECKOV_VERSION" != "latest" ] && pip3 install --no-cache-dir checkov==${CHECKOV_VERSION}; \

ps: I probably can try and do that, though I will need help building it and testing resulting images (@MaxymVlasov, that would be super great if you already had that automation so that I can push changes and you test build/run 🤪).

Copy link
Collaborator

Choose a reason for hiding this comment

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

or like below 🤔

 [ "$CHECKOV_VERSION" = "latest" ] && CHECKOV_VERSION="" || CHECKOV_VERSION="==${CHECKOV_VERSION}"; \ 
 pip3 install --no-cache-dir checkov${CHECKOV_VERSION}; \ 

Copy link
Collaborator

Choose a reason for hiding this comment

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

@yermulnik done in this PR. Also, I can confirm that without @antm-pp changes to rust-cargo, it fails in arm64, when with - checks passes.

And now we have prevention of silent fails for checkov - #635 (review)

[ "$CHECKOV_VERSION" = "latest" ] && pip3 install --no-cache-dir checkov \
|| pip3 install --no-cache-dir checkov==${CHECKOV_VERSION}; \
apk del gcc libffi-dev musl-dev \
apk del gcc libffi-dev musl-dev rust cargo \
) \
; fi

Expand Down
Loading