Skip to content

Commit d49f52a

Browse files
committed
Add suffix and prefix support
1 parent 775a4e3 commit d49f52a

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

.github/workflows/build-docker-artifacts-push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ jobs:
6767
const filteredRepositories = customer.repositories.filter(repo => !repo.skip);
6868
6969
// Comma separated list of source images, incl. registry, repository and tag
70-
const sourceImages = filteredRepositories.map(repo => `${process.env.SOURCE_ECR_REGISTRY}/${repo.source_repository}:${repo.source_image_tag || process.env.IMAGE_TAG}`).join(',');
71-
const destinationImages = filteredRepositories.map(repo => `${customer.registry}/${repo.target_repository}:${repo.target_image_tag || process.env.IMAGE_TAG}`).join(',');
70+
const sourceImages = filteredRepositories.map(repo => `${process.env.SOURCE_ECR_REGISTRY}/${repo.source_repository}:${repo.image_tag_prefix || ''}${repo.source_image_tag || process.env.IMAGE_TAG}${repo.image_tag_suffix || ''}`).join(',');
71+
const destinationImages = filteredRepositories.map(repo => `${customer.registry}/${repo.target_repository}:${repo.image_tag_prefix || ''}${repo.target_image_tag || process.env.IMAGE_TAG}${repo.image_tag_suffix || ''}`).join(',');
7272
7373
const result = {
7474
customer,

.github/workflows/build-docker-artifacts-trigger-push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ jobs:
7575
7676
const customers = process.env.PUSH_TO ? process.env.PUSH_TO.split(',') : Object.keys(config.push || {});
7777
78-
const imageTagBranchName = "${{ github.ref }}".replace('refs/heads/', '').replace('refs/tags/', '').replace(/[^a-zA-Z0-9._-]/g, '-');
78+
const imageTagAfterRetag = "${{ github.ref }}".replace('refs/heads/', '').replace('refs/tags/', '').replace(/[^a-zA-Z0-9._-]/g, '-');
7979
8080
const result = customers.map((c) => ({
8181
repository: process.env.REPOSITORY,
8282
customer: c,
8383
customer_json: JSON.stringify(config.push[c]),
84-
image_tag: imageTagBranchName,
84+
image_tag: imageTagAfterRetag,
8585
}));
8686
console.log(result);
8787
return result;

.github/workflows/build-docker-artifacts.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ jobs:
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 || {});
@@ -126,6 +124,9 @@ jobs:
126124
const formattedBuildArgs = component.build_args ?
127125
Object.entries(component.build_args).map(([key, value]) => `${key}=${value}`).join('\n') : '';
128126
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+
129130
return {
130131
...component,
131132
// We can skip the push only if we don't want to test the image below
@@ -135,9 +136,9 @@ jobs:
135136
flavor_id: id,
136137
flavor_directory: `./deploy/build/${flavor.directory}`,
137138
build_time: buildTime,
138-
image_tag: imageTag,
139-
image_ref: `${{ vars.DV_AWS_ECR_REGISTRY }}/${component.ecr_repository}:${imageTag}`,
140-
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,
141142
formatted_build_args: formattedBuildArgs,
142143
};
143144
}),
@@ -160,7 +161,7 @@ jobs:
160161
PUSH_TO: ${{ inputs.push_to }}
161162

162163
build-flavors:
163-
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 }})
164165
needs: get-flavors
165166
strategy:
166167
fail-fast: ${{ inputs.fail_fast }}
@@ -264,12 +265,12 @@ jobs:
264265
${{ matrix.component.image_ref }}
265266
labels: |
266267
name=${{ matrix.component.ecr_repository }}
267-
version=${{ matrix.component.image_tag_branch_name }}
268+
version=${{ matrix.component.image_tag_after_retag }}
268269
org.opencontainers.image.description=Image for ${{ matrix.component.ecr_repository }}
269270
org.opencontainers.image.source=${{ github.event.repository.html_url }}
270271
org.opencontainers.image.url=${{ github.event.repository.html_url }}
271272
org.opencontainers.image.title=${{ matrix.component.ecr_repository }}
272-
org.opencontainers.image.version=${{ matrix.component.image_tag_branch_name }}
273+
org.opencontainers.image.version=${{ matrix.component.image_tag_after_retag }}
273274
org.opencontainers.image.created=${{ matrix.component.build_time }}
274275
org.opencontainers.image.revision=${{ github.sha }}
275276
env:
@@ -427,15 +428,15 @@ jobs:
427428
run: |
428429
for component in $(jq -c '.components[]' <<< "$FLAVOR"); do
429430
repository_name=$(jq -r '.ecr_repository' <<< "$component")
430-
image_tag=$(jq -r '.image_tag' <<< "$component")
431-
image_tag_branch_name=$(jq -r '.image_tag_branch_name' <<< "$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")
432433
433-
echo "Processing repository: $repository_name, image_tag: $image_tag, 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-
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)')
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)')
436437
if [[ -z "${IMAGE_META}" || "${IMAGE_META}" == "null" ]]; then
437-
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')
438-
aws ecr put-image --repository-name "$repository_name" --image-tag "$image_tag_branch_name" --image-manifest "$MANIFEST"
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"
439440
else
440441
echo "Image already tagged for repository: $repository_name!"
441442
fi

0 commit comments

Comments
 (0)