Add new versions.json and update build and release workflow to use it #25
Workflow file for this run
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 }} | |
revision: ${{ steps.versions.outputs.revision}} | |
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) | |
revision=$(jq -r -c .revision versions.json) | |
echo "tools=$toolsVersions" >> $GITHUB_OUTPUT | |
echo "tools=$toolsVersions" | |
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: ${{ 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 Tag Version | |
run: | | |
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')" | |
fi | |
revision="-r${{ needs.versions.outputs.revision }}" | |
tagVersion="$kubernetesVersion$revision$preRelease"; | |
echo "tagVersion=$tagVersion" >> $GITHUB_OUTPUT; | |
echo "tagVersion=$tagVersion"; | |
allVersionsTag="kube${{ matrix.kubectl}}-helm${{ matrix.helm}}-pwsh${{matrix.powershell}}$revision$preRelease" | |
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: "${{ env.ArtifactoryImagePath }}:${{ steps.createTagVersion.outputs.tagVersion }},${{ env.ArtifactoryImagePath }}:${{ steps.createTagVersion.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.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,$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 }}" |