2727 - name : Set release tag
2828 shell : bash
2929 run : |
30- echo "::set-output name= TAG_NAME:: $(echo ${{ inputs.release_tag }} | sed -E 's/^([0-9]*\.[0-9]*\.[0-9]*).*/\1/')-init.${{ inputs.init_image_tag }}"
30+ echo "TAG_NAME= $(echo ${{ inputs.release_tag }} | sed -E 's/^([0-9]*\.[0-9]*\.[0-9]*).*/\1/')-init.${{ inputs.init_image_tag }}" >> "$GITHUB_OUTPUT "
3131 id : set_tag
3232
3333 - uses : actions/checkout@v3
@@ -48,18 +48,46 @@ jobs:
4848 aws-secret-access-key : ${{ secrets.RELEASE_ARTIFACTS_MANAGER_SECRET }}
4949 aws-region : us-east-1
5050
51+ - name : Set docker image tags
52+ id : set_docker_tags
53+ run : |
54+ python3 -m pip install semver
55+ existing_tags=()
56+ dockerhub_tags=$(curl -s "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.platform }}/tags?page_size=50" | jq -r ".results[].name")
57+ if [[ $? -ne 0 ]] ; then
58+ echo "Failed to fetch existing tags"
59+ exit 1
60+ fi
61+ while IFS= read -r line; do
62+ existing_tags+=("$line")
63+ done < <(echo $dockerhub_tags)
64+ for tag in $existing_tags
65+ do
66+ if [[ "$tag" == "latest" ]] ; then
67+ continue
68+ fi
69+ echo "Comparing existing tag: $tag with new: ${{steps.set_tag.outputs.TAG_NAME}}"
70+ if [[ $(pysemver compare $tag ${{steps.set_tag.outputs.TAG_NAME}}) -ge 0 ]] ; then
71+ echo "Existing tag: $tag is greater or equal than new: ${{ inputs.release_tag }}. Skip adding latest tag"
72+ echo "DOCKER_TAGS=lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.platform }}:${{steps.set_tag.outputs.TAG_NAME}}" >> "$GITHUB_OUTPUT"
73+ exit 0
74+ fi
75+ done
76+ echo "Adding latest tag to ${{steps.set_tag.outputs.TAG_NAME}}"
77+ echo "DOCKER_TAGS=lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.platform }}:${{steps.set_tag.outputs.TAG_NAME}},lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.platform }}:latest" >> "$GITHUB_OUTPUT"
78+
5179 - name : Download agent artifacts
5280 run : |
5381 aws s3 cp s3://${{ secrets.RELEASE_ARTIFACTS_BUCKET }}/artifacts/${{ inputs.release_tag }}/${{ matrix.agents.file }} ./lightrun-init-agent/
5482
5583
5684 - name : Build and push ${{ matrix.agents.platform }} container
57- uses : docker/build-push-action@v3
85+ uses : docker/build-push-action@v4
5886 with :
5987 context : .
6088 file : ./lightrun-init-agent/Dockerfile
6189 push : true
62- tags : " lightruncom/k8s-operator-init-java-agent- ${{ matrix.agents.platform }}:${{ steps.set_tag .outputs.TAG_NAME}} "
90+ tags : ${{steps.set_docker_tags .outputs.DOCKER_TAGS}}
6391 build-args : |
6492 FILE=${{ matrix.agents.file }}
6593
7098 env :
7199 SLACK_CHANNEL : devops-alerts
72100 SLACK_COLOR : ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
73- SLACK_MESSAGE : ' Tag ${{ inputs.release_tag }} | Platform ${{ matrix.agents.platform }}'
101+ SLACK_MESSAGE : " Tag ${{ inputs.release_tag }} | Platform ${{ matrix.agents.platform }}"
74102 SLACK_TITLE : Init contianer build status - ${{ job.status }}
75103 SLACK_WEBHOOK : ${{ secrets.SLACK_WEBHOOK }}
0 commit comments