Merge pull request #245 from okp4/dependabot/github_actions/wagoid/co… #234
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish | |
on: | |
push: | |
branches: [main] | |
jobs: | |
prepare: | |
name: Create build matrix | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix: ${{ steps.matrix.outputs.config }} | |
any-changed: ${{ steps.changed-dockerfiles.outputs.any_changed }} | |
repository_owner: ${{ steps.environment.outputs.repository_owner }} | |
date_stamp: ${{ steps.environment.outputs.date_stamp }} | |
date: ${{ steps.environment.outputs.date }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Find changed dockerfiles | |
id: changed-dockerfiles | |
uses: tj-actions/[email protected] | |
with: | |
separator: "," | |
files: | | |
**/Dockerfile | |
**/.platforms | |
- name: Setup environment | |
id: environment | |
run: | | |
echo "repository_owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT | |
echo "date_stamp=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT | |
echo "date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT | |
- name: Setup matrix (for changed dockerfiles) | |
id: matrix | |
run: | | |
CONFIG="" | |
ALL_MODIFIED_FILES=${{ steps.changed-dockerfiles.outputs.all_modified_files }} | |
IFS=',' read -r -a DOCKERFILES <<< "$ALL_MODIFIED_FILES" | |
for DOCKERFILE in "${DOCKERFILES[@]}"; do | |
APATH=$(dirname ${DOCKERFILE}) | |
VERSION=$(basename ${APATH}) | |
NAME=$(basename $(dirname $APATH)) | |
PLATFORMS=$(cat ${APATH}/.platforms || echo "linux/amd64") | |
CONFIG="${CONFIG:+${CONFIG}, }{\"path\": \"${APATH}\", \"version\": \"${VERSION}\", \"name\": \"${NAME}\", \"platforms\": \"${PLATFORMS}\"}" | |
done | |
echo "config=[${CONFIG}]" >> $GITHUB_OUTPUT | |
prepare-readmes: | |
runs-on: ubuntu-22.04 | |
needs: prepare | |
if: ${{ !failure() }} | |
outputs: | |
matrix: ${{ steps.matrix.outputs.config }} | |
any-changed: ${{ steps.changed-readmes.outputs.any_changed }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Find changed readme files | |
id: changed-readmes | |
uses: tj-actions/[email protected] | |
with: | |
separator: "," | |
files: | | |
./dockerfiles/**/README.md | |
- name: Build iterable readmes info | |
id: matrix | |
run: | | |
CONFIG="" | |
ALL_MODIFIED_FILES=${{ steps.changed-readmes.outputs.all_modified_files }} | |
IFS=',' read -r -a READMES <<< $ALL_MODIFIED_FILES | |
for README in ${READMES[@]}; do | |
REPO=$(basename $(dirname ${README})) | |
CONFIG="${CONFIG:+${CONFIG}, }{\"repo\": \"${REPO}\", \"path\": \"${README}\"}" | |
done | |
echo "config=[${CONFIG}]" >> $GITHUB_OUTPUT | |
publish-docker-images: | |
timeout-minutes: 10 | |
runs-on: ubuntu-22.04 | |
needs: prepare | |
strategy: | |
matrix: | |
context: ${{ fromJson(needs.prepare.outputs.matrix) }} | |
fail-fast: false | |
if: needs.prepare.outputs.any-changed == 'true' | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/[email protected] | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.DOCKER_REGISTRY_ID }} | |
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_REGISTRY_ID }} | |
password: ${{ secrets.DOCKER_HUB_REGISTRY_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ matrix.context.path }} | |
platforms: ${{ matrix.context.platforms }} | |
push: true | |
tags: | | |
"ghcr.io/${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}-${{ needs.prepare.outputs.date_stamp }}" | |
"ghcr.io/${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}" | |
"${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}-${{ needs.prepare.outputs.date_stamp }}" | |
"${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}" | |
labels: | | |
org.opencontainers.image.created=${{ needs.prepare.outputs.date_stamp }} | |
org.opencontainers.image.name=${{ matrix.context.name }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.version=${{ matrix.context.version }} | |
org.opencontainers.image.vendor=${{ needs.prepare.outputs.repository_owner }} | |
org.opencontainers.image.url=https://github.com/${{ github.repository }}/tree/main/dockerfiles/${{ matrix.context.name }}/${{ matrix.context.version }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }}/tree/main/dockerfiles/${{ matrix.context.name }}/${{ matrix.context.version }} | |
update-dockerhub-readme: | |
timeout-minutes: 10 | |
runs-on: ubuntu-22.04 | |
needs: prepare-readmes | |
strategy: | |
matrix: | |
context: ${{ fromJson(needs.prepare-readmes.outputs.matrix) }} | |
fail-fast: false | |
if: needs.prepare-readmes.outputs.any-changed == 'true' | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Docker Hub Description | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_REGISTRY_ID }} | |
password: ${{ secrets.DOCKER_HUB_REGISTRY_TOKEN }} | |
repository: okp4/${{ matrix.context.repo }} | |
readme-filepath: ${{ matrix.context.path }} |