44 workflow_dispatch :
55 inputs :
66 release_tag :
7- description : ' Release tag of the agent'
7+ description : " Release tag of the agent"
88 required : true
99 init_image_tag :
10- description : ' Image tag'
10+ description : " Image tag"
1111 required : true
1212 default : " 0"
1313 force :
14- description : ' Force build'
14+ description : " Force build"
1515 required : false
1616 default : " false"
1717
18-
19-
20- jobs :
18+ jobs :
2119 set_image_tag_variable :
2220 strategy :
2321 matrix :
24- agents : [
25- {name: "linux", file: "agent.zip", platform: "linux/amd64"},
26- {name: "alpine", file: "agent-alpine.zip", platform: "linux/amd64"},
27- {name: "linux-arm64", file: "agent-arm64.zip", platform: "linux/arm64"},
28- {name: "alpine-arm64", file: "agent-alpine-arm64.zip", platform: "linux/arm64"}
29- ]
22+ agents :
23+ [
24+ { name: "linux", file: "agent.zip", platform: "linux/amd64" },
25+ {
26+ name : " alpine" ,
27+ file : " agent-alpine.zip" ,
28+ platform : " linux/amd64" ,
29+ },
30+ {
31+ name : " linux-arm64" ,
32+ file : " agent-arm64.zip" ,
33+ platform : " linux/arm64" ,
34+ },
35+ {
36+ name : " alpine-arm64" ,
37+ file : " agent-alpine-arm64.zip" ,
38+ platform : " linux/arm64" ,
39+ },
40+ ]
3041 runs-on : ubuntu-latest
3142 name : Build and push Docker image
3243 steps :
33- - name : Set release tag
34- shell : bash
35- run : |
44+ - name : Set release tag
45+ shell : bash
46+ run : |
3647 # check that tag is matching regex x.y.x-release.<commit hash> or force flag is enabled
3748 if [[ ! ${{ inputs.release_tag }} =~ ^[0-9]+\.[0-9]+\.[0-9]+-release\.[0-9a-f]+$ ]] ; then
3849 echo "Tag ${{ inputs.release_tag }} is not matching regex x.y.x-release.<commithash>"
@@ -43,81 +54,78 @@ jobs:
4354 fi
4455 fi
4556 echo "TAG_NAME=$(echo ${{ inputs.release_tag }} | sed -E 's/^([0-9]*\.[0-9]*\.[0-9]*).*/\1/')-init.${{ inputs.init_image_tag }}" >> "$GITHUB_OUTPUT"
46- id : set_tag
57+ id : set_tag
4758
48- - uses : actions/checkout@v3
59+ - uses : actions/checkout@v4
4960
50- - name : Set up QEMU
51- uses : docker/setup-qemu-action@v3
52- - name : Set up Docker Buildx
53- uses : docker/setup-buildx-action@v3
61+ - name : Set up QEMU
62+ uses : docker/setup-qemu-action@v3
63+ - name : Set up Docker Buildx
64+ uses : docker/setup-buildx-action@v3
5465
55- - name : Login to DockerHub
56- if : ${{ success() }}
57- uses : docker/login-action@v2
58- with :
59- username : ${{ secrets.DOCKERHUB_USER }}
60- password : ${{ secrets.DOCKERHUB_PASS }}
61-
66+ - name : Login to DockerHub
67+ if : ${{ success() }}
68+ uses : docker/login-action@v2
69+ with :
70+ username : ${{ secrets.DOCKERHUB_USER }}
71+ password : ${{ secrets.DOCKERHUB_PASS }}
6272
63- - name : Configure AWS credentials for artifacts bucket
64- uses : aws-actions/configure-aws-credentials@v1
65- with :
66- aws-access-key-id : ${{ secrets.RELEASE_ARTIFACTS_MANAGER_KEY }}
67- aws-secret-access-key : ${{ secrets.RELEASE_ARTIFACTS_MANAGER_SECRET }}
68- aws-region : us-east-1
73+ - name : Configure AWS credentials for artifacts bucket
74+ uses : aws-actions/configure-aws-credentials@v1
75+ with :
76+ aws-access-key-id : ${{ secrets.RELEASE_ARTIFACTS_MANAGER_KEY }}
77+ aws-secret-access-key : ${{ secrets.RELEASE_ARTIFACTS_MANAGER_SECRET }}
78+ aws-region : us-east-1
6979
70- - name : Set docker image tags
71- id : set_docker_tags
72- run : |
73- python3 -m pip install semver
74- existing_tags=()
75- dockerhub_tags=$(curl -s "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}/tags?page_size=50" | jq -r ".results[].name")
76- if [[ $? -ne 0 ]] ; then
77- echo "Failed to fetch existing tags"
78- exit 1
79- fi
80- while IFS= read -r line; do
81- existing_tags+=("$line")
82- done < <(echo $dockerhub_tags)
83- for tag in $existing_tags
84- do
85- if [[ "$tag" == "latest" ]] ; then
86- continue
80+ - name : Set docker image tags
81+ id : set_docker_tags
82+ run : |
83+ python3 -m pip install semver
84+ existing_tags=()
85+ dockerhub_tags=$(curl -s "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}/tags?page_size=50" | jq -r ".results[].name")
86+ if [[ $? -ne 0 ]] ; then
87+ echo "Failed to fetch existing tags"
88+ exit 1
8789 fi
88- echo "Comparing existing tag: $tag with new: ${{steps.set_tag.outputs.TAG_NAME}}"
89- if [[ $(pysemver compare $tag ${{steps.set_tag.outputs.TAG_NAME}}) -ge 0 ]] ; then
90- echo "Existing tag: $tag is greater or equal than new: ${{ inputs.release_tag }}. Skip adding latest tag"
91- echo "DOCKER_TAGS=lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}:${{steps.set_tag.outputs.TAG_NAME}}" >> "$GITHUB_OUTPUT"
92- exit 0
93- fi
94- done
95- echo "Adding latest tag to ${{steps.set_tag.outputs.TAG_NAME}}"
96- echo "DOCKER_TAGS=lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}:${{steps.set_tag.outputs.TAG_NAME}},lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}:latest" >> "$GITHUB_OUTPUT"
97-
98- - name : Download agent artifacts
99- run : |
100- aws s3 cp s3://${{ secrets.RELEASE_ARTIFACTS_BUCKET }}/artifacts/${{ inputs.release_tag }}/${{ matrix.agents.file }} ./lightrun-init-agent/
101-
90+ while IFS= read -r line; do
91+ existing_tags+=("$line")
92+ done < <(echo $dockerhub_tags)
93+ for tag in $existing_tags
94+ do
95+ if [[ "$tag" == "latest" ]] ; then
96+ continue
97+ fi
98+ echo "Comparing existing tag: $tag with new: ${{steps.set_tag.outputs.TAG_NAME}}"
99+ if [[ $(pysemver compare $tag ${{steps.set_tag.outputs.TAG_NAME}}) -ge 0 ]] ; then
100+ echo "Existing tag: $tag is greater or equal than new: ${{ inputs.release_tag }}. Skip adding latest tag"
101+ echo "DOCKER_TAGS=lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}:${{steps.set_tag.outputs.TAG_NAME}}" >> "$GITHUB_OUTPUT"
102+ exit 0
103+ fi
104+ done
105+ echo "Adding latest tag to ${{steps.set_tag.outputs.TAG_NAME}}"
106+ echo "DOCKER_TAGS=lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}:${{steps.set_tag.outputs.TAG_NAME}},lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}:latest" >> "$GITHUB_OUTPUT"
102107
103- - name : Build and push ${{ matrix.agents.name }} container
104- uses : docker/build-push-action@v4
105- with :
106- context : .
107- file : ./lightrun-init-agent/Dockerfile
108- push : true
109- platforms : ${{ matrix.agents.platform }}
110- tags : ${{steps.set_docker_tags.outputs.DOCKER_TAGS}}
111- build-args : |
112- FILE=${{ matrix.agents.file }}
108+ - name : Download agent artifacts
109+ run : |
110+ aws s3 cp s3://${{ secrets.RELEASE_ARTIFACTS_BUCKET }}/artifacts/${{ inputs.release_tag }}/${{ matrix.agents.file }} ./lightrun-init-agent/
113111
112+ - name : Build and push ${{ matrix.agents.name }} container
113+ uses : docker/build-push-action@v4
114+ with :
115+ context : .
116+ file : ./lightrun-init-agent/Dockerfile
117+ push : true
118+ platforms : ${{ matrix.agents.platform }}
119+ tags : ${{steps.set_docker_tags.outputs.DOCKER_TAGS}}
120+ build-args : |
121+ FILE=${{ matrix.agents.file }}
114122
115- - name : Slack Notification
116- if : always()
117- uses : rtCamp/action-slack-notify@v2.2.0
118- env :
119- SLACK_CHANNEL : devops-alerts
120- SLACK_COLOR : ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
121- SLACK_MESSAGE : " Tag ${{ inputs.release_tag }} | Platform ${{ matrix.agents.name }}"
122- SLACK_TITLE : Init contianer build status - ${{ job.status }}
123- SLACK_WEBHOOK : ${{ secrets.SLACK_WEBHOOK }}
123+ - name : Slack Notification
124+ if : always()
125+ uses : rtCamp/action-slack-notify@v2.2.0
126+ env :
127+ SLACK_CHANNEL : devops-alerts
128+ SLACK_COLOR : ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
129+ SLACK_MESSAGE : " Tag ${{ inputs.release_tag }} | Platform ${{ matrix.agents.name }}"
130+ SLACK_TITLE : Init contianer build status - ${{ job.status }}
131+ SLACK_WEBHOOK : ${{ secrets.SLACK_WEBHOOK }}
0 commit comments