Skip to content

Commit c45e575

Browse files
authored
ci: docker image tag latest only on stable release (databendlabs#14266)
1 parent d3e9648 commit c45e575

1 file changed

Lines changed: 53 additions & 32 deletions

File tree

.github/workflows/release.yml

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
GH_TOKEN: ${{ secrets.DATABEND_BOT_TOKEN }}
105105
run: |
106106
echo "Creating release ${{ steps.bump.outputs.tag }} from ${{ steps.bump.outputs.sha }}"
107-
if [ "${{ inputs.stable }}" == "true" ]; then
107+
if [[ "${{ inputs.stable }}" == "true" ]]; then
108108
echo "Stable release"
109109
previous=$(gh release list --limit 1 --exclude-pre-releases | cut -f 1)
110110
gh release create ${{ steps.bump.outputs.tag }} --target ${{ steps.bump.outputs.sha }} --generate-notes --notes-start-tag $previous --latest
@@ -241,9 +241,6 @@ jobs:
241241
with:
242242
fetch-depth: 0
243243
ref: ${{ needs.create_release.outputs.version }}
244-
- name: Get the version
245-
id: get_version
246-
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
247244
- name: Get target
248245
id: target
249246
run: echo 'target=${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}' >> $GITHUB_OUTPUT
@@ -332,9 +329,6 @@ jobs:
332329
with:
333330
fetch-depth: 0
334331
ref: ${{ needs.create_release.outputs.version }}
335-
- name: Get the version
336-
id: get_version
337-
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
338332
- name: Get target
339333
id: target
340334
run: echo 'target=${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}' >> $GITHUB_OUTPUT
@@ -393,9 +387,6 @@ jobs:
393387
uses: actions/checkout@v4
394388
with:
395389
ref: ${{ needs.create_release.outputs.version }}
396-
- name: Get the version
397-
id: get_version
398-
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
399390
- name: Download binaries for usage
400391
id: download_binaries
401392
env:
@@ -421,16 +412,35 @@ jobs:
421412
ecr_role_arn: ${{ secrets.ECR_ROLE_ARN }}
422413
dockerhub_user: ${{ secrets.DOCKERHUB_USERNAME }}
423414
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
415+
- name: Get Image Tags
416+
id: tags
417+
uses: actions/github-script@v7
418+
env:
419+
REPO_DOCKERHUB: ${{ steps.login.outputs.dockerhub_repo }}
420+
REPO_ECR: ${{ steps.login.outputs.ecr_repo }}
421+
VERSION: ${{ needs.create_release.outputs.version }}
422+
STABLE: ${{ inputs.stable }}
423+
with:
424+
script: |
425+
const version = process.env.VERSION;
426+
const repos = [process.env.REPO_DOCKERHUB, process.env.REPO_ECR];
427+
const stable = process.env.STABLE;
428+
let tags = [];
429+
for (const repo of repos) {
430+
tags.push(`${repo}:${version}`);
431+
if (stable === 'true') {
432+
tags.push(`${repo}:latest`);
433+
} else {
434+
tags.push(`${repo}:nightly`);
435+
}
436+
}
437+
core.setOutput('tags', tags.join(','));
424438
- name: Build and push
425439
id: docker_build
426440
uses: docker/build-push-action@v3
427441
with:
428442
push: true
429-
tags: |
430-
${{ steps.login.outputs.dockerhub_repo }}:latest
431-
${{ steps.login.outputs.dockerhub_repo }}:${{ needs.create_release.outputs.version }}
432-
${{ steps.login.outputs.ecr_repo }}:latest
433-
${{ steps.login.outputs.ecr_repo }}:${{ needs.create_release.outputs.version }}
443+
tags: ${{ steps.tags.outputs.tags }}
434444
platforms: linux/amd64,linux/arm64
435445
context: .
436446
file: ./docker/Dockerfile
@@ -462,9 +472,6 @@ jobs:
462472
uses: actions/checkout@v4
463473
with:
464474
ref: ${{ needs.create_release.outputs.version }}
465-
- name: Get the version
466-
id: get_version
467-
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
468475
- name: Download binaries for usage
469476
id: download_binaries
470477
env:
@@ -490,24 +497,38 @@ jobs:
490497
ecr_role_arn: ${{ secrets.ECR_ROLE_ARN }}
491498
dockerhub_user: ${{ secrets.DOCKERHUB_USERNAME }}
492499
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
493-
- name: get image tags
494-
id: get_image_tags
495-
shell: bash
496-
run: |
497-
_tags="${{ steps.login.outputs.dockerhub_repo }}:${{ needs.create_release.outputs.version }}-${{ matrix.distro }}"
498-
_tags="${_tags},${{ steps.login.outputs.ecr_repo }}:${{ needs.create_release.outputs.version }}-${{ matrix.distro }}"
499-
if [[ "${{ matrix.distro }}" == "debian" ]]; then
500-
_tags="${_tags},${{ steps.login.outputs.dockerhub_repo }}:${{ needs.create_release.outputs.version }}"
501-
_tags="${_tags},${{ steps.login.outputs.ecr_repo }}:${{ needs.create_release.outputs.version }}"
502-
_tags="${_tags},${{ steps.login.outputs.dockerhub_repo }}:latest"
503-
_tags="${_tags},${{ steps.login.outputs.ecr_repo }}:latest"
504-
fi
505-
echo "IMAGE_TAGS=${_tags}" >> $GITHUB_OUTPUT
500+
- name: Get Image Tags
501+
id: tags
502+
uses: actions/github-script@v7
503+
env:
504+
DISTRO: ${{ matrix.distro }}
505+
REPO_DOCKERHUB: ${{ steps.login.outputs.dockerhub_repo }}
506+
REPO_ECR: ${{ steps.login.outputs.ecr_repo }}
507+
VERSION: ${{ needs.create_release.outputs.version }}
508+
STABLE: ${{ inputs.stable }}
509+
with:
510+
script: |
511+
const version = process.env.VERSION;
512+
const distro = process.env.DISTRO;
513+
const repos = [process.env.REPO_DOCKERHUB, process.env.REPO_ECR];
514+
const stable = process.env.STABLE;
515+
let tags = [];
516+
for (const repo of repos) {
517+
tags.push(`${repo}:${version}-${distro}`);
518+
if (distro === 'debian') {
519+
tags.push(`${repo}:${version}`);
520+
if (stable === 'true') {
521+
tags.push(`${repo}:latest`);
522+
} else {
523+
tags.push(`${repo}:nightly`);
524+
}
525+
}
526+
}
506527
- name: push service image
507528
uses: docker/build-push-action@v3
508529
with:
509530
push: true
510-
tags: ${{ steps.get_image_tags.outputs.IMAGE_TAGS }}
531+
tags: ${{ steps.tags.outputs.tags }}
511532
platforms: linux/amd64,linux/arm64
512533
context: .
513534
file: ./docker/${{ matrix.distro }}/${{ matrix.service }}.Dockerfile

0 commit comments

Comments
 (0)