Add new versions.json and update build and release workflow to use it… #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Container Image | |
on: | |
pull_request: | |
paths: | |
- 'versions.json' | |
push: | |
branches: | |
- main | |
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 | |
outputs: | |
toolsVersions: ${{ steps.versions.outputs.tools }} | |
latestVersion: ${{ steps.versions.outputs.latest }} | |
revisionHash: ${{ steps.versions.outputs.revisionHash}} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: "Parse versions.json" | |
id: versions | |
run: | | |
toolsVersions=$(jq -c .tools versions.json) | |
latestVersion=$(jq -r -c .latest versions.json) | |
revisionHash=$(jq -r -c .revisionHash versions.json) | |
echo "tools=$toolsVersions" >> $GITHUB_OUTPUT | |
echo "tools=$toolsVersions" | |
echo "latest=$latestVersion" >> $GITHUB_OUTPUT | |
echo "latest=$latestVersion" | |
echo "revisionHash=$revisionHash" >> $GITHUB_OUTPUT | |
echo "revisionHash=$revisionHash" | |
build: | |
runs-on: ubuntu-latest | |
needs: versions | |
strategy: | |
matrix: ${{ fromJSON(needs.versions.outputs.toolsVersions) }} | |
steps: | |
- name: Log Inputs | |
run: | | |
echo "Kubectl Version: ${{ matrix.kubectl }}" | |
echo "Helm Version: ${{ matrix.helm }}" | |
echo "Powershell Version: ${{ matrix.powershell }}" | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get branch names | |
id: branch_names | |
uses: OctopusDeploy/util-actions/[email protected] | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Artifactory | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ secrets.ARTIFACTORY_DOCKER_REPO_HOSTNAME }} | |
username: ${{ secrets.ARTIFACTORY_USERNAME }} | |
password: ${{ secrets.ARTIFACTORY_PASSWORD }} | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
# Only log into Dockerhub on when using main branch | |
if: ${{ github.ref == 'refs/heads/main' }} | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Get Kubernetes Version | |
id: kubernetes-version | |
run: | | |
kubectlVersion="${{ matrix.kubectl }}" | |
kubeVersion="${kubectlVersion%'.'*}" | |
echo "kubernetesVersion=$kubeVersion" >> $GITHUB_OUTPUT | |
echo "kubeVersion=$kubeVersion" | |
- 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')" | |
fi | |
# 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"; | |
# 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"; | |
# 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: 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.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 }}" | |
"HELM_VERSION=${{ matrix.helm }}" | |
"POWERSHELL_VERSION=${{ matrix.powershell }}" | |
- name: Create production docker tags | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
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 }}" ]] | |
then | |
artifactoryTags="$artifactoryTags,$ArtifactoryImagePath:latest" | |
dockerhubTags="$dockerhubTags,$DockerHubImagePath:latest" | |
fi | |
dockerTags="$artifactoryTags,$dockerhubTags" | |
echo "dockerTags=$dockerTags" >> $GITHUB_OUTPUT; | |
echo "dockerTags=$dockerTags"; | |
id: createProductionDockerTags | |
- name: Build and push for production | |
if: ${{ github.ref == 'refs/heads/main' }} | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ steps.createProductionDockerTags.outputs.dockerTags }} | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
"KUBECTL_VERSION=${{ matrix.kubectl }}" | |
"HELM_VERSION=${{ matrix.helm }}" | |
"POWERSHELL_VERSION=${{ matrix.powershell }}" |