diff --git a/.github/workflows/main.yaml b/.github/workflows/image-workflow.yaml similarity index 65% rename from .github/workflows/main.yaml rename to .github/workflows/image-workflow.yaml index 33f39af..91195d1 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/image-workflow.yaml @@ -1,8 +1,16 @@ -name: build-images +name: base-image-build on: - workflow_dispatch: - schedule: - - cron: '0 2 * * *' + workflow_call: + inputs: + app: + required: true + type: string + description: 'app image to build' + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_TOKEN: + required: true jobs: build-images: @@ -23,4 +31,4 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Run Build Script - run: bash ./scripts/build-images.sh ${{ secrets.DOCKERHUB_USERNAME }}/ + run: bash ./scripts/build-images.sh ${{ secrets.DOCKERHUB_USERNAME }}/ ${{ inputs.app }} diff --git a/.github/workflows/klipper.yaml b/.github/workflows/klipper.yaml new file mode 100644 index 0000000..f72bde9 --- /dev/null +++ b/.github/workflows/klipper.yaml @@ -0,0 +1,13 @@ +name: 'Image: Klipper' +on: + workflow_dispatch: + schedule: + - cron: '0 2 * * *' +jobs: + build: + uses: mkuf/prind/.github/workflows/image-workflow.yaml@main + with: + app: klipper + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/mainsail.yaml b/.github/workflows/mainsail.yaml new file mode 100644 index 0000000..a051a6e --- /dev/null +++ b/.github/workflows/mainsail.yaml @@ -0,0 +1,13 @@ +name: 'Image: Mainsail' +on: + workflow_dispatch: + schedule: + - cron: '0 2 * * *' +jobs: + build: + uses: mkuf/prind/.github/workflows/image-workflow.yaml@main + with: + app: mainsail + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/moonraker.yaml b/.github/workflows/moonraker.yaml new file mode 100644 index 0000000..d2d7c72 --- /dev/null +++ b/.github/workflows/moonraker.yaml @@ -0,0 +1,13 @@ +name: 'Image: Moonraker' +on: + workflow_dispatch: + schedule: + - cron: '0 2 * * *' +jobs: + build: + uses: mkuf/prind/.github/workflows/image-workflow.yaml@main + with: + app: moonraker + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/ustreamer.yaml b/.github/workflows/ustreamer.yaml new file mode 100644 index 0000000..a82ac52 --- /dev/null +++ b/.github/workflows/ustreamer.yaml @@ -0,0 +1,13 @@ +name: 'Image: Ustreamer' +on: + workflow_dispatch: + schedule: + - cron: '0 2 * * *' +jobs: + build: + uses: mkuf/prind/.github/workflows/image-workflow.yaml@main + with: + app: ustreamer + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/scripts/build-images.sh b/scripts/build-images.sh index 02b9996..994eccf 100755 --- a/scripts/build-images.sh +++ b/scripts/build-images.sh @@ -3,37 +3,33 @@ set -e registry=${1} +app=${2} + platform="linux/amd64,linux/arm/v7" +dockerfile=docker/${app}/Dockerfile +context=$(echo -n ${dockerfile} | rev | cut -f2- -d'/' | rev) -for file in $(find . -iname *Dockerfile* -type f); do - name=$(echo -n ${file} | rev | cut -f2 -d'/' | rev) - context=$(echo -n ${file} | rev | cut -f2- -d'/' | rev) - repo=$(grep "ARG REPO" ${file} | sed -r 's/.*REPO=(.*)$/\1/g') +source=$(grep "ARG REPO" ${dockerfile} | sed -r 's/.*REPO=(.*)$/\1/g') +ref=$(git ls-remote ${source} HEAD | cut -f1) +shortref=$(echo -n ${ref} | cut -c 1-7) - ## Only, if Dockerfile contains a repo - if ! [ -z "${repo}" ]; then - ref=$(git ls-remote ${repo} HEAD | cut -f1) - sref=$(echo -n ${ref} | cut -c 1-7) +## Explicitly build Targets, except 'build' +for target in $(grep "FROM .* as" ${dockerfile} | sed -r 's/.*FROM.*as (.*)/\1/g' | grep -v build); do - ## Explicitly build Targets, except 'build' - for target in $(grep "FROM .* as" ${file} | sed -r 's/.*FROM.*as (.*)/\1/g' | grep -v build); do - - ## Append Target to Tag unless it is 'run' - if [ "${target}" != "run" ]; then - tag_extra="-${target}" - fi - - ## Nightly - docker manifest inspect ${registry}${name}:${sref}${tag_extra} > /dev/null \ - || docker buildx build --build-arg VERSION=${ref} --platform ${platform} -t ${registry}${name}:${sref}${tag_extra} -t ${registry}${name}:nightly${tag_extra} --target ${target} --push ${context} - - ## Tags - for tag in $(git ls-remote --tags --refs ${repo} | tail -n3 | rev | cut -f1 -d'/' | rev); do - docker manifest inspect ${registry}${name}:${tag}${tag_extra} > /dev/null \ - || docker buildx build --build-arg VERSION=${tag} --platform ${platform} -t ${registry}${name}:${tag}${tag_extra} --target ${target} --push ${context} - done - - unset tag_extra - done + ## Append Target to Tag unless it is 'run' + if [ "${target}" != "run" ]; then + tag_extra="-${target}" fi + + ## Nightly + docker manifest inspect ${registry}${app}:${shortref}${tag_extra} > /dev/null \ + || docker buildx build --build-arg VERSION=${ref} --platform ${platform} -t ${registry}${app}:${shortref}${tag_extra} -t ${registry}${app}:nightly${tag_extra} --target ${target} --push ${context} + + ## Tags + for tag in $(git ls-remote --tags --sort='version:refname' --refs ${source} | tail -n3 | rev | cut -f1 -d'/' | rev); do + docker manifest inspect ${registry}${app}:${tag}${tag_extra} > /dev/null \ + || docker buildx build --build-arg VERSION=${tag} --platform ${platform} -t ${registry}${app}:${tag}${tag_extra} --target ${target} --push ${context} + done + + unset tag_extra done