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

Build vault-workertools image #84

Build vault-workertools image

Build vault-workertools image #84

Workflow file for this run

name: Build vault-workertools image
on:
schedule:
- cron: '0 5 * * *'
workflow_dispatch:
jobs:
get-vault-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 vault --limitoutput
$version = ($chocoInformationRaw.Split("|"))[1]
$versionSplit = $version.Split(".")
Write-Host "Retrieving tags ..."
$response = try {
$repositoryTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/vault-workertools/tags"
Write-Host "Retrieval successful!"
} catch [System.Net.WebException] {
$_.Exception.Response
Write-Host "Retrieval failed!!"
}
Write-Host "Version: $version"
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
if ($null -eq $response)
{
$matchingTag = $repositoryTags.results | Where-Object {$_.Name -eq $version}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version."
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "HashiCorp Vault 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
# This workflow contains a single job called "build"
build-linux:
# define needs
needs: [get-vault-version]
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Login to docker
- 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 ubuntu-22.04 Docker image
env:
VERSION_NUMBER: ${{ needs.get-vault-version.outputs.VERSION }}
run: docker build ./ubuntu-2204 --build-arg VAULT_VERSION=${{ needs.get-vault-version.outputs.VERSION }} --tag octopuslabs/vault-workertools:$VERSION_NUMBER-ubuntu.2204 --tag octopuslabs/vault-workertools:latest-ubuntu.2204
if: ${{ needs.get-vault-version.outputs.CONTINUE == 'Yes' }}
- name: Push the ubuntu-22.04 version image
env:
VERSION_NUMBER: ${{ needs.get-vault-version.outputs.VERSION }}
run: docker push octopuslabs/vault-workertools:$VERSION_NUMBER-ubuntu.2204
if: ${{ needs.get-vault-version.outputs.CONTINUE == 'Yes' }}
- name: Push the latest ubuntu.2204 image
env:
VERSION_NUMBER: ${{ needs.get-vault-version.outputs.VERSION }}
run: docker push octopuslabs/vault-workertools:latest-ubuntu.2204
if: ${{ needs.get-vault-version.outputs.CONTINUE == 'Yes' }}
build-docker-manifest:
needs: [build-linux, get-vault-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 manifests
env:
VERSION_NUMBER: ${{ needs.get-vault-version.outputs.VERSION }}
run: |
docker manifest create octopuslabs/vault-workertools:latest octopuslabs/vault-workertools:latest-ubuntu.2204
docker manifest create octopuslabs/vault-workertools:$VERSION_NUMBER octopuslabs/vault-workertools:$VERSION_NUMBER-ubuntu.2204
if: ${{ needs.get-vault-version.outputs.CONTINUE == 'Yes' }}
- name: Push manifests
env:
VERSION_NUMBER: ${{ needs.get-vault-version.outputs.VERSION }}
run: |
docker manifest push octopuslabs/vault-workertools:latest
docker manifest push octopuslabs/vault-workertools:$VERSION_NUMBER
if: ${{ needs.get-vault-version.outputs.CONTINUE == 'Yes' }}