diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..149d453 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: Docker images + +on: + workflow_dispatch: + inputs: + base_image_tags: + description: | + List of image tags of the mcdreforged/mcdreforged image for the workflow to build as the base images, separated with ",". + For example: "1.2.3,1.2.3-slim,1.2.3-py3.11,1.2.3-py3.11-slim" + type: string + required: true + +jobs: + build_matrix: + name: Build matrix from input + runs-on: ubuntu-latest + + steps: + - name: Build matrix + id: matrix + uses: actions/github-script@v7 + with: + script: | + let matrix = {'include': []} + let summary = core.summary.addHeading('Input tags', true).addRaw('```', true) + + let tags = process.env.BASE_IMAGE_TAGS.split(',') + tags.filter(tag => tag !== '').forEach(tag => { + matrix.include.push({'base_image_tag': tag}) + summary.addRaw(tag, true) + }) + + console.log(`matrix:`) + console.log(JSON.stringify(matrix, null, 2)) + core.setOutput('matrix', JSON.stringify(matrix)) + summary.addRaw('```', true).write() + + env: + BASE_IMAGE_TAGS: ${{ inputs.base_image_tags }} + + outputs: + matrix: ${{ steps.matrix.outputs.matrix }} + + images: + needs: build_matrix + strategy: + matrix: ${{ fromJson(needs.build_matrix.outputs.matrix) }} + + uses: ./.github/workflows/image_derivatives.yml + secrets: inherit + with: + source_tag: ${{ matrix.base_image_tag }} diff --git a/.github/workflows/image_all.yml b/.github/workflows/image_all.yml deleted file mode 100644 index a4ecf00..0000000 --- a/.github/workflows/image_all.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Docker images - -on: - push: - branches: - - noop # XXX - tags: - - 'v*' - -jobs: - base: - uses: ./.github/workflows/image_one.yml - secrets: inherit - with: - dockerfile_name: Dockerfile-base - build_args: '' - image_name: mcdreforged/mcdreforged - tag_suffix: '' - - openjdk: - needs: base - strategy: - matrix: - java: ['8', '11', '17', '21'] - distribution: ['temurin', 'zulu', 'liberica'] - - uses: ./.github/workflows/image_one.yml - secrets: inherit - with: - dockerfile_name: Dockerfile-${{ matrix.distribution }} - build_args: |- - BASE_IMAGE=mcdreforged/mcdreforged@${{ needs.base.outputs.digest }} - JAVA=${{ matrix.java }} - image_name: mcdreforged/mcdreforged-${{ matrix.distribution }} - tag_suffix: -${{ matrix.java }} diff --git a/.github/workflows/image_derivatives.yml b/.github/workflows/image_derivatives.yml new file mode 100644 index 0000000..d7d96ad --- /dev/null +++ b/.github/workflows/image_derivatives.yml @@ -0,0 +1,48 @@ +name: step.image_derivatives + +# image input: "mcdreforged/mcdreforged:" +# These images will be built: +# mcdreforged/mcdreforged-extra: +# mcdreforged/mcdreforged-: +# mcdreforged/mcdreforged-:-extra +# mcdreforged/mcdreforged-:-jdk +# mcdreforged/mcdreforged-:-jdk-extra +on: + workflow_call: + inputs: + source_tag: + type: string + required: true + +jobs: + extra: + uses: ./.github/workflows/image_one.yml + secrets: inherit + with: + dockerfile_name: Dockerfile-base + build_args: |- + BASE_IMAGE=mcdreforged/mcdreforged:${{ inputs.source_tag }} + image_name: mcdreforged/mcdreforged-extra + image_tags: ${{ inputs.source_tag }} + + openjdk: + needs: extra + strategy: + matrix: + java: ['8', '11', '17', '21'] + distribution: ['temurin', 'zulu', 'liberica'] + extra: ['false', 'true'] + + uses: ./.github/workflows/image_one.yml + secrets: inherit + with: + dockerfile_name: Dockerfile-${{ matrix.distribution }} + build_args: |- + BASE_IMAGE=mcdreforged/${{ matrix.extra == 'true' && 'mcdreforged-extra' || 'mcdreforged' }}:${{ inputs.source_tag }} + JAVA=${{ matrix.java }} + image_name: mcdreforged/mcdreforged-${{ matrix.distribution }} + image_tags: |- + type=raw,value=${{ inputs.source_tag }},enable=${{ matrix.extra == 'false' && matrix.java == '17' }} + type=raw,value=${{ inputs.source_tag }}-extra,enable=${{ matrix.extra == 'true' && matrix.java == '17' }} + type=raw,value=${{ inputs.source_tag }}-jdk${{ matrix.java }},enable=${{ matrix.extra == 'false' }} + type=raw,value=${{ inputs.source_tag }}-jdk${{ matrix.java }}-extra,enable=${{ matrix.extra == 'true' }} diff --git a/.github/workflows/image_one.yml b/.github/workflows/image_one.yml index b173cbc..cbab523 100644 --- a/.github/workflows/image_one.yml +++ b/.github/workflows/image_one.yml @@ -12,7 +12,7 @@ on: image_name: type: string required: true - tag_suffix: + image_tags: type: string required: true outputs: @@ -49,20 +49,15 @@ jobs: uses: docker/metadata-action@v4 with: images: ${{ inputs.image_name }} - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - flavor: - suffix=${{ inputs.tag_suffix }},onlatest=false + tags: ${{ inputs.image_tags }} - name: Build and push id: build uses: docker/build-push-action@v5 with: platforms: linux/amd64 - file: docker/${{ inputs.dockerfile_name }} - context: docker + file: src/${{ inputs.dockerfile_name }} + context: src push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index 49d982b..9e20476 100644 --- a/README.md +++ b/README.md @@ -30,23 +30,29 @@ Images with openjdk (`-extra` means with extra packages) ```bash mcdreforged/mcdreforged-temurin:latest -mcdreforged/mcdreforged-temurin:latest-jdk17 mcdreforged/mcdreforged-temurin:latest-extra +mcdreforged/mcdreforged-temurin:latest-jdk17 mcdreforged/mcdreforged-temurin:latest-jdk17-extra mcdreforged/mcdreforged-temurin:latest-slim -mcdreforged/mcdreforged-temurin:latest-slim-jdk17 mcdreforged/mcdreforged-temurin:latest-slim-extra +mcdreforged/mcdreforged-temurin:latest-slim-jdk17 mcdreforged/mcdreforged-temurin:latest-slim-jdk17-extra + mcdreforged/mcdreforged-temurin:2.13.0 +mcdreforged/mcdreforged-temurin:2.13.0-extra mcdreforged/mcdreforged-temurin:2.13.0-jdk17 +mcdreforged/mcdreforged-temurin:2.13.0-jdk17-extra mcdreforged/mcdreforged-temurin:2.13.0-slim +mcdreforged/mcdreforged-temurin:2.13.0-slim-extra mcdreforged/mcdreforged-temurin:2.13.0-slim-jdk17 +mcdreforged/mcdreforged-temurin:2.13.0-slim-jdk17-extra + mcdreforged/mcdreforged-temurin:2.13.0-py3.11 -mcdreforged/mcdreforged-temurin:2.13.0-py3.11-jdk17 -mcdreforged/mcdreforged-temurin:2.13.0-py3.11-slim -mcdreforged/mcdreforged-temurin:2.13.0-py3.11-slim-jdk17 mcdreforged/mcdreforged-temurin:2.13.0-py3.11-extra +mcdreforged/mcdreforged-temurin:2.13.0-py3.11-jdk17 mcdreforged/mcdreforged-temurin:2.13.0-py3.11-jdk17-extra +mcdreforged/mcdreforged-temurin:2.13.0-py3.11-slim mcdreforged/mcdreforged-temurin:2.13.0-py3.11-slim-extra +mcdreforged/mcdreforged-temurin:2.13.0-py3.11-slim-jdk17 mcdreforged/mcdreforged-temurin:2.13.0-py3.11-slim-jdk17-extra ``` diff --git a/build.sh b/build.sh deleted file mode 100644 index cecd72c..0000000 --- a/build.sh +++ /dev/null @@ -1,27 +0,0 @@ -#/bin/sh -set -e - -VERSION=test -JAVA=17 -BASE_IMAGE=mcdreforged/mcdreforged:${VERSION} - -if [ "$SLIM" == "true" ]; then - SUFFIX="-slim" -elif [ "$FULL" == "true" ]; then - SUFFIX="-full" -else - SUFFIX="" -fi - -docker build . -f Dockerfile-base --progress=plain \ - --build-arg "MCDR=${MCDR:-latest}" \ - --build-arg "SLIM=${SLIM:-false}" \ - --build-arg "FULL=${FULL:-false}" \ - -t "${BASE_IMAGE}${SUFFIX}" -exit 0 -for distribution in temurin zulu liberica; do - docker build . -f "Dockerfile-${distribution}" \ - --build-arg "BASE_IMAGE=${BASE_IMAGE}${SUFFIX}" \ - --build-arg "JAVA=${JAVA}" \ - -t "mcdreforged/mcdreforged-${distribution}:${VERSION}-${JAVA}${SUFFIX}" -done diff --git a/src/Dockerfile-extra b/src/Dockerfile-extra index aafc13a..a8a38c8 100644 --- a/src/Dockerfile-extra +++ b/src/Dockerfile-extra @@ -1,20 +1,15 @@ -ARG BASE_IMAGE_TAG -FROM mcdreforged/mcdreforged:${BASE_IMAGE_TAG} - -ARG MCDR=latest -ARG SLIM=false -ARG FULL=false +ARG BASE_IMAGE +FROM ${BASE_IMAGE} COPY requirements_common.txt / -# Python packages and and MCDR RUN <> /requirements_common.txt pip3 install -r /requirements_common.txt -pip3 install mcdreforged==${MCDR_VERSION} rm -f /requirements_common.txt pip3 cache purge