Skip to content

Commit

Permalink
DevOps: Fix json query in reading the docker names to filter out fiel…
Browse files Browse the repository at this point in the history
…ds not starting with aiida (#6573)

With the version update of bake-action the `BAKE_METADATA` a field with warning
information (buildx.build.warnings) was added that does not contain the key
`image.name` so the json query failed. With this commit another json query was
added that filters out every field name that does not start with "aiida", so
the field with warning information is filtered out.


Co-authored-by: Jusong Yu <[email protected]>
  • Loading branch information
agoscinski and unkcpz authored Oct 17, 2024
1 parent 332a4a9 commit e1467ed
Showing 1 changed file with 17 additions and 18 deletions.
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
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"

0 comments on commit e1467ed

Please sign in to comment.