Skip to content

Commit

Permalink
Add flyway workertools build
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisonmeister committed Feb 6, 2024
1 parent 0f4f95b commit 88759b1
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 0 deletions.
201 changes: 201 additions & 0 deletions .github/workflows/flyway-docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
name: Build flyway-workertools image

on:
push:
branches:
- minimal-manifest
paths:
- flyway/**
#schedule:
# - cron: '0 5 * * *'
workflow_dispatch:

env:
REGISTRY_IMAGE_BASE: ${{ secrets.TESTING_DOCKER_HUB_USER }}/labs-workertools
REGISTRY_IMAGE: ${{ secrets.TESTING_DOCKER_HUB_USER }}/labs-flyway-workertools

jobs:

get-version-number:
runs-on: windows-latest
outputs:
CONTINUE: ${{ steps.check-version.outputs.CONTINUE }}
VERSION: ${{ steps.check-version.outputs.VERSION }}
WIN2022_VERSION: ${{ steps.check-version.outputs.WIN2022_VERSION }}
steps:
- uses: actions/checkout@v4
- id: check-version
name: Compare latest version with container
run: |
$manifestDataRaw = Invoke-WebRequest "https://download.red-gate.com/maven/release/org/flywaydb/enterprise/flyway-commandline/maven-metadata.xml"
$manifestData = [Xml]$manifestDataRaw
$latestFlywayVersion = $manifestData.metadata.versioning.release
$workerToolsTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/${{ env.REGISTRY_IMAGE }}/tags?page_size=50"
$matchingTag = $workerToolsTags.results | Where-Object { $_.name -eq $latestFlywayVersion }
echo "VERSION=$latestFlywayVersion" >> $env:GITHUB_OUTPUT
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version of flyway"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "We need to upgrade the flyway container to $latestFlywayVersion"
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-linux:
needs: [get-version-number]
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
strategy:
matrix:
os:
- ubuntu-latest
platform:
- linux/amd64
- linux/arm64
runs-on: ${{ matrix.os }}
env:
VERSION: ${{ needs.get-version-number.outputs.VERSION }}
steps:

- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "PLATFORM_ARCH=${platform//[linux\/]/}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.TESTING_DOCKER_HUB_USER }}
password: ${{ secrets.TESTING_DOCKER_HUB_PAT }}

- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: flyway/${{ env.PLATFORM_PAIR }}
platforms: ${{ matrix.platform }}
build-args: |
BASE_IMAGE=${{ env.REGISTRY_IMAGE_BASE }}
FLYWAY_VERSION=${{ env.VERSION }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
build-win-2022:
needs: [get-version-number]
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
runs-on: windows-2022
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
steps:
- uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.TESTING_DOCKER_HUB_USER }}
password: ${{ secrets.TESTING_DOCKER_HUB_PAT }}

- name: Build the win2022 image
working-directory: ./flyway
run: docker build ./windows-2022 --build-arg BASE_IMAGE=${{ env.REGISTRY_IMAGE_BASE}} --build-arg FLYWAY_VERSION=${{ env.VERSION_NUMBER}} --tag ${{ env.REGISTRY_IMAGE }}:${{ env.VERSION_NUMBER }}-win.2022

- name: Push the win2022 version-specific image
run: docker push ${{ env.REGISTRY_IMAGE }}:${{ env.VERSION_NUMBER }}-win.2022

- name: Export windows digest
run: |
New-Item -Type Directory -Path "$($env:TEMP)/digests" -Force
$imageManifestOutput = $(docker manifest inspect --verbose ${{ env.REGISTRY_IMAGE }}:${{ env.VERSION_NUMBER }}-win.2022)
$fullDigest = ($imageManifestOutput | ConvertFrom-Json).Descriptor.digest
$digest = $fulldigest -Replace "sha256:", ""
$winDigestPath = "$($env:TEMP)/digests/$digest"
New-Item -Type File -Path $winDigestPath
echo "WIN_DIGEST_PATH=$($env:TEMP)/digests" >> $env:GITHUB_ENV
- name: Upload windows digest
uses: actions/upload-artifact@v4
with:
name: digests-windows-amd64
path: ${{ env.WIN_DIGEST_PATH }}/*
if-no-files-found: error
retention-days: 1

merge:
needs: [get-version-number, build-linux, build-win-2022]
if: ${{ needs.get-version-number.outputs.CONTINUE == 'Yes' }}
runs-on: ubuntu-latest
env:
VERSION_NUMBER: ${{ needs.get-version-number.outputs.VERSION }}
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
${{ env.VERSION_NUMBER }}
latest
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.TESTING_DOCKER_HUB_USER }}
password: ${{ secrets.TESTING_DOCKER_HUB_PAT }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
35 changes: 35 additions & 0 deletions flyway/linux-amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG BASE_IMAGE
FROM --platform=linux/amd64 ${BASE_IMAGE}:latest

ARG FLYWAY_VERSION=10.7.1

# Get JRE
RUN apt-get update && apt-get install -y openjdk-17-jre-headless

# Get SQL Fluff for Flyway Check Command
RUN pip3 install sqlfluff==1.2.1

# Install AWS CLI to support IAM role authentication
RUN apt-get update && apt-get install unzip \
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& rm awscliv2.zip \
&& ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update

# Change the workdir to flyway to install flyway binaries
WORKDIR /flyway

# Install flyway
RUN curl -L https://download.red-gate.com/maven/release/org/flywaydb/enterprise/flyway-commandline/${FLYWAY_VERSION}/flyway-commandline-${FLYWAY_VERSION}.tar.gz -o flyway-commandline-${FLYWAY_VERSION}.tar.gz \
&& tar -xzf flyway-commandline-${FLYWAY_VERSION}.tar.gz --strip-components=1 \
&& rm flyway-commandline-${FLYWAY_VERSION}.tar.gz \
# Make the /flyway/flyway command an executable
&& chmod +x /flyway/flyway \
# Make it so any user can call /flyway/flyway
&& ln -s /flyway/flyway /usr/local/bin/flyway

# Download Microsoft Managed Identity jar
RUN curl -o /flyway/lib/azure-identity-1.11.1.jar https://repo1.maven.org/maven2/com/azure/azure-identity/1.11.1/azure-identity-1.11.1.jar

# Octopus expects to start in the default directory
WORKDIR /
35 changes: 35 additions & 0 deletions flyway/linux-arm64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG BASE_IMAGE
FROM --platform=linux/arm64 ${BASE_IMAGE}:latest

ARG FLYWAY_VERSION=10.7.1

# Get JRE
RUN apt-get update && apt-get install -y openjdk-17-jre-headless

# Get SQL Fluff for Flyway Check Command
RUN pip3 install sqlfluff==1.2.1

# Install AWS CLI to support IAM role authentication
RUN apt-get update && apt-get install unzip \
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& rm awscliv2.zip \
&& ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update

# Change the workdir to flyway to install flyway binaries
WORKDIR /flyway

# Install flyway
RUN curl -L https://download.red-gate.com/maven/release/org/flywaydb/enterprise/flyway-commandline/${FLYWAY_VERSION}/flyway-commandline-${FLYWAY_VERSION}.tar.gz -o flyway-commandline-${FLYWAY_VERSION}.tar.gz \
&& tar -xzf flyway-commandline-${FLYWAY_VERSION}.tar.gz --strip-components=1 \
&& rm flyway-commandline-${FLYWAY_VERSION}.tar.gz \
# Make the /flyway/flyway command an executable
&& chmod +x /flyway/flyway \
# Make it so any user can call /flyway/flyway
&& ln -s /flyway/flyway /usr/local/bin/flyway

# Download Microsoft Managed Identity jar
RUN curl -o /flyway/lib/azure-identity-1.11.1.jar https://repo1.maven.org/maven2/com/azure/azure-identity/1.11.1/azure-identity-1.11.1.jar

# Octopus expects to start in the default directory
WORKDIR /
23 changes: 23 additions & 0 deletions flyway/windows-2022/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# escape=`
ARG BASE_IMAGE
FROM --platform=windows/amd64 ${BASE_IMAGE}:latest
SHELL ["powershell", "-Command"]

ARG FLYWAY_VERSION=10.7.1

# Get SQL Fluff for Flyway Check Command
RUN pip3 install sqlfluff==1.2.1

# # Install Flyway
RUN Invoke-WebRequest "https://download.red-gate.com/maven/release/org/flywaydb/enterprise/flyway-commandline/${env:FLYWAY_VERSION}/flyway-commandline-${env:FLYWAY_VERSION}-windows-x64.zip" -OutFile flyway-cli.zip; `
& '.\Program Files\7-Zip\7z.exe' x .\flyway-cli.zip; `
rm .\flyway-cli.zip;

RUN $old = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path).path; `
Write-Host $old; `
$flywayPath = ';C:\flyway-' + ${env:FLYWAY_VERSION}; `
$new = $old + $flywayPath; `
Write-Host $new; `
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path -Value $new; `
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1; `
refreshenv

0 comments on commit 88759b1

Please sign in to comment.