Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Add windows 2022 specific version for kubectl 1.26.3
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisonmeister committed Oct 3, 2023
1 parent 3f5e224 commit d3b8bff
Showing 1 changed file with 170 additions and 0 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/specific-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: Windows 2022 for kubectl

on:
push:
branches: [ kubectl1.26-win2022-backport ]
workflow_dispatch:

jobs:

get-version-number:
runs-on: windows-latest
outputs:
VERSION: ${{ steps.step1.outputs.VERSION }}
TAG_SUFFIX: ${{ steps.step1.outputs.TAG_SUFFIX }}
GCLOUD_CLI_VERSION: ${{ steps.step1.outputs.GCLOUD_CLI_VERSION }}
CONTINUE: ${{ steps.step1.outputs.Continue }}
WIN2019_VERSION: ${{ steps.step1.outputs.WIN2019_VERSION }}
WIN2022_VERSION: ${{ steps.step1.outputs.WIN2022_VERSION }}

steps:
- uses: actions/checkout@v3
- id: step1
name: Compare latest version with container
run: |
$VERSION = "1.26.3"
$GCLOUD_CLI_VERSION = "447.0.0"
$TAG_SUFFIX = "windows"
echo "GCLOUD_CLI_VERSION=$GCLOUD_CLI_VERSION" >> $env:GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $env:GITHUB_OUTPUT
echo "TAG_SUFFIX=$TAG_SUFFIX" >> $env:GITHUB_OUTPUT
$versionOutput = $VERSION
[System.Version]$version = $null
$versionParsed = [System.Version]::TryParse($versionOutput, [ref]$version)
if(-not $versionParsed) {
Write-Host "Unable to parse '$versionOutput' as a valid version. Won't continue"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else {
$versionToCompare = "$($version.Major).$($version.Minor).$($version.Build)-$TAG_SUFFIX"
Write-Host "Checking to see if octopuslabs/k8s-workertools has $versionToCompare already"
$workerToolsTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/k8s-workertools/tags?page_size=50"
$matchingTag = $workerToolsTags.results | Where-Object { $_.name -eq $versionToCompare }
echo "VERSION=$versionToCompare" >> $env:GITHUB_OUTPUT
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version ($versionToCompare)"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "We need to build a container with $versionToCompare"
Write-Host "Getting OS versions for windows 2022 and 2019"
$win2019_manifest = (docker manifest inspect --verbose "octopuslabs/workertools:latest-windows.2019" | ConvertFrom-Json)
$WIN2019_VERSION = $win2019_manifest.Descriptor.Platform.'os.version'
Write-Host "WIN2019_VERSION: $WIN2019_VERSION"
$win2022_manifest = (docker manifest inspect --verbose "octopuslabs/workertools:latest-windows.2022" | ConvertFrom-Json)
$WIN2022_VERSION = $win2022_manifest.Descriptor.Platform.'os.version'
Write-Host "WIN2022_VERSION: $WIN2022_VERSION"
if([string]::IsNullOrWhiteSpace($WIN2019_VERSION) -or [string]::IsNullOrWhiteSpace($WIN2022_VERSION)) {
throw "Could not establish OS versions for windows 2022 and 2019 needed for docker manifest"
}
echo "WIN2019_VERSION=$WIN2019_VERSION" >> $env:GITHUB_OUTPUT
echo "WIN2022_VERSION=$WIN2022_VERSION" >> $env:GITHUB_OUTPUT
Write-Host "We have everything we need, continuing."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
shell: powershell

build-win-2019:
needs: [get-version-number]
runs-on: windows-2019

steps:
- uses: actions/checkout@v3

- name: DockerHub Login
env:
USERNAME: ${{ secrets.DOCKER_HUB_USER }}
PASSWORD: ${{ secrets.DOCKER_HUB_PAT }}
run: docker login --username ${env:USERNAME} --password "${env:PASSWORD}"
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

- name: Build the win2019 image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
GCLOUD_CLI_VERSION: ${{ needs.get-version-number.outputs.GCLOUD_CLI_VERSION }}
run: docker build ./windows-2019 --build-arg GCLOUD_CLI_VERSION=${env:GCLOUD_CLI_VERSION} --tag octopuslabs/k8s-workertools:${env:VERSION_NUMBER}-windows.2019
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

- name: Push the win2019 version-specific image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
run: docker push octopuslabs/k8s-workertools:${env:VERSION_NUMBER}-windows.2019
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

build-win-2022:
needs: [get-version-number]
runs-on: windows-2022

steps:
- uses: actions/checkout@v3

- name: DockerHub Login
env:
USERNAME: ${{ secrets.DOCKER_HUB_USER }}
PASSWORD: ${{ secrets.DOCKER_HUB_PAT }}
run: docker login --username ${env:USERNAME} --password "${env:PASSWORD}"
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

- name: Build the win2022 image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
GCLOUD_CLI_VERSION: ${{ needs.get-version-number.outputs.GCLOUD_CLI_VERSION }}
run: docker build ./windows-2022 --build-arg GCLOUD_CLI_VERSION=${env:GCLOUD_CLI_VERSION} --tag octopuslabs/k8s-workertools:${env:VERSION_NUMBER}-windows.2022
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

- name: Push the win2022 version-specific image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
run: docker push octopuslabs/k8s-workertools:${env:VERSION_NUMBER}-windows.2022
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

build-docker-manifest:
needs: [get-version-number, build-win-2019, build-win-2022]
runs-on: ubuntu-latest

steps:
- name: DockerHub Login
env:
USERNAME: ${{ secrets.DOCKER_HUB_USER }}
PASSWORD: ${{ secrets.DOCKER_HUB_PAT }}
run: docker login --username $USERNAME --password "$PASSWORD"
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

- name: Create docker manifest for version-specific tag
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
TAG_SUFFIX: ${{ needs.get-version-number.outputs.TAG_SUFFIX }}
run: docker manifest create octopuslabs/k8s-workertools:$VERSION_NUMBER-$TAG_SUFFIX octopuslabs/k8s-workertools:$VERSION_NUMBER-windows.2019 octopuslabs/k8s-workertools:$VERSION_NUMBER-windows.2022
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

- name: Annotate docker manifest for version-specific tag
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
WIN2019_VERSION: ${{ needs.get-version-number.outputs.WIN2019_VERSION }}
WIN2022_VERSION: ${{ needs.get-version-number.outputs.WIN2022_VERSION }}
TAG_SUFFIX: ${{ needs.get-version-number.outputs.TAG_SUFFIX }}
run: |
docker manifest annotate --os "windows" --os-version "$WIN2019_VERSION" --arch "amd64" "octopuslabs/k8s-workertools:$VERSION_NUMBER-$TAG_SUFFIX" "octopuslabs/k8s-workertools:$VERSION_NUMBER-windows.2019" && \
docker manifest annotate --os "windows" --os-version "$WIN2022_VERSION" --arch "amd64" "octopuslabs/k8s-workertools:$VERSION_NUMBER-$TAG_SUFFIX" "octopuslabs/k8s-workertools:$VERSION_NUMBER-windows.2022"
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

- name: Push docker manifest for version-specific tag
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
TAG_SUFFIX: ${{ needs.get-version-number.outputs.TAG_SUFFIX }}
run: docker manifest push octopuslabs/k8s-workertools:$VERSION_NUMBER-$TAG_SUFFIX
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}

0 comments on commit d3b8bff

Please sign in to comment.