27
27
- name : Set release tag
28
28
shell : bash
29
29
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 "
31
31
id : set_tag
32
32
33
33
- uses : actions/checkout@v3
@@ -48,18 +48,46 @@ jobs:
48
48
aws-secret-access-key : ${{ secrets.RELEASE_ARTIFACTS_MANAGER_SECRET }}
49
49
aws-region : us-east-1
50
50
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
+
51
79
- name : Download agent artifacts
52
80
run : |
53
81
aws s3 cp s3://${{ secrets.RELEASE_ARTIFACTS_BUCKET }}/artifacts/${{ inputs.release_tag }}/${{ matrix.agents.file }} ./lightrun-init-agent/
54
82
55
83
56
84
- name : Build and push ${{ matrix.agents.platform }} container
57
- uses : docker/build-push-action@v3
85
+ uses : docker/build-push-action@v4
58
86
with :
59
87
context : .
60
88
file : ./lightrun-init-agent/Dockerfile
61
89
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}}
63
91
build-args : |
64
92
FILE=${{ matrix.agents.file }}
65
93
70
98
env :
71
99
SLACK_CHANNEL : devops-alerts
72
100
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 }}"
74
102
SLACK_TITLE : Init contianer build status - ${{ job.status }}
75
103
SLACK_WEBHOOK : ${{ secrets.SLACK_WEBHOOK }}
0 commit comments