Skip to content

Commit

Permalink
ci: Fix build and publish workflow (#49)
Browse files Browse the repository at this point in the history
* feat: Provide linux/amd64 and linux/arm64 images
* fix: Fix (hopefull) lack of description under "About this versio"n on package version index
  • Loading branch information
jimisola authored Feb 26, 2024
1 parent 2bcb002 commit f8b7fe4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 43 deletions.
91 changes: 52 additions & 39 deletions .github/workflows/docker-publish..yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: Publish Docker Image to GHCR

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
workflow_dispatch:
release:
Expand All @@ -28,69 +23,87 @@ jobs:
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Docker buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226

# Login against a Docker registry only when tag "vM.M.P"
# https://github.com/docker/login-action
- name: Login to image registry ${{ env.REGISTRY }}
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Cat Dockerfile
run: cat Dockerfile

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index

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

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

# login to ghcr only when tagged with "v*"
- name: Login to image registry ${{ env.REGISTRY }}
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
platforms: ${{ matrix.platform }}
#push: ${{ startsWith(github.ref, 'refs/tags/v') }}
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
annotations: ${{ steps.meta.outputs.annotations }}
provenance: mode=max
sbom: true
outputs: |
type=image,name=target,annotation-index.org.opencontainers.image.title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }},annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }},annotation-index.org.opencontainers.image.licenses=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.licenses'] }},annotation-index.org.opencontainers.image.documentation=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.documentation'] }},annotation-index.org.opencontainers.image.source=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.source'] }},annotation-index.org.opencontainers.image.url=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.url'] }}
# BuildKit doesn't preserve cache mounts in the GitHub Actions cache by default
# see: https://docs.docker.com/build/ci/github-actions/cache/#cache-mounts
# cache-from: type=gha
# cache-to: type=gha,mode=max

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: startsWith(github.ref, 'refs/tags/v')
uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.13.1'
uses: sigstore/cosign-installer@v3.4.0

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
- name: Sign the images with GitHub OIDC Token
if: startsWith(github.ref, 'refs/tags/v')
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.meta.outputs.tags }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --yes ${images}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG GID=worker
ARG VERSION_UNOSERVER=2.0.1

LABEL org.opencontainers.image.title="unoserver-docker"
LABEL org.opencontainers.image.description="Custom Docker Image that contains unoserver, LibreOffice and major set of fonts for file format conversions"
LABEL org.opencontainers.image.description="Custom Container Image that contains unoserver, LibreOffice and major set of fonts for file format conversions"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.documentation="https://github.com/unoconv/unoserver-docker/blob/master/README.adoc"
LABEL org.opencontainers.image.source="https://github.com/unoconv/unoserver-docker"
Expand Down
9 changes: 6 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
= Unoserver Docker Image
= Unoserver Container Image

Docker image for unoserver
Container image for unoserver

== The environment

This Docker image uses Alpine Linux as a base image and provides:
This Container image uses Alpine Linux as a base image and provides:

* link:https://www.libreoffice.org/[LibreOffice]
* link:https://github.com/unoconv/unoserver[unoserver]
Expand All @@ -25,6 +25,8 @@ This Docker image uses Alpine Linux as a base image and provides:

== How to use it

NOTE: The `docker` can normally be replaced with `podman` as well.

=== In interactive mode

Just run:
Expand Down Expand Up @@ -80,6 +82,7 @@ You need the following tools:

=== How to build

[source,bash]
----
docker build .
----

0 comments on commit f8b7fe4

Please sign in to comment.