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

DevOps: Fix json query in reading the docker names to filter out fields not starting with aiida #6573

Merged
merged 7 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Build images
uses: docker/bake-action@v5
uses: docker/bake-action@v5.5.0
agoscinski marked this conversation as resolved.
Show resolved Hide resolved
with:
# Load to Docker engine for testing
load: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- name: Build and upload to ghcr.io 📤
id: build
uses: docker/bake-action@v5
uses: docker/bake-action@v5.5.0
agoscinski marked this conversation as resolved.
Show resolved Hide resolved
with:
push: true
workdir: .docker/
Expand Down
35 changes: 17 additions & 18 deletions .github/workflows/extract-docker-image-names.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,35 @@ set -euo pipefail
# The input to this script is a JSON string passed via BAKE_METADATA env variable
# Here's example input (trimmed to relevant bits):
# BAKE_METADATA: {
# "base": {
# "aiida-core-base": {
# # ...
# "containerimage.descriptor": {
# "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
# "digest": "sha256:8e57a52b924b67567314b8ed3c968859cad99ea13521e60bbef40457e16f391d",
# "size": 6170,
# },
# "containerimage.digest": "sha256:8e57a52b924b67567314b8ed3c968859cad99ea13521e60bbef40457e16f391d",
# "image.name": "ghcr.io/aiidalab/base"
# },
# "aiida-core-base": {
# "image.name": "ghcr.io/aiidateam/aiida-core-base"
# "containerimage.digest": "sha256:6753a809b5b2675bf4c22408e07c1df155907a465b33c369ef93ebcb1c4fec26",
# "...": ""
# }
# "aiida-core-with-services": {
# "image.name": "ghcr.io/aiidateam/aiida-core-with-services"
# "containerimage.digest": "sha256:85ee91f61be1ea601591c785db038e5899d68d5fb89e07d66d9efbe8f352ee48",
# "...": ""
# }
# },
# "aiida-core-dev": {
# "image.name": "ghcr.io/aiidateam/aiida-core-with-services"
# "containerimage.digest": "sha256:4d9be090da287fcdf2d4658bb82f78bad791ccd15dac9af594fb8306abe47e97",
# "...": ...
# "image.name": "ghcr.io/aiidateam/aiida-core-dev"
# },
# "aiida-core-with-services": {
# "...": ""
# }
# "containerimage.digest": "sha256:85ee91f61be1ea601591c785db038e5899d68d5fb89e07d66d9efbe8f352ee48",
# "image.name": "ghcr.io/aiidateam/aiida-core-with-services"
# },
# "some-other-key": ...
# }
#
# Example output (real output is on one line):
#
# images={
# "AIIDA_CORE_BASE_IMAGE": "ghcr.io/aiidateam/aiida-core-base@sha256:8e57a52b924b67567314b8ed3c968859cad99ea13521e60bbef40457e16f391d",
# "AIIDA_CORE_WITH_SERVICES_IMAGE": "ghcr.io/aiidateam/aiida-core-with-services@sha256:6753a809b5b2675bf4c22408e07c1df155907a465b33c369ef93ebcb1c4fec26",
# "AIIDA_CORE_DEV_IMAGE": "ghcr.io/aiidateam/aiida-core-dev@sha256:85ee91f61be1ea601591c785db038e5899d68d5fb89e07d66d9efbe8f352ee48",
# "AIIDA_CORE_BASE_IMAGE": "ghcr.io/aiidateam/aiida-core-base@sha256:4c402a8bfd635650ad691674f8f29e7ddec5fa656fb425452067950415ee447f",
# "AIIDA_CORE_DEV_IMAGE": "ghcr.io/aiidateam/aiida-core-dev@sha256:f94c06e47f801e751f9829010b31532039b210aad2649d43205e16c08371b2ed",
# "AIIDA_CORE_WITH_SERVICES_IMAGE": "ghcr.io/aiidateam/aiida-core-with-services@sha256:bd8272f2a331af7eac3e83c44cc16d23b2e5f601a20ab4a865402659b758515e"
# }
#
# This json output is later turned to environment variables using fromJson() GHA builtin
Expand All @@ -52,5 +49,7 @@ if [[ -z ${BAKE_METADATA-} ]];then
exit 1
fi

images=$(echo "${BAKE_METADATA}" | jq -c '. as $base |[to_entries[] |{"key": (.key|ascii_upcase|sub("-"; "_"; "g") + "_IMAGE"), "value": [(.value."image.name"|split(",")[0]),.value."containerimage.digest"]|join("@")}] |from_entries')
images=$(echo "${BAKE_METADATA}" |
jq -c 'to_entries | map(select(.key | startswith("aiida"))) | from_entries' | # filters out every key that does not start with aiida
Copy link
Collaborator

Choose a reason for hiding this comment

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

interesting approach, although I am honestly quite unhappy about this obscure jq syntax.
Perhaps we should switch to javascript to make this more readable. This was recommended to me here:

docker/bake-action#239 (comment)

Copy link
Contributor Author

@agoscinski agoscinski Sep 27, 2024

Choose a reason for hiding this comment

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

Yes agree, understanding this json query was very cumbersome. I would prefer some Python code for this repo, but I guess it results in a similar code you linked.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed, if you can figure out some Python one-liner that would be best.

jq -c '. as $base |[to_entries[] |{"key": (.key|ascii_upcase|sub("-"; "_"; "g") + "_IMAGE"), "value": [(.value."image.name"|split(",")[0]),.value."containerimage.digest"]|join("@")}] |from_entries')
echo "images=$images"
Loading