Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Dec 28, 2023
1 parent cedac14 commit a2f17ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
54 changes: 28 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docker images
run-name: Images CI for "${{ inputs.base_image_tags || github.event.client_payload.base_image_tags }}"${{ github.event.client_payload.git_ref && ' at ' + github.event.client_payload.git_ref || '' }}
run-name: Images CI for "${{ inputs.base_image_tags || github.event.client_payload.base_image_tags }}"${{ github.event.client_payload.git_ref && format(' at {0}', github.event.client_payload.git_ref) || '' }}

on:
workflow_dispatch:
Expand All @@ -16,61 +16,55 @@ on:

jobs:
config:
name: Build matrix from input
name: Build config
runs-on: ubuntu-latest

steps:
- name: Build matrix
id: config
- id: config
uses: actions/github-script@v7
with:
script: |
let input_tags = process.env.BASE_IMAGE_TAGS_WD || process.env.BASE_IMAGE_TAGS_RD
console.log(`Input raw tags: ${input_tags}`)
let tags = input_tags.split(',').filter(tag => tag !== '')
if (tags.length == 0) {
let base_image_tags = input_tags.split(',').filter(tag => tag !== '')
if (base_image_tags.length == 0) {
core.setFailed("no valid base image tag")
return
}
let tagsMultiline = tags.join('\n')
core.setOutput('tag', tags[0])
core.setOutput('tags', tagsMultiline)
let tagsMultiline = base_image_tags.join('\n')
core.setOutput('base_image_tag', base_image_tags[0])
core.setOutput('base_image_tags', tagsMultiline)
core.summary.addHeading('Input tags').addCodeBlock(tagsMultiline).write()
openjdk_tags = []
tags.forEach(tag => {
openjdk_tags.push(`type=raw,value=${tag}` + ",enable=${{ matrix.extra == 'false' && matrix.java == '17' }}")
openjdk_tags.push(`type=raw,value=${tag}` + "-extra,enable=${{ matrix.extra == 'true' && matrix.java == '17' }}")
openjdk_tags.push(`type=raw,value=${tag}` + "-jdk${{ matrix.java }},enable=${{ matrix.extra == 'false' }}")
openjdk_tags.push(`type=raw,value=${tag}` + "-jdk${{ matrix.java }}-extra,enable=${{ matrix.extra == 'true' }}")
})
core.setOutput('openjdk_tags', openjdk_tags.join('\n'))
console.log('base_image_tags:')
base_image_tags.forEach(tag => console.log(`- ${tag}`))
env:
BASE_IMAGE_TAGS_WD: ${{ inputs.base_image_tags }}
BASE_IMAGE_TAGS_RD: ${{ github.event.client_payload.base_image_tags }}

outputs:
base_image_tag: ${{ steps.config.outputs.tag }}
base_image_tags: ${{ steps.config.outputs.tags }}
openjdk_tags: ${{ steps.config.outputs.openjdk_tags }}
base_image_tag: ${{ steps.config.outputs.base_image_tag }}
base_image_tags: ${{ steps.config.outputs.base_image_tags }}

extra:
name: Extra packages
needs: config
uses: ./.github/workflows/image_one.yml
secrets: inherit
with:
job_name: Extra packages
dockerfile_name: Dockerfile-extra
build_args: |-
BASE_IMAGE=mcdreforged/mcdreforged:${{ needs.config.outputs.base_image_tag }}
base_image_tags: ${{ needs.config.outputs.base_image_tags }}
image_name: mcdreforged/mcdreforged-extra
image_tags: ${{ needs.config.outputs.base_image_tags }}
image_tag_maker_script: |-
core.setOutput('image_tags', process.env.BASE_IMAGE_TAGS)
openjdk:
needs: extra
name: OpenJDK (jdk${{ matrix.java }}, ${{ matrix.distribution }}${{ matrix.extra == 'true' && ', extra' || '' }})
needs: [config, extra]
strategy:
matrix:
java: ['8', '11', '17', '21']
Expand All @@ -80,10 +74,18 @@ jobs:
uses: ./.github/workflows/image_one.yml
secrets: inherit
with:
job_name: OpenJDK (jdk${{ matrix.java }}, ${{ matrix.distribution }}${{ matrix.extra == 'true' && ', extra' || '' }})
dockerfile_name: Dockerfile-${{ matrix.distribution }}
build_args: |-
BASE_IMAGE=mcdreforged/${{ matrix.extra == 'true' && 'mcdreforged-extra' || 'mcdreforged' }}:${{ needs.config.outputs.base_image_tag }}
JAVA=${{ matrix.java }}
base_image_tags: ${{ needs.config.outputs.base_image_tags }}
image_name: mcdreforged/mcdreforged-${{ matrix.distribution }}
image_tags: ${{ needs.config.outputs.openjdk_tags }}
image_tag_maker_script: |-
let image_tags = []
process.env.BASE_IMAGE_TAGS.split('\n').forEach(tag => {
image_tags.push(`type=raw,value=${tag},enable=${{ matrix.extra == 'false' && matrix.java == '17' }}`)
image_tags.push(`type=raw,value=${tag}-extra,enable=${{ matrix.extra == 'true' && matrix.java == '17' }}`)
image_tags.push(`type=raw,value=${tag}-jdk${{ matrix.java }},enable=${{ matrix.extra == 'false' }}`)
image_tags.push(`type=raw,value=${tag}-jdk${{ matrix.java }}-extra,enable=${{ matrix.extra == 'true' }}`)
})
core.setOutput('image_tags', image_tags.join('\n'))
18 changes: 12 additions & 6 deletions .github/workflows/image_one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ name: step.image_one
on:
workflow_call:
inputs:
job_name:
type: string
required: false
dockerfile_name:
type: string
required: true
build_args:
type: string
required: true
base_image_tags:
type: string
required: true
image_name:
type: string
required: true
image_tags:
image_tag_maker_script:
type: string
required: true
outputs:
Expand All @@ -28,7 +28,6 @@ on:

jobs:
image:
name: ${{ inputs.job_name }}
runs-on: ubuntu-latest
outputs:
imageid: ${{ steps.build.outputs.imageid }}
Expand All @@ -37,6 +36,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- id: config
uses: actions/github-script@v7
with:
script: ${{ inputs.image_tag_maker_script }}
env:
BASE_IMAGE_TAGS: ${{ inputs.base_image_tags }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand All @@ -53,7 +59,7 @@ jobs:
uses: docker/metadata-action@v4
with:
images: ${{ inputs.image_name }}
tags: ${{ inputs.image_tags }}
tags: ${{ steps.config.outputs.image_tags }}

- name: Build and push
id: build
Expand Down

0 comments on commit a2f17ac

Please sign in to comment.