Skip to content

Build octopus-cli Docker image #136

Build octopus-cli Docker image

Build octopus-cli Docker image #136

Workflow file for this run

name: Build octopus-cli Docker image
on:
schedule:
- cron: '0 5 * * *'
workflow_dispatch:
jobs:
get-octopus-cli-version:
runs-on: windows-latest
outputs:
VERSION: ${{ steps.choco.outputs.VERSION }}
CONTINUE: ${{ steps.choco.outputs.CONTINUE }}
steps:
- uses: actions/checkout@v3
- id: choco
name: Compare latest version with container
run: |
$chocoInformationRaw = choco info octopus-cli --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"
echo "VERSION=$versionToCompare" >> $env:GITHUB_OUTPUT
Write-Host "Retrieving tags ..."
$response = try {
$repositoryTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/octopus-cli/tags"
Write-Host "Retrieval successful!"
} catch [System.Net.WebException] {
$_.Exception.Response
Write-Host "Retrieval failed!!"
}
if ($null -eq $response)
{
$matchingTag = $repositoryTags.results | Where-Object {$_.Name -eq $versionToCompare}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version."
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "vNext Octopus CLI has been updated, create new image."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
else
{
if ($response.StatusCode.value__ -eq 404)
{
Write-Host "No tags exist for repo, assuming first build."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
}
shell: powershell
build-linux:
needs: [get-octopus-cli-version]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Docker Hub login
env:
USERNAME: ${{ secrets.DOCKER_HUB_USER }}
PASSWORD: ${{ secrets.DOCKER_HUB_PAT }}
run: |
docker login --username $USERNAME --password "$PASSWORD"
- name: Build the alpine docker image
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: docker build ./alpine --build-arg OCTOPUS_CLI_VERSION=${{ needs.get-octopus-cli-version.outputs.VERSION }} --tag octopuslabs/octopus-cli:${{ needs.get-octopus-cli-version.outputs.VERSION }}-alpine --tag octopuslabs/octopus-cli:latest-alpine
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Push the alpine images
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker push octopuslabs/octopus-cli:$VERSION_NUMBER-alpine
docker push octopuslabs/octopus-cli:latest-alpine
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Build the ubuntu.2204 Docker image
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: docker build ./ubuntu-2204 --build-arg OCTOPUS_CLI_VERSION=${{ needs.get-octopus-cli-version.outputs.VERSION }} --tag octopuslabs/octopus-cli:$VERSION_NUMBER-ubuntu.2204 --tag octopuslabs/octopus-cli:latest-ubuntu.2204
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Push the ubuntu.2204 images
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker push octopuslabs/octopus-cli:$VERSION_NUMBER-ubuntu.2204
docker push octopuslabs/octopus-cli:latest-ubuntu.2204
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
build-docker-manifest:
needs: [build-linux, get-octopus-cli-version]
runs-on: ubuntu-latest
steps:
- name: Docker hub login
env:
USERNAME: ${{ secrets.DOCKER_HUB_USER }}
PASSWORD: ${{ secrets.DOCKER_HUB_PAT }}
run: docker login --username $USERNAME --password "$PASSWORD"
- name: Build latest image manifest
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker manifest create octopuslabs/octopus-cli:latest octopuslabs/octopus-cli:latest-alpine
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Push latest image manifest
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker manifest push octopuslabs/octopus-cli:latest
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Build version image manifest
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker manifest create octopuslabs/octopus-cli:$VERSION_NUMBER octopuslabs/octopus-cli:$VERSION_NUMBER-alpine
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Push version image manifest
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker manifest push octopuslabs/octopus-cli:$VERSION_NUMBER
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}