Skip to content

Build and push OCI image #1035

Build and push OCI image

Build and push OCI image #1035

Workflow file for this run

name: Build and push OCI image
on:
schedule:
- cron: '5 3 * * *' # UTC
push:
branches:
- master
- '[0-9].[0-9]'
- '[0-9].[0-9].[0-9]'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=pdftk/pdftk
QUAY_IMAGE=quay.io/pdftk/pdftk
TAG=noop
COMMIT=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
TAG=edge
COMMIT=master
elif [[ ${GITHUB_REF} == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
COMMIT=${TAG}
elif [[ ${GITHUB_REF} == refs/heads/* ]]; then
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
COMMIT=${TAG}
if [ "${{ github.event.repository.default_branch }}" = "${TAG}" ]; then
TAG=edge
COMMIT=master
fi
fi
TAGS="${DOCKER_IMAGE}:${TAG},${QUAY_IMAGE}:${TAG}"
if [[ $TAG =~ ^[0-9]{1,3}\.[0-9]{1,3}(\.[0-9]{1,3})*$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest,${QUAY_IMAGE}:latest"
BUILD_ARGS="VERSION=${TAG}"
else
BUILD_ARGS="COMMIT=${COMMIT}"
fi
echo "version=${TAG}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "args=${BUILD_ARGS}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
outputs: type=tar,dest=/tmp/image.tar
build-args: ${{ steps.prep.outputs.args }}
labels: |
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.label-schema.version=${{ steps.prep.outputs.version }}
org.label-schema.build-date=${{ steps.prep.outputs.created }}
org.label-schema.vcs-ref=${{ github.sha }}
- name: Extract artifacts
run: tar xvf /tmp/image.tar usr/share/java
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: pdftk-java#${{ github.run_id }}
path: usr/share/java/*.jar
retention-days: 1
if-no-files-found: error
outputs:
version: ${{ steps.prep.outputs.version }}
tags: ${{ steps.prep.outputs.tags }}
created: ${{ steps.prep.outputs.created }}
args: ${{ steps.prep.outputs.args }}
main:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Retrieve artifacts
uses: actions/download-artifact@v4
with:
name: pdftk-java#${{ github.run_id }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.multiarch
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ needs.build.outputs.tags }}
build-args: ${{ needs.build.outputs.args }}
labels: |
org.opencontainers.image.version=${{ needs.build.outputs.version }}
org.opencontainers.image.created=${{ needs.build.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.label-schema.version=${{ needs.build.outputs.version }}
org.label-schema.build-date=${{ needs.build.outputs.created }}
org.label-schema.vcs-ref=${{ github.sha }}
provenance: false
outputs:
version: ${{ needs.build.outputs.version }}
check:
needs: main
runs-on: ubuntu-latest
container: pdftk/pdftk:${{ needs.main.outputs.version }}
steps:
- name: Run 'pdftk --help'
run: pdftk --help
- name: Download test/files/duck.pdf from upstream
run: wget https://gitlab.com/pdftk-java/pdftk/-/raw/master/test/files/duck.pdf -O /work/duck.pdf
- name: Assemble (catenate) two PDF files into one
run: |
set -euo pipefail
pdftk /work/duck.pdf /work/duck.pdf output /work/two-ducks.pdf
pdftk /work/two-ducks.pdf dump_data | grep -q 'NumberOfPages: 2'
- name: Rotate a PDF file by 90 degrees clockwise
run: |
set -euo pipefail
pdftk /work/duck.pdf rotate 1east output /work/rotated-duck.pdf
pdftk /work/rotated-duck.pdf dump_data | grep -q 'PageMediaRotation: 90'