From 6294795afe8560058c251567cb907a1471be6061 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 14:52:16 +1000 Subject: [PATCH 01/27] Add new versions.json and update build and release workflow to use it --- .../build-and-publish-container-image.yml | 107 ++++++++++++------ versions.json | 18 +++ 2 files changed, 88 insertions(+), 37 deletions(-) create mode 100644 versions.json diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 67eb8a2..d3a03d6 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -1,40 +1,65 @@ name: Build and Push Container Image -run-name: "Build and Push Image: Kubectl ${{ inputs.kubectl-version }}, Helm ${{ inputs.helm-version }}, Powershell ${{ inputs.powershell-version }}" on: - workflow_dispatch: - inputs: - kubectl-version: - required: true - type: string - default: "1.30.5" - helm-version: - required: true - type: string - default: "3.16.1" - powershell-version: - required: true - type: string - default: "7.4.5" - tag-as-latest: - description: "(Main only) Tag the image as latest - kubectl 1.30.x only" - required: true - type: boolean - default: false + pull_request: + paths: + - versions.json + push: + branches: + - main + paths: + - versions.json jobs: + versions: + runs-on: ubuntu-latest + + outputs: + kubectlVersions: ${{ steps.versions.outputs.kubectl }} + helmVersions: ${{ steps.versions.outputs.helm }} + powershellVersions: ${{ steps.versions.outputs.powershell }} + latestVersion: ${{ steps.versions.outputs.latest }} + revision: ${{ steps.versions.outputs.revision}} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: "Parse versions.json" + id: versions + run: | + kubectlVersions=$(jq -r -c .tools.kubectl versions.json) + helmVersions=$(jq -r -c .tools.helm versions.json) + powershellVersions=$(jq -r -c .tools.powershell versions.json) + latestVersion=$(jq -r -c .latest versions.json) + revision=$(jq -r -c .revision versions.json) + + echo 'kubectl=$kubectlVersions' >> "$GITHUB_OUTPUT" + echo 'helm=$helmVersions' >> "$GITHUB_OUTPUT" + echo 'powershell=$powershellVersions' >> "$GITHUB_OUTPUT" + echo 'latest=$latestVersion' >> "$GITHUB_OUTPUT" + echo 'revision=$revision' >> "$GITHUB_OUTPUT" + build: runs-on: ubuntu-latest + needs: versions + strategy: + matrix: + kubectlVersion: ${{ fromJson(needs.versions.outputs.kubectlVersions)}} + helmVersion: ${{ fromJson(needs.versions.outputs.helmVersions)}} + powershellVersion: ${{ fromJson(needs.versions.outputs.powershellVersions)}} steps: - name: Log Inputs run: | - echo "Kubectl Version: ${{ inputs.kubectl-version }}" - echo "Helm Version: ${{ inputs.helm-version }}" + echo "Kubectl Version: ${{ matrix.kubectlVersion }}" + echo "Helm Version: ${{ matrix.helmVersion }}" + echo "Powershell Version: ${{matrix.powershellVersion}}" - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 - name: Get branch names id: branch_names @@ -60,36 +85,45 @@ jobs: - name: Create Tag Version run: | - fullVersion="${{ inputs.kubectl-version }}" + kubernetesVersion="${{ matrix.kubectlVersion }}" if [[ "${{steps.branch_names.outputs.branch_name}}" != "main" ]] then preRelease="-${{steps.branch_names.outputs.branch_name}}-$(date +'%Y%m%d%H%M%S')" fi - tagVersion="${fullVersion%'.'*}$preRelease"; + revision="-${{ needs.versions.outputs.revision }}" + + tagVersion="${kubernetesVersion%'.'*}$revision$preRelease"; echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; echo "tagVersion=$tagVersion"; + + allVersionsTag="${{ matrix.kubectlVersion}}-${{ matrix.helmVersion}}-${{matrix.powershellVersion}}$revision" + echo "allVersionsTag=$allVersionsTag" >> $GITHUB_OUTPUT; + echo "allVersionsTag=$allVersionsTag"; + id: createTagVersion - + - name: Build and push for test if: ${{ github.ref != 'refs/heads/main' }} uses: docker/build-push-action@v5 with: push: true - tags: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }}" + tags: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" platforms: linux/amd64,linux/arm64 build-args: | - "KUBECTL_VERSION=${{ inputs.kubectl-version }}" - "HELM_VERSION=${{ inputs.helm-version }}" - "POWERSHELL_VERSION=${{ inputs.powershell-version }}" + "KUBECTL_VERSION=${{ matrix.kubectlVersion }}" + "HELM_VERSION=${{ matrix.helmVersion }}" + "POWERSHELL_VERSION=${{ matrix.powershellVersion }}" - name: Create production docker tags if: ${{ github.ref == 'refs/heads/main' }} run: | - artifactoryTags="${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }}" - dockerhubTags="octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }}" + artifactoryTags="${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" + dockerhubTags="octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" + - if [[ "${{ inputs.tag-as-latest }}" == "true" ]] + kubernetesVersion="${{ matrix.kubectlVersion }}" + if [[ "${{ needs.versions.outputs.latestVersion }}" == "${kubernetesVersion%'.'*}" ]] then artifactoryTags="$artifactoryTags,${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:latest" dockerhubTags="$dockerhubTags,octopusdeploy/kubernetes-agent-tools-base:latest" @@ -100,7 +134,6 @@ jobs: echo "dockerTags=$dockerTags"; id: createProductionDockerTags - - name: Build and push for production if: ${{ github.ref == 'refs/heads/main' }} uses: docker/build-push-action@v5 @@ -109,6 +142,6 @@ jobs: tags: ${{ steps.createProductionDockerTags.outputs.dockerTags }} platforms: linux/amd64,linux/arm64 build-args: | - "KUBECTL_VERSION=${{ inputs.kubectl-version }}" - "HELM_VERSION=${{ inputs.helm-version }}" - "POWERSHELL_VERSION=${{ inputs.powershell-version }}" + "KUBECTL_VERSION=${{ matrix.kubectlVersion }}" + "HELM_VERSION=${{ matrix.helmVersion }}" + "POWERSHELL_VERSION=${{ matrix.powershellVersion }}" diff --git a/versions.json b/versions.json new file mode 100644 index 0000000..21736b0 --- /dev/null +++ b/versions.json @@ -0,0 +1,18 @@ +{ + "tools": { + "kubectl": [ + "1.31.1", + "1.30.5", + "1.29.9", + "1.28.14" + ], + "helm": [ + "3.16.1" + ], + "powershell": [ + "7.4.5" + ] + }, + "latest": "1.30", + "revision": 1 +} \ No newline at end of file From c15ecf1fac100d6977f01a4c474e6b2173366636 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:02:26 +1000 Subject: [PATCH 02/27] Debug logging --- .../build-and-publish-container-image.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index d3a03d6..bd1e717 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -36,19 +36,28 @@ jobs: revision=$(jq -r -c .revision versions.json) echo 'kubectl=$kubectlVersions' >> "$GITHUB_OUTPUT" + echo "kubectl=$kubectlVersions" + echo 'helm=$helmVersions' >> "$GITHUB_OUTPUT" + echo "helm=$helmVersions" + echo 'powershell=$powershellVersions' >> "$GITHUB_OUTPUT" + echo "powershell=$powershellVersions" + echo 'latest=$latestVersion' >> "$GITHUB_OUTPUT" + echo "latest=$latestVersion" + echo 'revision=$revision' >> "$GITHUB_OUTPUT" + echo "revision=$revision" build: runs-on: ubuntu-latest needs: versions strategy: matrix: - kubectlVersion: ${{ fromJson(needs.versions.outputs.kubectlVersions)}} - helmVersion: ${{ fromJson(needs.versions.outputs.helmVersions)}} - powershellVersion: ${{ fromJson(needs.versions.outputs.powershellVersions)}} + kubectlVersion: ${{ fromJson(needs.versions.outputs.kubectlVersions) }} + helmVersion: ${{ fromJson(needs.versions.outputs.helmVersions) }} + powershellVersion: ${{ fromJson(needs.versions.outputs.powershellVersions) }} steps: - name: Log Inputs From 3089173e91c3a484415ed23f6384716bd54ca624 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:18:06 +1000 Subject: [PATCH 03/27] Correct function name --- .github/workflows/build-and-publish-container-image.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index bd1e717..7de5b55 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -55,9 +55,9 @@ jobs: needs: versions strategy: matrix: - kubectlVersion: ${{ fromJson(needs.versions.outputs.kubectlVersions) }} - helmVersion: ${{ fromJson(needs.versions.outputs.helmVersions) }} - powershellVersion: ${{ fromJson(needs.versions.outputs.powershellVersions) }} + kubectlVersion: ${{ fromJSON(needs.versions.outputs.kubectlVersions) }} + helmVersion: ${{ fromJSON(needs.versions.outputs.helmVersions) }} + powershellVersion: ${{ fromJSON(needs.versions.outputs.powershellVersions) }} steps: - name: Log Inputs From 86812ad33cb8cdc34ddd4371e35db51bc9db1817 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:22:41 +1000 Subject: [PATCH 04/27] Change to pass matrix json --- .../build-and-publish-container-image.yml | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 7de5b55..620e16c 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -15,9 +15,7 @@ jobs: runs-on: ubuntu-latest outputs: - kubectlVersions: ${{ steps.versions.outputs.kubectl }} - helmVersions: ${{ steps.versions.outputs.helm }} - powershellVersions: ${{ steps.versions.outputs.powershell }} + toolsVersions: ${{ steps.versions.outputs.tools }} latestVersion: ${{ steps.versions.outputs.latest }} revision: ${{ steps.versions.outputs.revision}} @@ -29,20 +27,12 @@ jobs: - name: "Parse versions.json" id: versions run: | - kubectlVersions=$(jq -r -c .tools.kubectl versions.json) - helmVersions=$(jq -r -c .tools.helm versions.json) - powershellVersions=$(jq -r -c .tools.powershell versions.json) + toolsVersions=$(jq -r -c .tools versions.json) latestVersion=$(jq -r -c .latest versions.json) revision=$(jq -r -c .revision versions.json) - echo 'kubectl=$kubectlVersions' >> "$GITHUB_OUTPUT" - echo "kubectl=$kubectlVersions" - - echo 'helm=$helmVersions' >> "$GITHUB_OUTPUT" - echo "helm=$helmVersions" - - echo 'powershell=$powershellVersions' >> "$GITHUB_OUTPUT" - echo "powershell=$powershellVersions" + echo 'tools=$toolsVersions' >> "$GITHUB_OUTPUT" + echo "tools=$toolsVersions" echo 'latest=$latestVersion' >> "$GITHUB_OUTPUT" echo "latest=$latestVersion" @@ -54,17 +44,14 @@ jobs: runs-on: ubuntu-latest needs: versions strategy: - matrix: - kubectlVersion: ${{ fromJSON(needs.versions.outputs.kubectlVersions) }} - helmVersion: ${{ fromJSON(needs.versions.outputs.helmVersions) }} - powershellVersion: ${{ fromJSON(needs.versions.outputs.powershellVersions) }} + matrix: ${{ fromJSON(needs.versions.outputs.toolsVersions) }} steps: - name: Log Inputs run: | - echo "Kubectl Version: ${{ matrix.kubectlVersion }}" - echo "Helm Version: ${{ matrix.helmVersion }}" - echo "Powershell Version: ${{matrix.powershellVersion}}" + echo "Kubectl Version: ${{ matrix.kubectl }}" + echo "Helm Version: ${{ matrix.helm }}" + echo "Powershell Version: ${{ matrix.powershell }}" - uses: actions/checkout@v4 with: @@ -94,7 +81,7 @@ jobs: - name: Create Tag Version run: | - kubernetesVersion="${{ matrix.kubectlVersion }}" + kubernetesVersion="${{ matrix.kubectl }}" if [[ "${{steps.branch_names.outputs.branch_name}}" != "main" ]] then preRelease="-${{steps.branch_names.outputs.branch_name}}-$(date +'%Y%m%d%H%M%S')" @@ -106,7 +93,7 @@ jobs: echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; echo "tagVersion=$tagVersion"; - allVersionsTag="${{ matrix.kubectlVersion}}-${{ matrix.helmVersion}}-${{matrix.powershellVersion}}$revision" + allVersionsTag="${{ matrix.kubectl}}-${{ matrix.helm}}-${{matrix.powershell}}$revision" echo "allVersionsTag=$allVersionsTag" >> $GITHUB_OUTPUT; echo "allVersionsTag=$allVersionsTag"; @@ -120,9 +107,9 @@ jobs: tags: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" platforms: linux/amd64,linux/arm64 build-args: | - "KUBECTL_VERSION=${{ matrix.kubectlVersion }}" - "HELM_VERSION=${{ matrix.helmVersion }}" - "POWERSHELL_VERSION=${{ matrix.powershellVersion }}" + "KUBECTL_VERSION=${{ matrix.kubectl }}" + "HELM_VERSION=${{ matrix.helm }}" + "POWERSHELL_VERSION=${{ matrix.powershell }}" - name: Create production docker tags if: ${{ github.ref == 'refs/heads/main' }} @@ -131,7 +118,7 @@ jobs: dockerhubTags="octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" - kubernetesVersion="${{ matrix.kubectlVersion }}" + kubernetesVersion="${{ matrix.kubectl }}" if [[ "${{ needs.versions.outputs.latestVersion }}" == "${kubernetesVersion%'.'*}" ]] then artifactoryTags="$artifactoryTags,${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:latest" @@ -151,6 +138,6 @@ jobs: tags: ${{ steps.createProductionDockerTags.outputs.dockerTags }} platforms: linux/amd64,linux/arm64 build-args: | - "KUBECTL_VERSION=${{ matrix.kubectlVersion }}" - "HELM_VERSION=${{ matrix.helmVersion }}" - "POWERSHELL_VERSION=${{ matrix.powershellVersion }}" + "KUBECTL_VERSION=${{ matrix.kubectl }}" + "HELM_VERSION=${{ matrix.helm }}" + "POWERSHELL_VERSION=${{ matrix.powershell }}" From 5585b64698de1e559a61a7a36dbea30bf03d7d1a Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:25:55 +1000 Subject: [PATCH 05/27] Remove raw for tools object --- .github/workflows/build-and-publish-container-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 620e16c..9e0ae42 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -27,7 +27,7 @@ jobs: - name: "Parse versions.json" id: versions run: | - toolsVersions=$(jq -r -c .tools versions.json) + toolsVersions=$(jq -c .tools versions.json) latestVersion=$(jq -r -c .latest versions.json) revision=$(jq -r -c .revision versions.json) From aad779aae8686a35d2e1c7b3b94447c019aa038c Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:45:05 +1000 Subject: [PATCH 06/27] Escape tools json --- .github/workflows/build-and-publish-container-image.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 9e0ae42..2dddd17 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -31,6 +31,8 @@ jobs: latestVersion=$(jq -r -c .latest versions.json) revision=$(jq -r -c .revision versions.json) + toolsVersions=${toolsVersions//\"/\\\"} + echo 'tools=$toolsVersions' >> "$GITHUB_OUTPUT" echo "tools=$toolsVersions" From c31393bdc086e12560f6bd563d916cbfd3c0bcd8 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:50:29 +1000 Subject: [PATCH 07/27] Remove escaping --- .github/workflows/build-and-publish-container-image.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 2dddd17..9e0ae42 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -31,8 +31,6 @@ jobs: latestVersion=$(jq -r -c .latest versions.json) revision=$(jq -r -c .revision versions.json) - toolsVersions=${toolsVersions//\"/\\\"} - echo 'tools=$toolsVersions' >> "$GITHUB_OUTPUT" echo "tools=$toolsVersions" From 22ab6c804b6f3ca621b9bd91256fdd6dd05dd8ef Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:50:59 +1000 Subject: [PATCH 08/27] Fix quoting --- .github/workflows/build-and-publish-container-image.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 9e0ae42..7387d47 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -32,13 +32,13 @@ jobs: revision=$(jq -r -c .revision versions.json) echo 'tools=$toolsVersions' >> "$GITHUB_OUTPUT" - echo "tools=$toolsVersions" + echo 'tools=$toolsVersions' echo 'latest=$latestVersion' >> "$GITHUB_OUTPUT" - echo "latest=$latestVersion" + echo 'latest=$latestVersion' echo 'revision=$revision' >> "$GITHUB_OUTPUT" - echo "revision=$revision" + echo 'revision=$revision' build: runs-on: ubuntu-latest From f53e0731f536f7d8525d6fd9b964c876217640cf Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:56:32 +1000 Subject: [PATCH 09/27] confirmation step --- .github/workflows/build-and-publish-container-image.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 7387d47..2c30448 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -40,6 +40,12 @@ jobs: echo 'revision=$revision' >> "$GITHUB_OUTPUT" echo 'revision=$revision' + - name: "Confirm" + run: | + echo "${{ steps.versions.outputs.tools }}" + echo "${{ steps.versions.outputs.latest }}" + echo "${{ steps.versions.outputs.revision}}" + build: runs-on: ubuntu-latest needs: versions From 7c6b5defed58a15d1d933fdf14183fb24d1a53f4 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 15:58:47 +1000 Subject: [PATCH 10/27] Stop quoting the --- .github/workflows/build-and-publish-container-image.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 2c30448..315ef6f 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -31,13 +31,13 @@ jobs: latestVersion=$(jq -r -c .latest versions.json) revision=$(jq -r -c .revision versions.json) - echo 'tools=$toolsVersions' >> "$GITHUB_OUTPUT" + echo 'tools=$toolsVersions' >> $GITHUB_OUTPUT echo 'tools=$toolsVersions' - echo 'latest=$latestVersion' >> "$GITHUB_OUTPUT" + echo 'latest=$latestVersion' >> $GITHUB_OUTPUT echo 'latest=$latestVersion' - echo 'revision=$revision' >> "$GITHUB_OUTPUT" + echo 'revision=$revision' >> $GITHUB_OUTPUT echo 'revision=$revision' - name: "Confirm" From 30836e8da29988ac277a67971d796142e9985800 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 16:01:46 +1000 Subject: [PATCH 11/27] Use double quotes --- .../workflows/build-and-publish-container-image.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 315ef6f..d8b1879 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -31,14 +31,14 @@ jobs: latestVersion=$(jq -r -c .latest versions.json) revision=$(jq -r -c .revision versions.json) - echo 'tools=$toolsVersions' >> $GITHUB_OUTPUT - echo 'tools=$toolsVersions' + echo "tools=$toolsVersions" >> $GITHUB_OUTPUT + echo "tools=$toolsVersions" - echo 'latest=$latestVersion' >> $GITHUB_OUTPUT - echo 'latest=$latestVersion' + echo "latest=$latestVersion" >> $GITHUB_OUTPUT + echo "latest=$latestVersion" - echo 'revision=$revision' >> $GITHUB_OUTPUT - echo 'revision=$revision' + echo "revision=$revision" >> $GITHUB_OUTPUT + echo "revision=$revision" - name: "Confirm" run: | From 55caff1b3292b4354d530319a81ec75d824b6716 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 16:05:54 +1000 Subject: [PATCH 12/27] add r to revision number and fix all versions tag --- .../workflows/build-and-publish-container-image.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index d8b1879..8c1bec0 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -40,12 +40,6 @@ jobs: echo "revision=$revision" >> $GITHUB_OUTPUT echo "revision=$revision" - - name: "Confirm" - run: | - echo "${{ steps.versions.outputs.tools }}" - echo "${{ steps.versions.outputs.latest }}" - echo "${{ steps.versions.outputs.revision}}" - build: runs-on: ubuntu-latest needs: versions @@ -93,13 +87,13 @@ jobs: preRelease="-${{steps.branch_names.outputs.branch_name}}-$(date +'%Y%m%d%H%M%S')" fi - revision="-${{ needs.versions.outputs.revision }}" + revision="-r${{ needs.versions.outputs.revision }}" tagVersion="${kubernetesVersion%'.'*}$revision$preRelease"; echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; echo "tagVersion=$tagVersion"; - allVersionsTag="${{ matrix.kubectl}}-${{ matrix.helm}}-${{matrix.powershell}}$revision" + allVersionsTag="${{ matrix.kubectl}}-${{ matrix.helm}}-${{matrix.powershell}}$revision$preRelease" echo "allVersionsTag=$allVersionsTag" >> $GITHUB_OUTPUT; echo "allVersionsTag=$allVersionsTag"; From 1903f6a51185a8304300efbc56199d2a1d5bc1b1 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Mon, 30 Sep 2024 17:09:22 +1000 Subject: [PATCH 13/27] Add deprecations and add naming to all versions tag --- .github/workflows/build-and-publish-container-image.yml | 2 +- versions.json | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 8c1bec0..1a14afd 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -93,7 +93,7 @@ jobs: echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; echo "tagVersion=$tagVersion"; - allVersionsTag="${{ matrix.kubectl}}-${{ matrix.helm}}-${{matrix.powershell}}$revision$preRelease" + allVersionsTag="kube${{ matrix.kubectl}}-helm${{ matrix.helm}}-pwsh${{matrix.powershell}}$revision$preRelease" echo "allVersionsTag=$allVersionsTag" >> $GITHUB_OUTPUT; echo "allVersionsTag=$allVersionsTag"; diff --git a/versions.json b/versions.json index 21736b0..87c7e54 100644 --- a/versions.json +++ b/versions.json @@ -14,5 +14,9 @@ ] }, "latest": "1.30", - "revision": 1 + "revision": 1, + "deprecatedKubectlVersions": { + "1.26": "1.26", + "1.27": "1.27" + } } \ No newline at end of file From 09ed3cf107781a01b91a10921bcd3c270fbed96e Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 09:24:00 +1000 Subject: [PATCH 14/27] Clean up some logic for getting the k8s version --- .../workflows/build-and-publish-container-image.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 1a14afd..369c06a 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -79,9 +79,16 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Get Kubernetes Version + id: kubernetes-version + run: | + kubectlVersion="${{ matrix.kubectl }}" + echo "kubernetesVersion=${kubernetesVersion%'.'*}" >> $GITHUB_OUTPUT + - name: Create Tag Version run: | - kubernetesVersion="${{ matrix.kubectl }}" + kubernetesVersion="${{ steps.kubernetes-version.outputs.kubernetesVersion }}" + if [[ "${{steps.branch_names.outputs.branch_name}}" != "main" ]] then preRelease="-${{steps.branch_names.outputs.branch_name}}-$(date +'%Y%m%d%H%M%S')" @@ -89,7 +96,7 @@ jobs: revision="-r${{ needs.versions.outputs.revision }}" - tagVersion="${kubernetesVersion%'.'*}$revision$preRelease"; + tagVersion="$kubernetesVersion$revision$preRelease"; echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; echo "tagVersion=$tagVersion"; @@ -119,7 +126,7 @@ jobs: kubernetesVersion="${{ matrix.kubectl }}" - if [[ "${{ needs.versions.outputs.latestVersion }}" == "${kubernetesVersion%'.'*}" ]] + if [[ "${{ needs.versions.outputs.latestVersion }}" == "${{ steps.kubernetes-version.outputs.kubernetesVersion }}" ]] then artifactoryTags="$artifactoryTags,${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:latest" dockerhubTags="$dockerhubTags,octopusdeploy/kubernetes-agent-tools-base:latest" From 460f6b3780393b339ddfd321f448c07b39eacd1b Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 09:33:44 +1000 Subject: [PATCH 15/27] Use env vars for image paths --- .../build-and-publish-container-image.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 369c06a..432db50 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -46,6 +46,10 @@ jobs: strategy: matrix: ${{ fromJSON(needs.versions.outputs.toolsVersions) }} + env: + ArtifactoryImagePath: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base" + DockerHubImagePath: "octopusdeploy/kubernetes-agent-tools-base" + steps: - name: Log Inputs run: | @@ -111,7 +115,7 @@ jobs: uses: docker/build-push-action@v5 with: push: true - tags: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" + tags: "$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.tagVersion }},$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.allVersionsTag}}" platforms: linux/amd64,linux/arm64 build-args: | "KUBECTL_VERSION=${{ matrix.kubectl }}" @@ -121,15 +125,15 @@ jobs: - name: Create production docker tags if: ${{ github.ref == 'refs/heads/main' }} run: | - artifactoryTags="${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" - dockerhubTags="octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.tagVersion }},octopusdeploy/kubernetes-agent-tools-base:${{ steps.createTagVersion.outputs.allVersionsTag}}" + artifactoryTags="$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.tagVersion }},$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.allVersionsTag}}" + dockerhubTags="$DockerHubImagePath:${{ steps.createTagVersion.outputs.tagVersion }},$DockerHubImagePath:${{ steps.createTagVersion.outputs.allVersionsTag}}" kubernetesVersion="${{ matrix.kubectl }}" if [[ "${{ needs.versions.outputs.latestVersion }}" == "${{ steps.kubernetes-version.outputs.kubernetesVersion }}" ]] then - artifactoryTags="$artifactoryTags,${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base:latest" - dockerhubTags="$dockerhubTags,octopusdeploy/kubernetes-agent-tools-base:latest" + artifactoryTags="$artifactoryTags,$ArtifactoryImagePath:latest" + dockerhubTags="$dockerhubTags,$DockerHubImagePath:latest" fi dockerTags="$artifactoryTags,$dockerhubTags" From efb850089125b913d524a25c6f2e3dcdee80dd55 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 09:41:17 +1000 Subject: [PATCH 16/27] fix env vars --- .../build-and-publish-container-image.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 432db50..5dc9331 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -10,6 +10,10 @@ on: paths: - versions.json +env: + ArtifactoryImagePath: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base" + DockerHubImagePath: "octopusdeploy/kubernetes-agent-tools-base" + jobs: versions: runs-on: ubuntu-latest @@ -46,10 +50,6 @@ jobs: strategy: matrix: ${{ fromJSON(needs.versions.outputs.toolsVersions) }} - env: - ArtifactoryImagePath: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base" - DockerHubImagePath: "octopusdeploy/kubernetes-agent-tools-base" - steps: - name: Log Inputs run: | @@ -87,7 +87,9 @@ jobs: id: kubernetes-version run: | kubectlVersion="${{ matrix.kubectl }}" - echo "kubernetesVersion=${kubernetesVersion%'.'*}" >> $GITHUB_OUTPUT + kubeVersion="${kubernetesVersion%'.'*}" + echo "kubernetesVersion=$kubeVersion" >> $GITHUB_OUTPUT + echo "kubeVersion=$kubeVersion" - name: Create Tag Version run: | @@ -115,7 +117,7 @@ jobs: uses: docker/build-push-action@v5 with: push: true - tags: "$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.tagVersion }},$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.allVersionsTag}}" + tags: "${{ env.ArtifactoryImagePath }}:${{ steps.createTagVersion.outputs.tagVersion }},${{ env.ArtifactoryImagePath }}:${{ steps.createTagVersion.outputs.allVersionsTag}}" platforms: linux/amd64,linux/arm64 build-args: | "KUBECTL_VERSION=${{ matrix.kubectl }}" From 3187dd76fb7864dff91fcc9e998daf8f98bb64e0 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 09:42:58 +1000 Subject: [PATCH 17/27] Use correct variable --- .github/workflows/build-and-publish-container-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 5dc9331..460fd55 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -87,7 +87,7 @@ jobs: id: kubernetes-version run: | kubectlVersion="${{ matrix.kubectl }}" - kubeVersion="${kubernetesVersion%'.'*}" + kubeVersion="${kubectlVersion%'.'*}" echo "kubernetesVersion=$kubeVersion" >> $GITHUB_OUTPUT echo "kubeVersion=$kubeVersion" From 90a2eb54ff8d45d029f190129a097137f74d6be2 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 11:26:21 +1000 Subject: [PATCH 18/27] Update Readme --- README.md | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2c9a53a..227a508 100644 --- a/README.md +++ b/README.md @@ -4,24 +4,27 @@ This repo produces a container image that is used by the Kubernetes Agent to exe Summary: The image packages `kubectl`, `helm`, `powershell` and `curl` on the base image `mcr.microsoft.com/dotnet/runtime-deps`. -# Building and Pushing a image -Currently this is mostly a manual process which involves dispatching `build-and-publish-container-image` github workflow. -The steps are as follows: -1. Navigate to the ["build and publish container image" workflow](https://github.com/OctopusDeploy/kubernetes-agent-tools-base/actions/workflows/build-and-publish-container-image.yml) -2. Click "Run workflow" -3. Configure the workflow as follows -* Branch: main or your desired branch - Only main will be pushed to dockerhub -* kubectl-version: This follows the Kubernetes versioning - values can be found on the [K8s git repo](https://github.com/kubernetes/kubernetes/tags) -* helm-version: This value will depend on the version of kubectl you have chosen, see the [helm compatibility table](https://helm.sh/docs/topics/version_skew/#supported-version-skew) to get the value. -* powershell-version: See the [Powershell github repo](https://github.com/PowerShell/PowerShell/tags) for a value or just use the default. -* tag-as-latest: If running against main and checked this will also push the image with the latest tag as well as the version tag. -4. Click "Run workflow" - -# Accessing the image -Mainline builds will be pushed to both dockerhub with the name `octopusdeploy/kubernetes-agent-tools-base:{Kubectll Minor Version}.{Kubectl Minor Version}` -Example Dockerhub: `octopusdeploy/kubernetes-agent-tools-base:1.29` - -Branch builds will only be pushed the Octopus' Artifactory instance with a prerelease version `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:{Kubectll Minor Version}.{Kubectl Minor Version}-{Sanitized Branch Name}-{Date}` -Example: `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:1.29-tl-push-to-dockerhub-20240424041854` +## Updating versions + +In the root of the directory there is a file, `versions.json` which contains information about what versions of Kubectl (and thus Kubernetes), Helm & Powershell are used to generate the images. +Under the `tools` object, there are 3 fields with versions arrays (`kubectl`,`helm`,`powershell`), which are used in a matrix to generate the images. + +There is also a `latest` field that represents the kubernetes version that will be tagged with the `latest` tag. +The `revision` field is used to distinguish between versions of the image. + +When updating the images, the `revision` should be continually incremented. + +### Tags + +There are 3 tags being published + +- `latest` - Assigned to the highest version of the Kubernetes supported by the Kubernetes agent. +- `{Kubectl Major Version}.{Kubectl Minor Version}-r{Revision}` - For each `kubectl` version, there will be an image with the Kubernetes major & minor version and revision. Example: `1.31-r6`. +- `kube{Kubectl Version}-helm{Helm Version}-pwsh{Powershell Version}-r{Revision}` - Contains all versions of the tools plus the revision. Example `kube1.31.1-helm3.16.1-pwsh7.4.5-r4`. + +### Branch builds + +Branch builds will only be pushed the Octopus' Artifactory instance with a prerelease version `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:{Kubectll Minor Version}.{Kubectl Minor Version}-r{Revision}-{Sanitized Branch Name}-{Date}` +Example: `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:1.29-r1-tl-push-to-dockerhub-20240424041854` The tags can be found from the logs in the Github action workflow under the step "Create Tag Version` \ No newline at end of file From 0959effc81f746f87bc6d97496ab7a3bc727e4e5 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 11:29:29 +1000 Subject: [PATCH 19/27] Only run on versions.json change --- .github/workflows/build-and-publish-container-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 460fd55..6960242 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -3,12 +3,12 @@ name: Build and Push Container Image on: pull_request: paths: - - versions.json + - 'versions.json' push: branches: - main paths: - - versions.json + - 'versions.json' env: ArtifactoryImagePath: "${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }}/octopusdeploy/kubernetes-agent-tools-base" From 5fe0af831891e8b9247b0cd0e7b67620e9030287 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 12:11:36 +1000 Subject: [PATCH 20/27] Change revision to be random 4 char string --- .github/workflows/build-and-publish-container-image.yml | 4 ++-- versions.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 6960242..2ece3c9 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -33,7 +33,7 @@ jobs: run: | toolsVersions=$(jq -c .tools versions.json) latestVersion=$(jq -r -c .latest versions.json) - revision=$(jq -r -c .revision versions.json) + revision=$(tr -dc A-Za-z0-9 > $GITHUB_OUTPUT echo "tools=$toolsVersions" @@ -100,7 +100,7 @@ jobs: preRelease="-${{steps.branch_names.outputs.branch_name}}-$(date +'%Y%m%d%H%M%S')" fi - revision="-r${{ needs.versions.outputs.revision }}" + revision="-${{ needs.versions.outputs.revision }}" tagVersion="$kubernetesVersion$revision$preRelease"; echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; diff --git a/versions.json b/versions.json index 87c7e54..82f2eec 100644 --- a/versions.json +++ b/versions.json @@ -14,7 +14,6 @@ ] }, "latest": "1.30", - "revision": 1, "deprecatedKubectlVersions": { "1.26": "1.26", "1.27": "1.27" From 522a67c8e73fe2d95fcaf4a7bc864170c8e3417a Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 12:16:43 +1000 Subject: [PATCH 21/27] Only apply revision to main builds --- .github/workflows/build-and-publish-container-image.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 2ece3c9..ac0a48d 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -98,11 +98,12 @@ jobs: if [[ "${{steps.branch_names.outputs.branch_name}}" != "main" ]] then preRelease="-${{steps.branch_names.outputs.branch_name}}-$(date +'%Y%m%d%H%M%S')" + else + revision="-${{ needs.versions.outputs.revision }}" fi - revision="-${{ needs.versions.outputs.revision }}" - tagVersion="$kubernetesVersion$revision$preRelease"; + echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; echo "tagVersion=$tagVersion"; From 776166b0b38674b5359db0d20df921d30bae15d9 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 12:17:23 +1000 Subject: [PATCH 22/27] change to 6 char random revision --- .github/workflows/build-and-publish-container-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index ac0a48d..95443ca 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -33,7 +33,7 @@ jobs: run: | toolsVersions=$(jq -c .tools versions.json) latestVersion=$(jq -r -c .latest versions.json) - revision=$(tr -dc A-Za-z0-9 > $GITHUB_OUTPUT echo "tools=$toolsVersions" @@ -103,7 +103,7 @@ jobs: fi tagVersion="$kubernetesVersion$revision$preRelease"; - + echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; echo "tagVersion=$tagVersion"; From 750e2c5c91fb6eb88ac49b58188813d103be5a05 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 12:24:30 +1000 Subject: [PATCH 23/27] Update readme --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 227a508..0b08b58 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,18 @@ In the root of the directory there is a file, `versions.json` which contains inf Under the `tools` object, there are 3 fields with versions arrays (`kubectl`,`helm`,`powershell`), which are used in a matrix to generate the images. There is also a `latest` field that represents the kubernetes version that will be tagged with the `latest` tag. -The `revision` field is used to distinguish between versions of the image. - -When updating the images, the `revision` should be continually incremented. ### Tags There are 3 tags being published - `latest` - Assigned to the highest version of the Kubernetes supported by the Kubernetes agent. -- `{Kubectl Major Version}.{Kubectl Minor Version}-r{Revision}` - For each `kubectl` version, there will be an image with the Kubernetes major & minor version and revision. Example: `1.31-r6`. -- `kube{Kubectl Version}-helm{Helm Version}-pwsh{Powershell Version}-r{Revision}` - Contains all versions of the tools plus the revision. Example `kube1.31.1-helm3.16.1-pwsh7.4.5-r4`. +- `{Kubectl Major Version}.{Kubectl Minor Version}-{Random6Chars}` - For each `kubectl` version, there will be an image with the Kubernetes major & minor version and random 6 char hash. Example: `1.31-X5msD0`. +- `kube{Kubectl Version}-helm{Helm Version}-pwsh{Powershell Version}-{Random6Chars}` - Contains all versions of the tools plus the revision. Example `kube1.31.1-helm3.16.1-pwsh7.4.5-X5msD0`. ### Branch builds -Branch builds will only be pushed the Octopus' Artifactory instance with a prerelease version `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:{Kubectll Minor Version}.{Kubectl Minor Version}-r{Revision}-{Sanitized Branch Name}-{Date}` -Example: `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:1.29-r1-tl-push-to-dockerhub-20240424041854` +Branch builds will only be pushed the Octopus' Artifactory instance with a prerelease version `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:{Kubectll Minor Version}.{Kubectl Minor Version}-{Sanitized Branch Name}-{Date}` +Example: `{artifactory-hostname}/octopusdeploy/kubernetes-agent-tools-base:1.29-tl-push-to-dockerhub-20240424041854` The tags can be found from the logs in the Github action workflow under the step "Create Tag Version` \ No newline at end of file From 2fc764eb537a16521673b6c920950460f034cc83 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 14:26:39 +1000 Subject: [PATCH 24/27] Change to revision hash driven from versions.json --- .../build-and-publish-container-image.yml | 37 ++++++++++--------- versions.json | 1 + 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index 95443ca..f00cf8a 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -21,7 +21,7 @@ jobs: outputs: toolsVersions: ${{ steps.versions.outputs.tools }} latestVersion: ${{ steps.versions.outputs.latest }} - revision: ${{ steps.versions.outputs.revision}} + revisionHash: ${{ steps.versions.outputs.revision}} steps: - uses: actions/checkout@v4 @@ -33,7 +33,7 @@ jobs: run: | toolsVersions=$(jq -c .tools versions.json) latestVersion=$(jq -r -c .latest versions.json) - revision=$(tr -dc A-Za-z0-9 > $GITHUB_OUTPUT echo "tools=$toolsVersions" @@ -41,8 +41,8 @@ jobs: echo "latest=$latestVersion" >> $GITHUB_OUTPUT echo "latest=$latestVersion" - echo "revision=$revision" >> $GITHUB_OUTPUT - echo "revision=$revision" + echo "revisionHash=$revisionHash" >> $GITHUB_OUTPUT + echo "revisionHash=$revisionHash" build: runs-on: ubuntu-latest @@ -91,34 +91,38 @@ jobs: echo "kubernetesVersion=$kubeVersion" >> $GITHUB_OUTPUT echo "kubeVersion=$kubeVersion" - - name: Create Tag Version + - name: Create tags run: | kubernetesVersion="${{ steps.kubernetes-version.outputs.kubernetesVersion }}" + revisionHash="-${{ needs.versions.outputs.revisionHash }}" if [[ "${{steps.branch_names.outputs.branch_name}}" != "main" ]] then preRelease="-${{steps.branch_names.outputs.branch_name}}-$(date +'%Y%m%d%H%M%S')" - else - revision="-${{ needs.versions.outputs.revision }}" fi - tagVersion="$kubernetesVersion$revision$preRelease"; + # The short tag is just `1.30` (if pre-release, contains full pre-release string) + shortTag="$kubernetesVersion$preRelease" + echo "shortTag=$shortTag" >> $GITHUB_OUTPUT; + echo "shortTag=$shortTag"; - echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; - echo "tagVersion=$tagVersion"; + # Revisioned short tag contains the 6 char revision hash e.g. `1.30-Df8l2d` (plus pre-release, if pre-release) + revisionedShortTag="$kubernetesVersion$revisionHash$preRelease" + echo "revisionedShortTag=$revisionedShortTag" >> $GITHUB_OUTPUT; + echo "revisionedShortTag=$revisionedShortTag"; - allVersionsTag="kube${{ matrix.kubectl}}-helm${{ matrix.helm}}-pwsh${{matrix.powershell}}$revision$preRelease" + # The all versions tag contains all the versions of the main tooling, plus revision hash and pre-release + allVersionsTag="kube${{ matrix.kubectl}}-helm${{ matrix.helm}}-pwsh${{matrix.powershell}}$revisionHash$preRelease" echo "allVersionsTag=$allVersionsTag" >> $GITHUB_OUTPUT; echo "allVersionsTag=$allVersionsTag"; - - id: createTagVersion + id: create-tags - name: Build and push for test if: ${{ github.ref != 'refs/heads/main' }} uses: docker/build-push-action@v5 with: push: true - tags: "${{ env.ArtifactoryImagePath }}:${{ steps.createTagVersion.outputs.tagVersion }},${{ env.ArtifactoryImagePath }}:${{ steps.createTagVersion.outputs.allVersionsTag}}" + tags: "${{ env.ArtifactoryImagePath }}:${{ steps.create-tags.outputs.shortTag }},${{ env.ArtifactoryImagePath }}:${{ steps.create-tags.outputs.revisionedShortTag}},${{ env.ArtifactoryImagePath }}:${{ steps.create-tags.outputs.allVersionsTag}}" platforms: linux/amd64,linux/arm64 build-args: | "KUBECTL_VERSION=${{ matrix.kubectl }}" @@ -128,9 +132,8 @@ jobs: - name: Create production docker tags if: ${{ github.ref == 'refs/heads/main' }} run: | - artifactoryTags="$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.tagVersion }},$ArtifactoryImagePath:${{ steps.createTagVersion.outputs.allVersionsTag}}" - dockerhubTags="$DockerHubImagePath:${{ steps.createTagVersion.outputs.tagVersion }},$DockerHubImagePath:${{ steps.createTagVersion.outputs.allVersionsTag}}" - + artifactoryTags="$ArtifactoryImagePath:${{ steps.create-tags.outputs.shortTag }},$ArtifactoryImagePath:${{ steps.create-tags.outputs.revisionedShortTag}},$ArtifactoryImagePath:${{ steps.create-tags.outputs.allVersionsTag}}" + dockerhubTags="$DockerHubImagePath:${{ steps.create-tags.outputs.shortTag }},$DockerHubImagePath:${{ steps.create-tags.outputs.revisionedShortTag}},$DockerHubImagePath:${{ steps.create-tags.outputs.allVersionsTag}}" kubernetesVersion="${{ matrix.kubectl }}" if [[ "${{ needs.versions.outputs.latestVersion }}" == "${{ steps.kubernetes-version.outputs.kubernetesVersion }}" ]] diff --git a/versions.json b/versions.json index 82f2eec..762d891 100644 --- a/versions.json +++ b/versions.json @@ -14,6 +14,7 @@ ] }, "latest": "1.30", + "revisionHash": "Juaa5J", "deprecatedKubectlVersions": { "1.26": "1.26", "1.27": "1.27" From ed661f99cda2fdffbec2e89b599dc6d8cfc68760 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 14:31:30 +1000 Subject: [PATCH 25/27] Update readme --- README.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0b08b58..723c6b2 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,28 @@ There is also a `latest` field that represents the kubernetes version that will ### Tags -There are 3 tags being published +There are 4 tags being published - `latest` - Assigned to the highest version of the Kubernetes supported by the Kubernetes agent. -- `{Kubectl Major Version}.{Kubectl Minor Version}-{Random6Chars}` - For each `kubectl` version, there will be an image with the Kubernetes major & minor version and random 6 char hash. Example: `1.31-X5msD0`. -- `kube{Kubectl Version}-helm{Helm Version}-pwsh{Powershell Version}-{Random6Chars}` - Contains all versions of the tools plus the revision. Example `kube1.31.1-helm3.16.1-pwsh7.4.5-X5msD0`. +- `{Kubectl Major Version}.{Kubectl Minor Version}` - For each `kubectl` version, there will be an image with the Kubernetes major & minor version. Example: `1.31`. +- `{Kubectl Major Version}.{Kubectl Minor Version}-{Random6Chars}` - For each `kubectl` version, there will be an image with the Kubernetes major & minor version and random 6 char revision hash. Example: `1.31-X5msD0`. +- `kube{Kubectl Version}-helm{Helm Version}-pwsh{Powershell Version}-{Random6Chars}` - Contains all versions of the tools plus the revision hash. Example `kube1.31.1-helm3.16.1-pwsh7.4.5-X5msD0`. + +### What is the `revisionHash`? + +The revision hash is a "cache-busting" mechanism to allow the Kubernetes agent to get an updated version of the tools container image without needing to set the `imagePullPolicy` to `Always`. Because Kubernetes will cache the image on the node(s), it's possible that the image does not get re-acquired when there is a tooling update. + +#### Generating a new `revisionHash` + +As the `revisionHash` is used in the docker tag, which are case-sensitive, the following command generates a unique 6 char hash. + +```bash +tr -dc A-Za-z0-9 Date: Tue, 1 Oct 2024 14:43:14 +1000 Subject: [PATCH 26/27] Update deprecations node --- versions.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/versions.json b/versions.json index 762d891..4d6b1cc 100644 --- a/versions.json +++ b/versions.json @@ -15,8 +15,12 @@ }, "latest": "1.30", "revisionHash": "Juaa5J", - "deprecatedKubectlVersions": { - "1.26": "1.26", - "1.27": "1.27" + "deprecations": { + "1.26": { + "latestTag": "1.26@sha256:a0892db7be9d668eceba2ce0c56ed82b2a58ff205ffea27a98e40825143b63f" + }, + "1.27": { + "latestTag": "1.27@sha256:9d1ce87c37a33582bd3bb0b2e2d54d7a6bc0e71d659a1132acd3893c9645a507" + } } } \ No newline at end of file From 8a8959c91b6020775489d4a2472591dd959e5937 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 1 Oct 2024 14:45:57 +1000 Subject: [PATCH 27/27] Fix revision hash not being passed through --- .github/workflows/build-and-publish-container-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-container-image.yml b/.github/workflows/build-and-publish-container-image.yml index f00cf8a..66c6f5e 100644 --- a/.github/workflows/build-and-publish-container-image.yml +++ b/.github/workflows/build-and-publish-container-image.yml @@ -21,7 +21,7 @@ jobs: outputs: toolsVersions: ${{ steps.versions.outputs.tools }} latestVersion: ${{ steps.versions.outputs.latest }} - revisionHash: ${{ steps.versions.outputs.revision}} + revisionHash: ${{ steps.versions.outputs.revisionHash}} steps: - uses: actions/checkout@v4