Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-platform builds, delete branch/test tags, and remove GAR [minor] #53

Merged
merged 14 commits into from
Nov 16, 2024
43 changes: 15 additions & 28 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
echo "sha=$SHA" >> $GITHUB_OUTPUT
id: extract_tag

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Setup docker build
shell: bash
run: |-
Expand All @@ -49,48 +55,29 @@ jobs:
echo "context=$DIR" >> $GITHUB_OUTPUT
id: setup

- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: ${{ secrets.GCLOUD_OIDC_POOL }}
create_credentials_file: true
service_account: ${{ secrets.GSA }}
token_format: 'access_token'

- name: GAR login
uses: 'docker/login-action@v3'
with:
registry: 'us-docker.pkg.dev'
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.access_token }}'

- name: Docker Hub Login
uses: docker/login-action@v3
with:
registry: 'docker.io'
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push GAR
uses: docker/build-push-action@v5
with:
context: ${{steps.setup.outputs.context}}
build-args: |
TAG=${{steps.extract_tag.outputs.tag}}
DOCKER_REPOSITORY=us-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT }}/public
push: true
tags: |
us-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT }}/public/${{steps.setup.outputs.image}}:${{steps.extract_tag.outputs.tag}}
us-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT }}/public/${{steps.setup.outputs.image}}:${{steps.extract_tag.outputs.tag}}-${{steps.extract_tag.outputs.sha}}
- name: Determine platforms
id: determine-platforms
run: |
if [[ "${{steps.setup.outputs.image}}" == "scyllaridae-whisper" ]]; then
echo "DOCKER_PLATFORMS=linux/amd64" >> $GITHUB_ENV
else
echo "DOCKER_PLATFORMS=linux/amd64,linux/arm64" >> $GITHUB_ENV
fi

- name: Build and push dockerhub
uses: docker/build-push-action@v5
with:
context: ${{steps.setup.outputs.context}}
platforms: ${{ env.DOCKER_PLATFORMS }}
build-args: |
TAG=${{steps.extract_tag.outputs.tag}}
DOCKER_REPOSITORY=lehighlts
push: true
tags: |
lehighlts/${{steps.setup.outputs.image}}:${{steps.extract_tag.outputs.tag}}
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Delete Docker Tags with Wildcard

on:
delete:
branches:
- "**"
workflow_dispatch:
inputs:
tag_pattern:
description: 'Wildcard pattern for Docker tags to delete'
required: true
default: "^branch-name.*"

jobs:
find-images:
name: Find docker images needing deleted
runs-on: ubuntu-latest
outputs:
dockerFiles: ${{ steps.images.outputs.images }}
steps:
- uses: actions/checkout@v4

- name: Find docker files
id: images
run: |
dockerFiles=$(find examples -name Dockerfile | jq -c --raw-input --slurp 'split("\n")| .[0:-1]')
images=$(echo "$dockerFiles" | jq -r '.[]' | \
awk -F'/' '{print "scyllaridae-" $2}' | \
jq -R -s '. | split("\n") | .[0:-1] | . + ["scyllaridae"]')
echo "images=$images" >> $GITHUB_OUTPUT

delete-docker-tags:
needs: [find-images]
runs-on: ubuntu-latest
strategy:
matrix:
image: ${{ fromJson(needs.find-images.outputs.images )}}
max-parallel: 1 # go easy on the dockerhub API
steps:
- name: checkout
uses: actions/checkout@v4

- name: Delete Docker Tags
run: ./ci/delete-tags.sh
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
DOCKER_REGISTRY: "lehighlts"
DOCKER_IMAGE: ${{ matrix.image }}
TAG_PATTERN: "^${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag_pattern || github.ref_name }}.*"
2 changes: 1 addition & 1 deletion .github/workflows/lint-test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ jobs:
id: images
run: ./ci/run.sh
env:
DOCKER_REPOSITORY_BASE: us-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT }}/public/scyllaridae
DOCKER_REPOSITORY_BASE: lehighlts/scyllaridae
DOCKER_TAG: ${{steps.extract_tag.outputs.tag}}
44 changes: 44 additions & 0 deletions ci/delete-tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set -eou pipefail

if [ "$TAG_PATTERN" = "" ] || [ "$TAG_PATTERN" = "^.*" ] || [ "$TAG_PATTERN" = "^main.*" ]; then
echo "Not mass deleting"
exit 1
fi

echo "Deleting tags matching pattern '$TAG_PATTERN' in repository ${DOCKER_IMAGE}"

curl -s -o response.json -u "${DOCKER_USERNAME}:${DOCKER_ACCESS_TOKEN}" "https://hub.docker.com/v2/repositories/${DOCKER_REPOSITORY}/${DOCKER_IMAGE}/tags?page_size=100"
TAGS=$(jq -r '.results[].name' response.json)
if [ -z "$TAGS" ] || [ "$TAGS" = "null" ]; then
echo "No tags found or failed to retrieve tags."
exit 1
fi

curl -s -o token.json -XPOST \
-H "Content-Type: application/json" \
-d '{"username": "'"${DOCKER_USERNAME}"'", "password": "'"${DOCKER_ACCESS_TOKEN}"'"}' \
"https://hub.docker.com/v2/users/login"

TOKEN=$(jq -r .token token.json)
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
echo "Unable to auth to dockerhub."
exit 1
fi

for TAG in $TAGS; do
if [[ "$TAG" =~ $TAG_PATTERN ]]; then
echo "Deleting tag $TAG"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
-H "Authorization: bearer ${TOKEN}" \
"https://hub.docker.com/v2/repositories/${DOCKER_REPOSITORY}/${DOCKER_IMAGE}/tags/$TAG/")
if [ "$RESPONSE" -eq 204 ]; then
echo "Tag $TAG deleted successfully."
else
echo "Failed to delete tag $TAG. Response code: $RESPONSE"
fi
fi
done

rm response.json token.json
14 changes: 8 additions & 6 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ services:
fits:
image: islandora/fits:main
crayfits:
image: ${DOCKER_REPOSITORY_BASE}-fits:${DOCKER_TAG}
image: lehighlts/scyllaridae-fits:${DOCKER_TAG}
ffmpeg:
image: ${DOCKER_REPOSITORY_BASE}-ffmpeg:${DOCKER_TAG}
image: lehighlts/scyllaridae-ffmpeg:${DOCKER_TAG}
imagemagick:
image: ${DOCKER_REPOSITORY_BASE}-imagemagick:${DOCKER_TAG}
image: lehighlts/scyllaridae-imagemagick:${DOCKER_TAG}
tesseract:
image: ${DOCKER_REPOSITORY_BASE}-tesseract:${DOCKER_TAG}
image: lehighlts/scyllaridae-tesseract:${DOCKER_TAG}
whisper:
image: ${DOCKER_REPOSITORY_BASE}-whisper:${DOCKER_TAG}
image: lehighlts/scyllaridae-whisper:${DOCKER_TAG}
pandoc:
image: lehighlts/scyllaridae-pandoc:${DOCKER_TAG}
test:
image: alpine
command: sleep 300
environment:
DOCKER_REPOSITORY_BASE: ${DOCKER_REPOSITORY_BASE}
DOCKER_TAG: ${DOCKER_TAG}
volumes:
- ./test.sh:/test.sh
- ./fixtures:/fixtures
24 changes: 24 additions & 0 deletions ci/fixtures/pandoc/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Title

## Subtitle

This is a **bold** text and an *italic* text.

Here is a bullet list:
- Item 1
- Item 2

And a numbered list:
1. First
2. Second

Here is an equation:
\[
E = mc^2
\]

A table:

| Column 1 | Column 2 |
|----------|----------|
| Data 1 | Data 2 |
23 changes: 23 additions & 0 deletions ci/fixtures/pandoc/output.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
\section{Title}\label{title}

\subsection{Subtitle}\label{subtitle}

This is a \textbf{bold} text and an \emph{italic} text.

Here is a bullet list: - Item 1 - Item 2

And a numbered list: 1. First 2. Second

Here is an equation: {[} E = mc\^{}2 {]}

A table:

\begin{longtable}[]{@{}ll@{}}
\toprule\noalign{}
Column 1 & Column 2 \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Data 1 & Data 2 \\
\end{longtable}
17 changes: 17 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SERVICES=(
"crayfits"
"ffmpeg"
"whisper"
"pandoc"
)
for SERVICE in "${SERVICES[@]}"; do
URL="http://$SERVICE:8080/"
Expand Down Expand Up @@ -67,6 +68,22 @@ for SERVICE in "${SERVICES[@]}"; do
grep "ask not what your country can do for you" vtt.txt || exit 1
echo "VTT as expected"
rm vtt.txt
elif [ "$SERVICE" == "pandoc" ]; then
curl -o result.tex \
-H "Content-Type: text/markdown" \
-H "Accept: application/x-latex" \
--data-binary "@/fixtures/pandoc/input.md" \
"$URL"

if diff -u result.tex "fixtures/pandoc/output.tex" > diff_output.txt; then
echo "Test Passed: Output matches expected."
else
echo "Test Failed: Differences found."
cat diff_output.txt
exit 1
fi


else
echo "Unknown service"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion examples/cache-warmer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG}

RUN apk update && \
Expand Down
14 changes: 7 additions & 7 deletions examples/coverpage/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae-pandoc:${TAG}

RUN apk add --no-cache \
bash==5.2.21-r0 \
curl==8.5.0-r0 \
ghostscript==10.04.0-r0 \
jq==1.7.1-r0

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl=8.5.0-2ubuntu10.4 \
ghostscript=10.02.1~dfsg1-0ubuntu7.4 \
jq=1.7.1-3build1 \
&& rm -rf /var/lib/apt/lists/*
COPY . /app
2 changes: 1 addition & 1 deletion examples/curl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG}

COPY scyllaridae.yml /app/scyllaridae.yml
2 changes: 1 addition & 1 deletion examples/ffmpeg/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG}

RUN apk update && \
Expand Down
2 changes: 1 addition & 1 deletion examples/fits/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG}

COPY scyllaridae.yml /app/scyllaridae.yml
2 changes: 1 addition & 1 deletion examples/imagemagick/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM islandora/imagemagick:alpine-3.20.2-imagemagick-7.1.1.36-r0 AS imagemagick
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG}

Expand Down
2 changes: 1 addition & 1 deletion examples/libreoffice/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG} AS scyllaridae

COPY scyllaridae.yml /app/
Expand Down
2 changes: 1 addition & 1 deletion examples/mergepdf/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM islandora/leptonica:alpine-3.20.2-leptonica-1.84.1-r0 AS leptonica
FROM ${DOCKER_REPOSITORY}/scyllaridae-imagemagick:${TAG} AS scyllaridae

Expand Down
2 changes: 1 addition & 1 deletion examples/ocrpdf/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=local
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae-imagemagick:${TAG} AS scyllaridae

RUN apk update && \
Expand Down
Loading