Build Docker Images #662
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker Images | |
# | |
# Update Docker images we use for building CI | |
# | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 3 * * *' # Scheduled runs every day at 3am UTC | |
permissions: | |
contents: write | |
actions: write | |
packages: write | |
jobs: | |
Docker: | |
runs-on: ubuntu-latest | |
if: ${{ github.repository_owner == 'armbian' }} | |
strategy: | |
fail-fast: false # let other jobs try to complete if one fails | |
matrix: | |
include: | |
- os: "ubuntu" | |
release: "jammy" | |
cache-from: "type=gha,scope=docker_build_jammy" # all-automatic GitHub Actions caching | |
cache-to: "type=gha,scope=docker_build_jammy,mode=max" # all-automatic GitHub Actions caching, max mode | |
- os: "debian" | |
release: "bookworm" | |
cache-from: "" # no caching | |
cache-to: "" # no caching | |
# - os: "debian" | |
# release: "sid" | |
# cache-from: "" # no caching | |
# cache-to: "" # no caching | |
- os: "ubuntu" | |
release: "noble" | |
cache-from: "type=gha,scope=docker_build_noble" # all-automatic GitHub Actions caching | |
cache-to: "type=gha,scope=docker_build_noble,mode=max" # all-automatic GitHub Actions caching, max mode | |
name: "${{ matrix.release }} (${{ matrix.os }})" | |
env: | |
DOCKERFILE_OS: "${{ matrix.os }}" | |
DOCKERFILE_RELEASE: "${{ matrix.release }}" | |
steps: | |
- name: Checkout Armbian Framework | |
uses: actions/checkout@v4 | |
with: | |
repository: armbian/build | |
ref: main | |
fetch-depth: 1 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx_1 | |
continue-on-error: true # this process is prone to failure, lets repeat it again if fails | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up Docker Buildx (retry) | |
id: buildx_2 | |
if: steps.buildx.outcome == 'failure' | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx_3 | |
if: steps.buildx.outcome == 'failure' | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} # github username or org | |
password: ${{ secrets.GITHUB_TOKEN }} # github actions builtin token. repo has to have pkg access. | |
- name: Prepare | |
id: prep | |
run: echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT | |
- name: Generate Dockerfile for ${{env.DOCKERFILE_OS}}:${{env.DOCKERFILE_RELEASE}} via Armbian helper script | |
id: generate | |
env: | |
DOCKER_ARMBIAN_BASE_IMAGE: "${{env.DOCKERFILE_OS}}:${{env.DOCKERFILE_RELEASE}}" # Use this base image | |
DOCKERFILE_USE_ARMBIAN_IMAGE_AS_BASE: "no" # Do NOT use the Armbian image as base image to speed up; we're creating it here | |
run: | | |
bash ./compile.sh generate-dockerfile | |
- name: Build and push ${{env.DOCKERFILE_OS}}:${{env.DOCKERFILE_RELEASE}} (first try) | |
id: docker_build_first | |
continue-on-error: true | |
timeout-minutes: 40 | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 # arm64 is done under qemu and is _very_ slow. Thanks, GitHub! | |
pull: true # Pull new version of base image, always; avoid bit-rot | |
push: true | |
labels: | | |
org.opencontainers.image.title=${{ github.repository }} | |
org.opencontainers.image.description=${{ github.event.repository.description }} | |
org.opencontainers.image.url=${{ github.event.repository.html_url }} | |
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} | |
cache-from: "${{ matrix.cache-from }}" | |
cache-to: "${{ matrix.cache-to }}" | |
tags: ghcr.io/${{ github.repository }}:armbian-${{env.DOCKERFILE_OS}}-${{env.DOCKERFILE_RELEASE}}-latest | |
- name: sleep a random amount of seconds, up to 60, if build/push failed, before trying again | |
if: steps.docker_build_first.outcome == 'failure' | |
run: | | |
echo "::notice os=${{env.DOCKERFILE_OS}},release=${{env.DOCKERFILE_RELEASE}}::Build/push failed, retrying" | |
sleep $((RANDOM % 60)) | |
- name: Build and push again (second try if first failed) | |
id: docker_build_second | |
if: steps.docker_build_first.outcome == 'failure' | |
continue-on-error: false # let the build break if the two tries fail | |
timeout-minutes: 40 | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 # arm64 is done under qemu and is _very_ slow. Thanks, GitHub! | |
pull: false # Don't pull when retrying | |
push: true | |
labels: | | |
org.opencontainers.image.title=${{ github.repository }} | |
org.opencontainers.image.description=${{ github.event.repository.description }} | |
org.opencontainers.image.url=${{ github.event.repository.html_url }} | |
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} | |
#cache-from: "${{ matrix.cache-from }}" # do NOT reload cache when retrying | |
cache-to: "${{ matrix.cache-to }}" # but do save cache | |
tags: ghcr.io/${{ github.repository }}:armbian-${{env.DOCKERFILE_OS}}-${{env.DOCKERFILE_RELEASE}}-latest | |
Keep: | |
name: Keep Alive | |
needs: Docker | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: gautamkrishnar/keepalive-workflow@v2 | |
with: | |
use_api: true |