From b303423c0042e320e9d314792a19566e991f0699 Mon Sep 17 00:00:00 2001 From: Moshiko Date: Sun, 23 Feb 2025 18:38:19 +0200 Subject: [PATCH 1/6] DEVOPS-2538 add is_internal to init container workflow --- .github/workflows/init_container.yaml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/init_container.yaml b/.github/workflows/init_container.yaml index cf79e92..7b7e226 100644 --- a/.github/workflows/init_container.yaml +++ b/.github/workflows/init_container.yaml @@ -14,6 +14,10 @@ on: description: "Force build" required: false default: "false" + is_internal: + description: "Internal release" + required: false + default: "true" jobs: set_image_tag_variable: @@ -82,7 +86,17 @@ jobs: run: | python3 -m pip install semver existing_tags=() - 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") + + # Set repository suffix based on is_internal input + repo_suffix="" + if [[ "${{ inputs.is_internal }}" == "true" ]] ; then + repo_suffix="-internal" + fi + + # Define the base repository name + DOCKER_REPO="lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}" + + dockerhub_tags=$(curl -s "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}/tags?page_size=50" | jq -r ".results[].name") if [[ $? -ne 0 ]] ; then echo "Failed to fetch existing tags" exit 1 @@ -98,12 +112,12 @@ jobs: echo "Comparing existing tag: $tag with new: ${{steps.set_tag.outputs.TAG_NAME}}" if [[ $(pysemver compare $tag ${{steps.set_tag.outputs.TAG_NAME}}) -ge 0 ]] ; then echo "Existing tag: $tag is greater or equal than new: ${{ inputs.release_tag }}. Skip adding latest tag" - echo "DOCKER_TAGS=lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}:${{steps.set_tag.outputs.TAG_NAME}}" >> "$GITHUB_OUTPUT" + echo "DOCKER_TAGS=${DOCKER_REPO}:${{steps.set_tag.outputs.TAG_NAME}}" >> "$GITHUB_OUTPUT" exit 0 fi done echo "Adding latest tag to ${{steps.set_tag.outputs.TAG_NAME}}" - 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" + echo "DOCKER_TAGS=${DOCKER_REPO}:${{steps.set_tag.outputs.TAG_NAME}},${DOCKER_REPO}:latest" >> "$GITHUB_OUTPUT" - name: Download agent artifacts run: | From b6c2132ba7d1c1cbda47bd1eb6c6a49b34e337ae Mon Sep 17 00:00:00 2001 From: Moshiko Date: Sun, 23 Feb 2025 20:52:41 +0200 Subject: [PATCH 2/6] add credentials to init_container.yaml rest requests --- .github/workflows/init_container.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/init_container.yaml b/.github/workflows/init_container.yaml index 7b7e226..64a06fe 100644 --- a/.github/workflows/init_container.yaml +++ b/.github/workflows/init_container.yaml @@ -96,7 +96,16 @@ jobs: # Define the base repository name DOCKER_REPO="lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}" - dockerhub_tags=$(curl -s "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}/tags?page_size=50" | jq -r ".results[].name") + # Check if repository exists + repo_check=$(curl -s -f -u "${{ secrets.DOCKERHUB_USER }}:${{ secrets.DOCKERHUB_PASS }}" \ + "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}") + if [[ $? -ne 0 ]] ; then + echo "Error: Repository ${DOCKER_REPO} does not exist in Docker Hub. Please create it first." + exit 1 + fi + + dockerhub_tags=$(curl -s -u "${{ secrets.DOCKERHUB_USER }}:${{ secrets.DOCKERHUB_PASS }}" \ + "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}/tags?page_size=50" | jq -r ".results[].name") if [[ $? -ne 0 ]] ; then echo "Failed to fetch existing tags" exit 1 From bf4880c46e5d0b3cb29b8a4844052a140c04bc5e Mon Sep 17 00:00:00 2001 From: Moshiko Date: Sun, 23 Feb 2025 21:08:47 +0200 Subject: [PATCH 3/6] DEBUG only linux arm --- .github/workflows/init_container.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/init_container.yaml b/.github/workflows/init_container.yaml index 64a06fe..6291a07 100644 --- a/.github/workflows/init_container.yaml +++ b/.github/workflows/init_container.yaml @@ -25,22 +25,22 @@ jobs: matrix: agents: [ - { name: "linux", file: "agent.zip", platform: "linux/amd64" }, - { - name: "alpine", - file: "agent-alpine.zip", - platform: "linux/amd64", - }, + # { name: "linux", file: "agent.zip", platform: "linux/amd64" }, + # { + # name: "alpine", + # file: "agent-alpine.zip", + # platform: "linux/amd64", + # }, { name: "linux-arm64", file: "agent-arm64.zip", platform: "linux/arm64", }, - { - name: "alpine-arm64", - file: "agent-alpine-arm64.zip", - platform: "linux/arm64", - }, + # { + # name: "alpine-arm64", + # file: "agent-alpine-arm64.zip", + # platform: "linux/arm64", + # }, ] runs-on: ubuntu-latest name: Build and push Docker image From 1d3b3bf6e788b2ce3790f48750fd3d415c240e84 Mon Sep 17 00:00:00 2001 From: Moshiko Date: Sun, 23 Feb 2025 21:24:25 +0200 Subject: [PATCH 4/6] fix auth to dockerhub --- .github/workflows/init_container.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/init_container.yaml b/.github/workflows/init_container.yaml index 6291a07..666d3df 100644 --- a/.github/workflows/init_container.yaml +++ b/.github/workflows/init_container.yaml @@ -96,15 +96,25 @@ jobs: # Define the base repository name DOCKER_REPO="lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}" + # Get Docker Hub JWT token + TOKEN=$(curl -s -H "Content-Type: application/json" \ + -X POST -d '{"username": "${{ secrets.DOCKERHUB_USER }}", "password": "${{ secrets.DOCKERHUB_PASS }}"}' \ + "https://hub.docker.com/v2/users/login/" | jq -r .token) + + if [[ -z "$TOKEN" ]] ; then + echo "Failed to get Docker Hub authentication token" + exit 1 + fi + # Check if repository exists - repo_check=$(curl -s -f -u "${{ secrets.DOCKERHUB_USER }}:${{ secrets.DOCKERHUB_PASS }}" \ + repo_check=$(curl -s -f -H "Authorization: Bearer ${TOKEN}" \ "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}") if [[ $? -ne 0 ]] ; then echo "Error: Repository ${DOCKER_REPO} does not exist in Docker Hub. Please create it first." exit 1 fi - dockerhub_tags=$(curl -s -u "${{ secrets.DOCKERHUB_USER }}:${{ secrets.DOCKERHUB_PASS }}" \ + dockerhub_tags=$(curl -s -H "Authorization: Bearer ${TOKEN}" \ "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}/tags?page_size=50" | jq -r ".results[].name") if [[ $? -ne 0 ]] ; then echo "Failed to fetch existing tags" From ec97e60ab7c5c1253bbbb2e96db38c4726746eea Mon Sep 17 00:00:00 2001 From: Moshiko Date: Sun, 23 Feb 2025 21:27:03 +0200 Subject: [PATCH 5/6] revert debug --- .github/workflows/init_container.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/init_container.yaml b/.github/workflows/init_container.yaml index 666d3df..1e693c3 100644 --- a/.github/workflows/init_container.yaml +++ b/.github/workflows/init_container.yaml @@ -25,22 +25,22 @@ jobs: matrix: agents: [ - # { name: "linux", file: "agent.zip", platform: "linux/amd64" }, - # { - # name: "alpine", - # file: "agent-alpine.zip", - # platform: "linux/amd64", - # }, + { name: "linux", file: "agent.zip", platform: "linux/amd64" }, + { + name: "alpine", + file: "agent-alpine.zip", + platform: "linux/amd64", + }, { name: "linux-arm64", file: "agent-arm64.zip", platform: "linux/arm64", }, - # { - # name: "alpine-arm64", - # file: "agent-alpine-arm64.zip", - # platform: "linux/arm64", - # }, + { + name: "alpine-arm64", + file: "agent-alpine-arm64.zip", + platform: "linux/arm64", + }, ] runs-on: ubuntu-latest name: Build and push Docker image From f1fa08240073069c81ee21d9ac06587b32ffbebc Mon Sep 17 00:00:00 2001 From: Moshiko Date: Sun, 23 Feb 2025 21:33:49 +0200 Subject: [PATCH 6/6] add internal to slack notification if needed --- .github/workflows/init_container.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/init_container.yaml b/.github/workflows/init_container.yaml index 1e693c3..adf6548 100644 --- a/.github/workflows/init_container.yaml +++ b/.github/workflows/init_container.yaml @@ -93,8 +93,6 @@ jobs: repo_suffix="-internal" fi - # Define the base repository name - DOCKER_REPO="lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}" # Get Docker Hub JWT token TOKEN=$(curl -s -H "Content-Type: application/json" \ @@ -106,6 +104,9 @@ jobs: exit 1 fi + # Define the base repository name + DOCKER_REPO="lightruncom/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}" + # Check if repository exists repo_check=$(curl -s -f -H "Authorization: Bearer ${TOKEN}" \ "https://hub.docker.com/v2/namespaces/lightruncom/repositories/k8s-operator-init-java-agent-${{ matrix.agents.name }}${repo_suffix}") @@ -158,7 +159,7 @@ jobs: uses: rtCamp/action-slack-notify@v2.2.0 env: SLACK_CHANNEL: devops-alerts - SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff' - SLACK_MESSAGE: "Tag ${{ inputs.release_tag }} | Platform ${{ matrix.agents.name }}" - SLACK_TITLE: Init contianer build status - ${{ job.status }} + SLACK_COLOR: ${{ job.status }} + SLACK_MESSAGE: "Tag ${{ inputs.release_tag }} ${{ inputs.is_internal == 'true' && '(Internal)' || '' }} | Platform ${{ matrix.agents.name }}" + SLACK_TITLE: Init container ${{ inputs.is_internal == 'true' && '(Internal)' || '' }} build status - ${{ job.status }} SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}