Skip to content

Build Docker images of Java applications #206

Build Docker images of Java applications

Build Docker images of Java applications #206

Workflow file for this run

---
name: "Build Docker images of Java applications"
on:
workflow_dispatch:
push:
branches:
- "master"
schedule:
- cron: "11 23 * * 0"
env:
REGISTRY_URL: "docker.io/"
jobs:
prepare_base_image:
runs-on: "ubuntu-latest"
outputs:
base_image: "${{ steps.base_image_pre.outputs.base_image }}"
base_tags: "${{ steps.base_image_pre.outputs.tags }}"
tag_jdk: "${{ steps.base_image_pre.outputs.tag_jdk }}"
steps:
- name: "Checkout this repository"
uses: "actions/checkout@v3"
with:
ref: "master"
path: "base_image"
- name: "run prepare script"
id: "base_image_pre"
run: |
chmod a+x ./base_image/workflow/pre.sh
./base_image/workflow/pre.sh
build_base_image:
needs: "prepare_base_image"
runs-on: "ubuntu-latest"
strategy:
fail-fast: true
matrix: "${{ fromJSON( needs.prepare_base_image.outputs.base_tags ) }}"
steps:
- name: "Login to DockerHub"
uses: "docker/login-action@v2"
with:
username: "${{ secrets.DOCKERHUB_USER }}"
password: "${{ secrets.DOCKERHUB_TOKEN }}"
- name: "Checkout this repository"
uses: "actions/checkout@v3"
with:
ref: "master"
path: "base_image"
- name: "Set up QEMU"
uses: "docker/setup-qemu-action@v2"
- name: "Set up Docker Buildx"
uses: "docker/setup-buildx-action@v2"
- name: "retrieve build_args"
id: "current_build_args"
run: |
build_args=$( echo '${{ needs.prepare_base_image.outputs.tag_jdk }}' | jq -r ."${{ matrix.tags }}" )
echo "${build_args}"
echo "buildargs=$( echo "${build_args}" )" >> $GITHUB_OUTPUT
- name: "Build and push ${{ matrix.tags }}"
id: "docker_build"
uses: "docker/build-push-action@v3"
with:
push: true
tags: "${{ needs.prepare_base_image.outputs.base_image }}:${{ matrix.tags }}"
no-cache: true
context: "./base_image/"
file: "./base_image/Dockerfile"
platforms: linux/amd64,linux/arm64
build-args: |
${{ steps.current_build_args.outputs.buildargs }}
base_image_documentation:
needs:
- "prepare_base_image"
- "build_base_image"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout this repository"
uses: "actions/checkout@v3"
with:
ref: "master"
path: "base_image"
- name: "Add build date to JSON"
run: |
dt=$( date '+%Y-%m-%d %H:%M (%Z)' )
fileName="./base_image/built.json"
tagList=$( echo '${{ needs.prepare_base_image.outputs.base_tags }}' | jq -r '.tags[]' )
IFS=$'\n'
for tag in $( echo "${tagList}" ); do
echo "$( cat "${fileName}" | jq -S --argjson add "$( echo '{}' | jq -c --arg key "${tag}" --arg val "${dt}" '.[ $key ] = $val' )" '."master" |= . + $add' )" > "${fileName}"
done
- name: "Commit last built information of base image"
uses: "stefanzweifel/git-auto-commit-action@v4"
with:
commit_message: "Base-Image – last built tags"
commit_user_name: "GitHub Actions"
commit_user_email: "dev@winter-martin.de"
repository: "./base_image/"
trigger_other_repositories:
needs:
- "base_image_documentation"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout this repository"
uses: "actions/checkout@v3"
with:
ref: "master"
path: "base_image"
- name: "try to trigger other workflows from other repositories"
run: |
triggerDefinitionFile="workflow/trigger.json"
curlPrefix='curl --request POST -u "${{ secrets.PAT_USERNAME }}:${{ secrets.PAT_TOKEN }}" '
runCommands=$( cat "./base_image/${triggerDefinitionFile}" | jq -c --arg sq "'" --arg prefix "${curlPrefix}" '.[] as $c | { "cmd": ( $prefix + $c[ "url" ] + " --data " + $sq + ( $c[ "data" ] | tostring ) + $sq ), "comment": $c[ "comment" ] }' )
IFS=$'\n'
for trigger in $( echo "${runCommands}" ); do
echo $( echo "${trigger}" | jq -r '.comment as $c | "\\033[1;30;42m " + $c + " \\033[0m"' )
bash -c "$( echo "${trigger}" | jq -r '.cmd' )"
done
...