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

Docker Image CI

Docker Image CI #865

name: Docker Image CI
on:
push:
branches: [ main ]
schedule:
- cron: '0 5 * * *'
workflow_dispatch:
jobs:
get-version-number:
runs-on: windows-latest
outputs:
VERSION: ${{ steps.step1.outputs.VERSION }}
CONTINUE: ${{ steps.step1.outputs.Continue }}
WIN2022_VERSION: ${{ steps.step1.outputs.WIN2022_VERSION }}
steps:
- uses: actions/checkout@v3
- id: step1
name: Compare latest version with container
run: |
$chocoInformationRaw = choco info terraform --limitoutput
$versionOutput = ($chocoInformationRaw.Split("|"))[1]
[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)"
Write-Host "Parsed version as $versionToCompare"
$workerToolsTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/terraform-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"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "We need to upgrade the container to $versionToCompare"
Write-Host "Getting OS versions for windows 2022"
$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($WIN2022_VERSION)) {
throw "Could not establish OS versions for windows 2022 needed for docker manifest"
}
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-ubuntu:
needs: [get-version-number]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- 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: Build the ubuntu.2004 image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
run: docker build ./ubuntu-2004 --tag octopuslabs/terraform-workertools:$VERSION_NUMBER-ubuntu.2004 --tag octopuslabs/terraform-workertools:latest-ubuntu.2004
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Push the ubuntu.2004 version-specific image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
run: docker push octopuslabs/terraform-workertools:$VERSION_NUMBER-ubuntu.2004
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Push the ubuntu.2004 latest image
run: docker push octopuslabs/terraform-workertools:latest-ubuntu.2004
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Build the ubuntu.2204 image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
run: docker build ./ubuntu-2204 --tag octopuslabs/terraform-workertools:$VERSION_NUMBER-ubuntu.2204 --tag octopuslabs/terraform-workertools:latest-ubuntu.2204
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Push the ubuntu.2204 version-specific image
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
run: docker push octopuslabs/terraform-workertools:$VERSION_NUMBER-ubuntu.2204
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Push the ubuntu.2204 latest image
run: docker push octopuslabs/terraform-workertools:latest-ubuntu.2204
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 }}
run: docker build ./windows-2022 --tag octopuslabs/terraform-workertools:${env:VERSION_NUMBER}-windows.2022 --tag octopuslabs/terraform-workertools:latest-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/terraform-workertools:${env:VERSION_NUMBER}-windows.2022
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Push the win2022 latest image
run: docker push octopuslabs/terraform-workertools:latest-windows.2022
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
build-docker-manifest:
needs: [get-version-number, build-ubuntu, 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 latest tag
run: docker manifest create octopuslabs/terraform-workertools:latest octopuslabs/terraform-workertools:latest-windows.2022 octopuslabs/terraform-workertools:latest-ubuntu.2204
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Annotate docker manifest for latest tag
env:
WIN2022_VERSION: ${{ needs.get-version-number.outputs.WIN2022_VERSION }}
run: |
docker manifest annotate --os "windows" --os-version "$WIN2022_VERSION" --arch "amd64" "octopuslabs/terraform-workertools:latest" "octopuslabs/terraform-workertools:latest-windows.2022"
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
- name: Push docker manifest for latest tag
run: docker manifest push octopuslabs/terraform-workertools:latest
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 }}
run: docker manifest create octopuslabs/terraform-workertools:$VERSION_NUMBER octopuslabs/terraform-workertools:$VERSION_NUMBER-windows.2022 octopuslabs/terraform-workertools:$VERSION_NUMBER-ubuntu.2204
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 }}
WIN2022_VERSION: ${{ needs.get-version-number.outputs.WIN2022_VERSION }}
run: |
docker manifest annotate --os "windows" --os-version "$WIN2022_VERSION" --arch "amd64" "octopuslabs/terraform-workertools:$VERSION_NUMBER" "octopuslabs/terraform-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 }}
run: docker manifest push octopuslabs/terraform-workertools:$VERSION_NUMBER
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}