Skip to content

Publish Docker image #2

Publish Docker image

Publish Docker image #2

name: Publish Docker image
on:
workflow_dispatch:
inputs:
version:
description: For which PMD version the docker image should be created, e.g. 7.12.0?
required: true
type: string
tags:
description: Comma separated list of tags to be pushed, e.g. "latest,x.y.z,x.y,x"
required: true
type: string
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to Docker Hub
# https://github.com/docker/login-action/releases/tag/v3.4.0
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the Container registry
# https://github.com/docker/login-action/releases/tag/v3.4.0
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create tags list
id: meta
env:
TAGS: ${{ inputs.tags }}
shell: bash
run: |
IFS="," read -ra TAGSARRAY <<< "$TAGS"
all_tags=""
for tag in "${TAGSARRAY[@]}"; do
all_tags="${all_tags}docker.io/pmdcode/pmd:$tag,ghcr.io/pmd/pmd:$tag,"
done
# remove trailing comma
all_tags="${all_tags%,}"
echo "tags=${all_tags}" >> "$GITHUB_OUTPUT"
echo "created=$(date -uIs)" >> "$GITHUB_OUTPUT"
- name: Build and push Docker images
id: push
# https://github.com/docker/build-push-action/releases/tag/v6.15.0
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
with:
context: .
file: ./Dockerfile
build-args: |
PMD_VERSION=${{ inputs.version }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
org.opencontainers.image.title=PMD Docker
org.opencontainers.image.url=https://github.com/pmd/docker
org.opencontainers.image.version=${{ inputs.version }}
org.opencontainers.image.created=${{ steps.meta.outputs.created }}
org.opencontainers.image.source=https://github.com/pmd/docker
org.opencontainers.image.licenses=BSD-3-Clause
- name: Generate artifact attestation (docker)
uses: actions/attest-build-provenance@v2
with:
subject-name: index.docker.io/pmdcode/pmd
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: false
- name: Generate artifact attestation (ghcr)
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/pmd/pmd
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: false