9797 const config = require('./deploy/build/config.json');
9898
9999 const buildTime = new Date().toISOString().replace(/:/g, '').replace(/\..+/, 'Z');
100- const imageTagBranchName = "${{ github.ref }}".replace('refs/heads/', '').replace('refs/tags/', '').replace(/[^a-zA-Z0-9._-]/g, '-');
101- const imageTag = `tagged-${imageTagBranchName}-${buildTime}`;
102100
103101 const builds = process.env.BUILDS ? process.env.BUILDS.split(',') : Object.keys(config.build);
104102 const push_to = process.env.PUSH_TO ? process.env.PUSH_TO.split(',') : Object.keys(config.push || {});
@@ -116,9 +114,6 @@ jobs:
116114 skip_retag: skip_push,
117115 // Add metadata to the flavor object (will be used as matrix input)
118116 build_time: buildTime,
119- image_tag: imageTag,
120- image_tag_branch_name: imageTagBranchName,
121- ecr_repositories: flavor.components.map(component => component.ecr_repository),
122117 test_images: {
123118 enabled: testImageEnabled,
124119 script_path: testImagesHookScript,
@@ -129,6 +124,9 @@ jobs:
129124 const formattedBuildArgs = component.build_args ?
130125 Object.entries(component.build_args).map(([key, value]) => `${key}=${value}`).join('\n') : '';
131126
127+ const imageTagAfterRetag = (component.image_tag_prefix || '') + "${{ github.ref }}".replace('refs/heads/', '').replace('refs/tags/', '').replace(/[^a-zA-Z0-9._-]/g, '-') + (component.image_tag_suffix || '');
128+ const imageTagBeforeRetag = `tagged-${imageTagAfterRetag}-${buildTime}`;
129+
132130 return {
133131 ...component,
134132 // We can skip the push only if we don't want to test the image below
@@ -138,9 +136,9 @@ jobs:
138136 flavor_id: id,
139137 flavor_directory: `./deploy/build/${flavor.directory}`,
140138 build_time: buildTime,
141- image_tag: imageTag ,
142- image_ref: `${{ vars.DV_AWS_ECR_REGISTRY }}/${component.ecr_repository}:${imageTag }`,
143- image_tag_branch_name: imageTagBranchName ,
139+ image_tag_before_retag: imageTagBeforeRetag ,
140+ image_ref: `${{ vars.DV_AWS_ECR_REGISTRY }}/${component.ecr_repository}:${imageTagBeforeRetag }`,
141+ image_tag_after_retag: imageTagAfterRetag ,
144142 formatted_build_args: formattedBuildArgs,
145143 };
146144 }),
@@ -163,7 +161,7 @@ jobs:
163161 PUSH_TO : ${{ inputs.push_to }}
164162
165163 build-flavors :
166- name : Build ${{ matrix.component.directory }} of ${{ matrix.component.flavor.directory }} (${{ matrix.component.ecr_repository }}:${{ matrix.component.image_tag }})
164+ name : Build ${{ matrix.component.directory }} of ${{ matrix.component.flavor.directory }} (${{ matrix.component.ecr_repository }}:${{ matrix.component.image_tag_before_retag }})
167165 needs : get-flavors
168166 strategy :
169167 fail-fast : ${{ inputs.fail_fast }}
@@ -247,6 +245,8 @@ jobs:
247245 # Disable provenance as it creates weird multi-arch images: https://github.com/docker/build-push-action/issues/755
248246 provenance : false
249247 # Disable the cache to avoid outdated (base) images
248+ # TODO: are we sure we want this? We might benefit a lot from caching! But also, our base images like datavisyn/base/python:main are updated frequently and have no version tag...
249+ # maybe no-cache-filters works? Or we do this on our self-hosted runners: https://docs.docker.com/build/ci/github-actions/cache/#local-cache
250250 no-cache : true
251251 build-args : |
252252 GIT_BRANCH=${{ steps.get-branch.outputs.branch }}
@@ -265,12 +265,12 @@ jobs:
265265 ${{ matrix.component.image_ref }}
266266 labels : |
267267 name=${{ matrix.component.ecr_repository }}
268- version=${{ matrix.component.image_tag_branch_name }}
268+ version=${{ matrix.component.image_tag_after_retag }}
269269 org.opencontainers.image.description=Image for ${{ matrix.component.ecr_repository }}
270270 org.opencontainers.image.source=${{ github.event.repository.html_url }}
271271 org.opencontainers.image.url=${{ github.event.repository.html_url }}
272272 org.opencontainers.image.title=${{ matrix.component.ecr_repository }}
273- org.opencontainers.image.version=${{ matrix.component.image_tag_branch_name }}
273+ org.opencontainers.image.version=${{ matrix.component.image_tag_after_retag }}
274274 org.opencontainers.image.created=${{ matrix.component.build_time }}
275275 org.opencontainers.image.revision=${{ github.sha }}
276276 env :
@@ -426,19 +426,19 @@ jobs:
426426 - name : Retag images
427427 shell : bash
428428 run : |
429- image_tag="${{ matrix.flavor.image_tag }}"
430- image_tag_branch_name="${{ matrix.flavor.image_tag_branch_name }}"
429+ for component in $(jq -c '.components[]' <<< "$FLAVOR"); do
430+ repository_name=$(jq -r '.ecr_repository' <<< "$component")
431+ image_tag_before_retag=$(jq -r '.image_tag_before_retag' <<< "$component")
432+ image_tag_after_retag=$(jq -r '.image_tag_after_retag' <<< "$component")
431433
432- echo "image_tag=$image_tag"
433- echo "image_tag_branch_name=$image_tag_branch_name"
434+ echo "Processing repository: $repository_name, image_tag_before_retag: $image_tag_before_retag, image_tag_after_retag: $image_tag_after_retag"
434435
435- for repository_name in $(jq -r '.ecr_repositories[]' <<< "$FLAVOR"); do
436- IMAGE_META=$(aws ecr describe-images --repository-name "$repository_name" --image-ids imageTag="$image_tag" --output json | jq --arg var "${image_tag_branch_name}" '.imageDetails[0].imageTags | index( $var )')
437- if [[ -z "${IMAGE_META}" || ${IMAGE_META} == "null" ]]; then
438- MANIFEST=$(aws ecr batch-get-image --repository-name "$repository_name" --image-ids imageTag="$image_tag" --output json | jq --raw-output --join-output '.images[0].imageManifest')
439- aws ecr put-image --repository-name "$repository_name" --image-tag "$image_tag_branch_name" --image-manifest "$MANIFEST"
436+ IMAGE_META=$(aws ecr describe-images --repository-name "$repository_name" --image-ids imageTag="$image_tag_before_retag" --output json | jq --arg var "${image_tag_after_retag}" '.imageDetails[0].imageTags | index($var)')
437+ if [[ -z "${IMAGE_META}" || "${IMAGE_META}" == "null" ]]; then
438+ MANIFEST=$(aws ecr batch-get-image --repository-name "$repository_name" --image-ids imageTag="$image_tag_before_retag" --output json | jq --raw-output --join-output '.images[0].imageManifest')
439+ aws ecr put-image --repository-name "$repository_name" --image-tag "$image_tag_after_retag" --image-manifest "$MANIFEST"
440440 else
441- echo "image already tagged!"
441+ echo "Image already tagged for repository: $repository_name !"
442442 fi
443443 done;
444444 env :
0 commit comments