Skip to content

Commit

Permalink
Give fully parallelised build a try
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Oct 7, 2024
1 parent 4fcf86b commit cd337a1
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 39 deletions.
93 changes: 78 additions & 15 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,50 @@ permissions:
contents: read
packages: write

env:
REGISTRY_IMAGE: ghcr.io/docker-ruby-nightly/ruby

jobs:
set-up-matrix:
name: Set up matrix
runs-on: ubuntu-latest
outputs:
variants: ${{ steps.fetch-variants.outputs.variants }}
images: ${{ steps.fetch-matrix.outputs.images }}
json: ${{ steps.fetch-json.outputs.json }}
steps:
- uses: actions/checkout@v4
- id: fetch-variants
run: echo "variants=$(./variants.rb)" >> "$GITHUB_OUTPUT"
- id: fetch-json
run: echo "json=$(./nightly-versions.rb)" >> "$GITHUB_OUTPUT"
- run: ./apply-templates.sh

- id: fetch-matrix
run: echo "images=$(./images.rb)" >> "$GITHUB_OUTPUT"

build:
needs: set-up-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
variant: ${{ fromJson(needs.set-up-matrix.outputs.variants) }}
name: ${{ matrix.variant }}
image: ${{ fromJson(needs.set-up-matrix.outputs.images) }}
name: ${{ matrix.image.variant }} - ${{ matrix.image.platform }}
steps:
- uses: actions/checkout@v4
- run: echo '${{ needs.set-up-matrix.outputs.json }}' > versions.json
- run: echo date=$(jq -r .master.date versions.json) >> $GITHUB_ENV
- run: ./apply-templates.sh
- run: echo base=$(ruby -e 's = File.read("master/${{ matrix.variant }}/Dockerfile"); puts s[/FROM (.*)/, 1]') >> $GITHUB_ENV
- run: echo platforms=$(./architectures.rb $base) >> $GITHUB_ENV

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env:
tag1: ${{ env.REGISTRY_IMAGE }}:${{ matrix.image.variant }}-nightly-${{ env.date }}
tag2: ${{ env.REGISTRY_IMAGE }}:${{ matrix.image.variant }}-nightly
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=schedule,prefix=${{ matrix.image.variant }}-nightly-,pattern={{date 'YYYY-MM-DD'}}
type=schedule,prefix=${{ matrix.image.variant }}-,pattern=nightly
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -52,13 +67,61 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
env:
tag1: ghcr.io/docker-ruby-nightly/ruby:${{ matrix.variant }}-nightly-${{ env.date }}
tag2: ghcr.io/docker-ruby-nightly/ruby:${{ matrix.variant }}-nightly
with:
context: ./master/${{ matrix.variant }}
push: true
platforms: ${{ env.platforms }}
tags: ${{ env.tag1 }},${{ env.tag2 }}
context: ./master/${{ matrix.image.variant }}
platforms: ${{ matrix.image.platform }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.image.variant }}-${{ matrix.image.platform }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}

- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
16 changes: 0 additions & 16 deletions architectures.rb

This file was deleted.

35 changes: 35 additions & 0 deletions images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env ruby

require "json"

json = JSON.parse(File.read("versions.json"))
latest_release = json.compact.keys.max_by(&:to_f)
variants = json[latest_release]["variants"]

# Result:
# [
# { "variant": "slim-bullseye", "platform": "linux/amd64" },
# { "variant": "slim-bullseye", "platform": "linux/arm64/v8" },
# { "variant": "slim-bullseye", "platform": "linux/386" },
# { "variant": "alpine3.20", "platform": "linux/amd64" },
# { "variant": "alpine3.20", "platform": "linux/arm64/v8" },
# { "variant": "alpine3.20", "platform": "linux/386" }
# ]
images = variants.map do |variant|
# debian:bullseye-slim
base_image = File.read("master/#{variant}/Dockerfile")[/FROM (.*)/, 1]
manifest_inspect = JSON.parse(`docker manifest inspect #{base_image}`)

# ["linux/amd64", "linux/arm64/v8", "linux/386"]
platforms = manifest_inspect["manifests"].filter_map do |manifest|
platform = manifest["platform"]
next unless platform["os"] == "linux"

optional_variant = "/#{platform['variant']}" if platform['variant']
"#{platform['os']}/#{platform['architecture']}#{optional_variant}"
end

platforms.map { |platform| { variant: variant, platform: platform } }
end.flatten

puts images.to_json
6 changes: 5 additions & 1 deletion nightly-versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
"rust" => donor["rust"],
"rustup" => donor["rustup"],
})
puts JSON.generate({ "master" => master })
result = { "master" => master }.to_json
# For step output
puts result
# For apply-templates.sh
File.write("versions.json", result)
7 changes: 0 additions & 7 deletions variants.rb

This file was deleted.

0 comments on commit cd337a1

Please sign in to comment.