-
Notifications
You must be signed in to change notification settings - Fork 1
Add tests to test size of the image to catch regressions #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9291a27
Test image size
JackPGreen f09fde4
https://github.com/hazelcast/docker-actions/pull/40#discussion_r26100…
JackPGreen 61d87e2
https://github.com/hazelcast/docker-actions/pull/40#discussion_r26100…
JackPGreen 7609bd2
Fix permissions
JackPGreen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: Test assert-image-size action | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Test scripts | ||
| run: ./assert-image-size/test_scripts.sh | ||
|
|
||
| - name: Run assert-image-size | ||
| uses: ./assert-image-size | ||
| with: | ||
| image: hazelcast/hazelcast:5.0.1-slim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # assert-image-size | ||
|
|
||
| A GitHub Action that validates image isn't excessively large / wasting space using [`dive`](https://github.com/wagoodman/dive). | ||
|
|
||
| Docker images are built of overlaid [layers](https://docs.docker.com/get-started/docker-concepts/building-images/understanding-image-layers), building on top of one-another. When downloading an image, each layer is downloaded. | ||
|
|
||
| If one layer contains a file that is subsequently removed or modified in a subsequent layer, this intermediate state will still be present in the layer to be downloaded, bloating the overall image. An example of this occurred in <https://github.com/hazelcast/hazelcast-docker/pull/1137>. | ||
|
|
||
| This action asserts that the amount of wasted space in an image is below a % threshold. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Test image size | ||
| description: Test image isn't excessively large / wasting space | ||
|
|
||
| inputs: | ||
| image: | ||
| description: Image name to test | ||
| required: true | ||
| minimum_efficiency: | ||
| description: Minimum efficiency percentage required - 0-1 scale | ||
| required: false | ||
| default: 0.95 | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - shell: bash | ||
| run: | | ||
| . ${GITHUB_ACTION_PATH}/assert-image-size.functions.sh | ||
|
|
||
| assert_image_size "${IMAGE}" "${MINIMUM_EFFICIENCY}" | ||
| env: | ||
| IMAGE: ${{ inputs.image }} | ||
| MINIMUM_EFFICIENCY: ${{ inputs.minimum_efficiency }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| function assert_image_size() { | ||
| local image=$1 | ||
| local minimum_efficiency=$2 | ||
|
|
||
| local config_file | ||
| config_file=$(mktemp) | ||
|
|
||
| # https://github.com/wagoodman/dive/blob/main/README.md#ci-integration | ||
| yq eval -n " | ||
| .rules.lowestEfficiency = ${minimum_efficiency} | | ||
| .rules.highestWastedBytes = \"disabled\" | | ||
| .rules.highestUserWastedPercent = \"disabled\" | ||
| " > "${config_file}" | ||
|
|
||
| docker run --rm \ | ||
| --env CI=true \ | ||
| --volume /var/run/docker.sock:/var/run/docker.sock \ | ||
| --volume "${config_file}:/.dive-ci" \ | ||
| docker.io/wagoodman/dive:latest \ | ||
| "${image}" | ||
|
|
||
| return $? | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -eu ${RUNNER_DEBUG:+-x} | ||
|
|
||
| SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" | ||
|
|
||
| # Source the latest version of assert.sh unit testing library and include in current shell | ||
| source /dev/stdin <<< "$(curl --silent https://raw.githubusercontent.com/hazelcast/assert.sh/main/assert.sh)" | ||
|
|
||
| . "$SCRIPT_DIR"/assert-image-size.functions.sh | ||
|
|
||
| TESTS_RESULT=0 | ||
|
|
||
| function assert_assert_image_size { | ||
|
Check warning on line 14 in assert-image-size/assert-image-size.functions_tests.sh
|
||
| local image=$1 | ||
| local minimum_efficiency=$2 | ||
| local expected_exit_code=$3 | ||
| assert_image_size "${image}" "${minimum_efficiency}" && true | ||
| local actual_exit_code=$? | ||
| local msg="Expected exit code for \"${image}\" / \"${minimum_efficiency}\"" | ||
| assert_eq "${expected_exit_code}" "${actual_exit_code}" "${msg}" && log_success "${msg}" || TESTS_RESULT=$? | ||
| } | ||
|
|
||
| log_header "Tests for assert_image_size" | ||
| # expected efficiency: 99.8541 % | ||
| assert_assert_image_size hazelcast/hazelcast:5.0.1-slim 0.95 0 | ||
| assert_assert_image_size hazelcast/hazelcast:5.0.1-slim 0.99999999999 1 | ||
|
|
||
| assert_eq 0 "$TESTS_RESULT" "All tests should pass" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" | ||
|
|
||
| find "$SCRIPT_DIR" -name "*_tests.sh" -print0 | xargs -0 -n1 bash |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.