Skip to content

Set max-parallel back to 8 and disable quay.io for now #21

Set max-parallel back to 8 and disable quay.io for now

Set max-parallel back to 8 and disable quay.io for now #21

Workflow file for this run

name: Build Toolchains
permissions: {}
on:
push:
paths:
- ".github/workflows/toolchain.yml"
- "Dockerfile.toolchain"
- "config.mak"
branches:
- main
## ##
## To trigger this workflow using `act` (https://github.com/nektos/act) you can do the following.
## Full run
## act push -j toolchain
## ##
jobs:
# ###
# Generate variables used by other jobs
tbuild_vars:
if: ${{ github.repository == 'BlackDex/rust-musl' }}
name: Generate Build Variables
runs-on: ubuntu-24.04
env:
HAVE_DOCKERHUB_LOGIN: ${{ vars.DOCKERHUB_ENABLED == 'true' && secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}
HAVE_GHCR_LOGIN: ${{ vars.GHCR_ENABLED == 'true' && github.repository_owner != '' && secrets.GITHUB_TOKEN != '' }}
HAVE_QUAY_LOGIN: ${{ vars.QUAY_ENABLED == 'true' && secrets.QUAY_USERNAME != '' && secrets.QUAY_TOKEN != '' }}
outputs:
have_dockerhub_login: ${{ env.HAVE_DOCKERHUB_LOGIN }}
have_ghcr_login: ${{ env.HAVE_GHCR_LOGIN }}
have_quay_login: ${{ env.HAVE_QUAY_LOGIN }}
tag_date: ${{ steps.date.outputs.tag }}
registry_list: ${{ steps.registry.outputs.list }}
steps:
- name: Determine Container Date Tag
id: date
shell: bash
run: |
# Get the current date
echo "tag=$(date +'-%Y-%m-%d')" | tee -a "${GITHUB_OUTPUT}"
- name: Determine Container Registries
id: registry
env:
HAVE_DOCKERHUB_LOGIN: ${{ env.HAVE_DOCKERHUB_LOGIN }}
HAVE_GHCR_LOGIN: ${{ env.HAVE_GHCR_LOGIN }}
HAVE_QUAY_LOGIN: ${{ env.HAVE_QUAY_LOGIN }}
HAVE_LOCALHOST: ${{ github.event.act }}
shell: bash
run: |
registries=""
if [[ "${HAVE_DOCKERHUB_LOGIN}" = true ]]; then
registries="${registries:+${registries} }docker.io"
fi
if [[ "${HAVE_GHCR_LOGIN}" = true ]]; then
registries="${registries:+${registries} }ghcr.io"
fi
if [[ "${HAVE_QUAY_LOGIN}" = true ]]; then
registries="${registries:+${registries} }quay.io"
fi
if [[ "${HAVE_LOCALHOST}" = true ]]; then
registries="${registries:+${registries} }localhost:5000"
fi
echo "list=${registries}" | tee -a "${GITHUB_OUTPUT}"
# ###
# Building Toolchain
toolchain:
if: ${{ github.repository == 'BlackDex/rust-musl' }}
name: Build Toolchain - ${{ matrix.image_tag }} - ${{ matrix.os }}
needs:
- tbuild_vars
runs-on: ${{ matrix.os }}
permissions:
packages: write
contents: read
strategy:
max-parallel: ${{ github.event.act && 1 || 8 }}
matrix:
act:
- ${{ github.event.act }}
os:
- ubuntu-24.04
- ${{ (github.event.act && github.event_name == 'qemu') && 'ubuntu-24.04-qemu-arm' || 'ubuntu-24.04-arm' }}
image_tag:
- x86_64-musl
- aarch64-musl
- armv7-musleabihf
- arm-musleabi
# arch_common_config are based upon the `"COMMON_CONFIG +=` additions extracted
# from the MUSL Dockerfiles here: https://github.com/rust-embedded/cross/tree/master/docker
include:
- image_tag: x86_64-musl
target: x86_64-unknown-linux-musl
- image_tag: aarch64-musl
target: aarch64-unknown-linux-musl
- image_tag: armv7-musleabihf
target: armv7-unknown-linux-musleabihf
arch_common_config: "--with-arch=armv7-a --with-float=hard --with-mode=thumb --with-fpu=vfp"
- image_tag: arm-musleabi
target: arm-unknown-linux-musleabi
arch_common_config: "--with-arch=armv6 --with-float=soft --with-mode=arm"
exclude:
- os: ubuntu-24.04-arm
act: true
steps:
- name: "[act] Debug Matrix"
if: ${{ github.event.act }}
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
MATRIX_JSON: ${{ toJson(matrix) }}
NEEDS_JSON: ${{ toJson(needs)}}
# GITHUB_JSON: ${{ toJson(github) }}
run: |
echo "event_name = ${EVENT_NAME}"
echo ; echo "matrix = ${MATRIX_JSON}"
echo ; echo "needs = ${NEEDS_JSON}"
# echo ; echo "github = ${GITHUB_JSON}"
- name: Determine Arch Tag
id: arch
env:
MATRIX_OS: ${{ matrix.os }}
shell: bash
run: |
if [[ "${MATRIX_OS}" == *-arm ]]; then
echo "type=arm64-" | tee -a "${GITHUB_OUTPUT}"
else
echo "type=amd64-" | tee -a "${GITHUB_OUTPUT}"
fi
- name: Setup Docker Buildx (setup-buildx-action)
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3.9.0
with:
# When using `act`, use the `docker` driver to use local 'docker build' cache
driver: ${{ github.event.act && 'docker' || 'docker-container' }}
cache-binary: false
driver-opts: |
network=host
- name: "[act] Start local registry"
if: ${{ github.event.act }}
shell: bash
run: |
# Start a local docker registry
docker run -d --name act-registry --network host registry:2 || true
- name: Login to DockerHub
if: ${{ needs.tbuild_vars.outputs.have_dockerhub_login == 'true' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to ghcr.io
if: ${{ needs.tbuild_vars.outputs.have_ghcr_login == 'true' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to quay.io
if: ${{ needs.tbuild_vars.outputs.have_quay_login == 'true' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Generate Container Tags
continue-on-error: false
id: tags
shell: bash
env:
REGISTRIES: ${{ needs.tbuild_vars.outputs.registry_list }}
ARCH_TYPE: ${{ steps.arch.outputs.type }}
TAG_DATE: ${{ needs.tbuild_vars.outputs.tag_date }}
run: |
tags=""
for registry in ${REGISTRIES}; do
echo "Generating tags for ${registry}:"
tags="${tags:+${tags},}${registry}/blackdex/musl-toolchain:${ARCH_TYPE}${{ matrix.image_tag }}"
tags="${tags:+${tags},}${registry}/blackdex/musl-toolchain:${ARCH_TYPE}${{ matrix.image_tag }}${TAG_DATE}"
done
if [[ "${tags}" = "" ]]; then
echo "::error::Unable to generate tags. Check if registries are available!"
exit 1
fi
echo "tags=${tags}" | tee -a "${GITHUB_OUTPUT}"
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Docker Build
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
env:
BUILDKIT_PROGRESS: plain
with:
platforms: ${{ (matrix.os == 'ubuntu-24.04-arm' || matrix.os == 'ubuntu-24.04-qemu-arm') && 'linux/arm64' || 'linux/amd64'}}
context: .
file: ./Dockerfile.toolchain
build-args: |
QEMU_CPU=${{ matrix.os == 'ubuntu-24.04-qemu-arm' && 'max,pauth-impdef=on' || ''}}
TARGET=${{ matrix.target }}
ARCH_COMMON_CONFIG=${{ matrix.arch_common_config }}
tags: ${{ steps.tags.outputs.tags }}
push: true
# Merge the separate build amd64 and arm64 builds into one
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
toolchain_merge:
if: ${{ github.repository == 'BlackDex/rust-musl' }}
name: Merge Toolchain Container
runs-on: ubuntu-24.04
permissions:
packages: write
needs:
- tbuild_vars
- toolchain
strategy:
max-parallel: ${{ github.event.act && 1 || 8 }}
matrix:
image_tag:
- x86_64-musl
- aarch64-musl
- armv7-musleabihf
- arm-musleabi
steps:
- name: "[act] Debug Matrix"
if: ${{ github.event.act }}
shell: bash
env:
BUILD_JSON: ${{ toJson(needs.tbuild_vars) }}
NEEDS_JSON: ${{ toJson(needs.toolchain) }}
EVENT_NAME: ${{ github.event_name }}
MATRIX_JSON: ${{ toJson(matrix) }}
# GITHUB_JSON: ${{ toJson(github) }}
run: |
echo "event_name = ${EVENT_NAME}"
echo "build_json = ${BUILD_JSON}"
echo "needs_json = ${NEEDS_JSON}"
echo ; echo "matrix = ${MATRIX_JSON}"
# echo ; echo "github = ${GITHUB_JSON}"
- name: Setup Docker Buildx (setup-buildx-action)
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3.9.0
with:
# When using `act`, use the `docker` driver to use local 'docker build' cache
driver: ${{ github.event.act && 'docker' || 'docker-container' }}
cache-binary: false
driver-opts: |
network=host
- name: "[act] Start local registry"
if: ${{ github.event.act }}
shell: bash
run: |
# Start a local docker registry
docker run -d --name act-registry --network host registry:2 || true
- name: Login to DockerHub
if: ${{ needs.tbuild_vars.outputs.have_dockerhub_login == 'true' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to ghcr.io
if: ${{ needs.tbuild_vars.outputs.have_ghcr_login == 'true' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to quay.io
if: ${{ needs.tbuild_vars.outputs.have_quay_login == 'true' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Create combined manifests for amd64/arm64
shell: bash
env:
REGISTRIES: ${{ needs.tbuild_vars.outputs.registry_list }}
TAG_DATE: ${{ needs.tbuild_vars.outputs.tag_date }}
run: |
tags=""
for registry in ${REGISTRIES}; do
echo "Generating manifest for ${registry}:"
docker buildx imagetools create \
-t ${registry}/blackdex/musl-toolchain:${{ matrix.image_tag }} \
-t ${registry}/blackdex/musl-toolchain:${{ matrix.image_tag }}${TAG_DATE} \
${registry}/blackdex/musl-toolchain:amd64-${{ matrix.image_tag }}${TAG_DATE} \
${registry}/blackdex/musl-toolchain:arm64-${{ matrix.image_tag }}${TAG_DATE}
done
- name: Inspect manifests for amd64/arm64
shell: bash
env:
REGISTRIES: ${{ needs.tbuild_vars.outputs.registry_list }}
run: |
tags=""
for registry in ${REGISTRIES}; do
echo "Inspecting manifest for ${registry}:"
docker buildx imagetools inspect ${registry}/blackdex/musl-toolchain:${{ matrix.image_tag }}
done