openwrt-23.05 mediatek/filogic #49764
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 and push containers | |
run-name: ${{ inputs.ref }} ${{ inputs.target }} | |
on: | |
# push: | |
pull_request: | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: "Tag or branch to deploy (empty for main)" | |
default: "main" | |
required: false | |
target: | |
description: "Single target to build (empty for all)" | |
required: false | |
file_host: | |
description: "File host to use (empty for default)" | |
required: false | |
prefix: | |
description: "Prefix for the image name (add '-' at the end)" | |
required: false | |
# schedule: | |
# - cron: "0 5 * * *" # daily snapshot | |
# - cron: "0 6 * * *" # daily 23.05-SNAPSHOT | |
# - cron: "0 7 * * 2" # weekly 22.03-SNAPSHOT | |
# - cron: "0 8 16 * *" # monthly 21.02-SNAPSHOT | |
jobs: | |
generate_matrix: | |
name: Set matrix | |
runs-on: ${{ (github.event_name != 'pull_request') && fromJSON('[ "docker-builder", "Linux", "X64" ]') || 'ubuntu-latest' }} | |
outputs: | |
imagebuilders: ${{ steps.find_targets.outputs.imagebuilders }} | |
rootfs: ${{ steps.find_targets.outputs.rootfs }} | |
sdks: ${{ steps.find_targets.outputs.sdks }} | |
ref: ${{ steps.find_targets.outputs.ref }} | |
version: ${{ steps.find_targets.outputs.version }} | |
version_path: ${{ steps.find_targets.outputs.version_path }} | |
file_host: ${{ steps.find_targets.outputs.file_host }} | |
steps: | |
- name: Set release to 23.05-SNAPSHOT | |
if: github.event.schedule == '0 6 * * *' | |
run: | | |
echo "VERSION=23.05-SNAPSHOT" >> "$GITHUB_ENV" | |
echo "VERSION_PATH=releases/23.05-SNAPSHOT" >> "$GITHUB_ENV" | |
echo "REF=openwrt-23.05" >> "$GITHUB_ENV" | |
- name: Set release to 22.03-SNAPSHOT | |
if: github.event.schedule == '0 7 * * 2' | |
run: | | |
echo "VERSION=22.03-SNAPSHOT" >> "$GITHUB_ENV" | |
echo "VERSION_PATH=releases/22.03-SNAPSHOT" >> "$GITHUB_ENV" | |
echo "REF=openwrt-22.03" >> "$GITHUB_ENV" | |
- name: Set release to 21.02-SNAPSHOT | |
if: github.event.schedule == '0 8 16 * *' | |
run: | | |
echo "VERSION=21.02-SNAPSHOT" >> "$GITHUB_ENV" | |
echo "VERSION_PATH=releases/21.02-SNAPSHOT" >> "$GITHUB_ENV" | |
echo "REF=openwrt-21.02" >> "$GITHUB_ENV" | |
- name: Set release manually | |
if: github.event.inputs.ref != '' | |
run: | | |
export REF=${{ github.event.inputs.ref == 'master' && 'main' || github.event.inputs.ref }} | |
echo "REF=$REF" >> "$GITHUB_ENV" | |
case $REF in | |
main) | |
VERSION=SNAPSHOT | |
echo "VERSION_PATH=snapshots" >> "$GITHUB_ENV" | |
;; | |
openwrt-*) | |
VERSION=${REF//openwrt-/}-SNAPSHOT | |
echo "VERSION_PATH=releases/$VERSION" >> "$GITHUB_ENV" | |
;; | |
v*) | |
VERSION=${REF//v/} | |
echo "VERSION_PATH=releases/$VERSION" >> "$GITHUB_ENV" | |
;; | |
*) | |
echo "No tag or branch found" | |
exit 1 | |
;; | |
esac | |
echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: openwrt/openwrt | |
ref: ${{ env.REF}} | |
- name: Set targets | |
id: find_targets | |
run: | | |
TARGET_FILTER="${{ github.event.inputs.target }}" | |
# imagebuilders & rootfs | |
JSON_IB='[' | |
FIRST_IB=1 | |
JSON_ROOTFS='[' | |
FIRST_ROOTFS=1 | |
while read -r line; | |
do | |
TARGET=$(echo "$line" | cut -d " " -f 1) | |
ARCH=$(echo "$line" | cut -d " " -f 2) | |
[[ $FIRST_IB -ne 1 ]] && JSON_IB="$JSON_IB"',' | |
FIRST_IB=0 | |
JSON_IB="$JSON_IB"'{"target":"'"$TARGET"'"}' | |
case "$TARGET" in | |
x86/*|arm*|malta/be|mvebu/cortexa9) | |
[[ $FIRST_ROOTFS -ne 1 ]] && JSON_ROOTFS="$JSON_ROOTFS"',' | |
FIRST_ROOTFS=0 | |
JSON_ROOTFS="$JSON_ROOTFS"'{"target":"'"$TARGET"'","arch":"'"$ARCH"'"}' | |
;; | |
esac | |
done <<< $(perl ./scripts/dump-target-info.pl targets 2>/dev/null | ([[ -n "$TARGET_FILTER" ]] && grep -w "$TARGET_FILTER" || cat)) | |
JSON_IB='{"include":'"$JSON_IB"']}' | |
echo -e "\n---- imagebuilders ----\n" | |
echo "$JSON_IB" | jq | |
echo -e "\n---- imagebuilders ----\n" | |
echo "imagebuilders=$JSON_IB" >> "$GITHUB_OUTPUT" | |
JSON_ROOTFS='{"include":'"$JSON_ROOTFS"']}' | |
echo -e "\n---- rootfs ----\n" | |
echo "$JSON_ROOTFS" | jq | |
echo -e "\n---- rootfs ----\n" | |
echo "rootfs=$JSON_ROOTFS" >> "$GITHUB_OUTPUT" | |
# sdks | |
JSON='[' | |
FIRST=1 | |
while read -r line; | |
do | |
ARCH=$(echo "$line" | cut -d " " -f 1) | |
[ -z "$TARGET_FILTER" ] && TARGET=$(echo "$line" | cut -d " " -f 2) || TARGET="$TARGET_FILTER" | |
TARGETS=$(echo "$line" | cut -d " " -f 2- | sed -e 's/ /\\n/g') | |
[[ $FIRST -ne 1 ]] && JSON="$JSON"',' | |
FIRST=0 | |
JSON="$JSON"'{"arch":"'"$ARCH"'","target":"'"$TARGET"'","tags":"'"$ARCH"'\n'"$TARGETS"'"}' | |
done <<< $(perl ./scripts/dump-target-info.pl architectures 2>/dev/null | ([[ -n "$TARGET_FILTER" ]] && grep -w "$TARGET_FILTER" || cat)) | |
JSON='{"include":'"$JSON"']}' | |
echo -e "\n---- sdks ----\n" | |
echo "$JSON" | jq | |
echo -e "\n---- sdks ----\n" | |
echo "sdks=$JSON" >> "$GITHUB_OUTPUT" | |
echo "ref=${REF:-main}" >> "$GITHUB_OUTPUT" | |
echo "version=${VERSION:-SNAPSHOT}" >> "$GITHUB_OUTPUT" | |
echo "version_path=${VERSION_PATH:-snapshots}" >> "$GITHUB_OUTPUT" | |
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }} | |
echo "file_host=${FILE_HOST:-mirror-03.infra.openwrt.org}" >> "$GITHUB_OUTPUT" | |
push-imagebuilder-container: | |
name: ImageBuilder | |
runs-on: ${{ (github.event_name != 'pull_request') && fromJSON('[ "docker-builder", "Linux", "X64" ]') || 'ubuntu-latest' }} | |
needs: generate_matrix | |
strategy: | |
fail-fast: False | |
matrix: ${{fromJson(needs.generate_matrix.outputs.imagebuilders)}} | |
steps: | |
- name: Login to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Docker.io Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Login to Quay.io Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAY_USER }} | |
password: ${{ secrets.QUAY_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/openwrt/imagebuilder | |
docker.io/openwrt/imagebuilder | |
quay.io/openwrt/imagebuilder | |
flavor: | | |
latest=false | |
prefix=${{ github.event.inputs.prefix }} | |
tags: | | |
${{ matrix.target }}-${{ needs.generate_matrix.outputs.ref }} | |
${{ matrix.target }}-${{ needs.generate_matrix.outputs.version }} | |
${{ matrix.target }}-master,enable=${{ needs.generate_matrix.outputs.ref == 'main' }} | |
${{ matrix.target }},enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' }} | |
latest,enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' && matrix.target == 'x86/64'}} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
no-cache: true | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
DOWNLOAD_FILE=imagebuilder-.*x86_64.tar.[xz|zst] | |
VERSION_PATH=${{ needs.generate_matrix.outputs.version_path }} | |
TARGET=${{ matrix.target }} | |
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }} | |
- name: Cleanup Docker containers | |
run: docker system prune -f | |
push-sdk-container: | |
name: SDK | |
runs-on: ${{ (github.event_name != 'pull_request') && fromJSON('[ "docker-builder", "Linux", "X64" ]') || 'ubuntu-latest' }} | |
needs: generate_matrix | |
strategy: | |
fail-fast: False | |
matrix: ${{fromJson(needs.generate_matrix.outputs.sdks)}} | |
steps: | |
- name: Login to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Docker.io Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Login to Quay.io Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAY_USER }} | |
password: ${{ secrets.QUAY_TOKEN }} | |
- name: Docker meta (tag or branch) | |
id: meta_ref | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/openwrt/sdk | |
docker.io/openwrt/sdk | |
quay.io/openwrt/sdk | |
flavor: | | |
latest=false | |
prefix=${{ github.event.inputs.prefix }} | |
suffix=-${{ needs.generate_matrix.outputs.ref }} | |
tags: ${{ matrix.tags }} | |
- name: Docker meta (version) | |
id: meta_version | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/openwrt/sdk | |
docker.io/openwrt/sdk | |
quay.io/openwrt/sdk | |
flavor: | | |
latest=false | |
prefix=${{ github.event.inputs.prefix }} | |
suffix=-${{ needs.generate_matrix.outputs.version }} | |
tags: ${{ matrix.tags }} | |
- name: Docker meta (master) | |
if: needs.generate_matrix.outputs.ref == 'main' | |
id: meta_master | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/openwrt/sdk | |
docker.io/openwrt/sdk | |
quay.io/openwrt/sdk | |
flavor: | | |
latest=false | |
prefix=${{ github.event.inputs.prefix }} | |
suffix=-master | |
tags: ${{ matrix.tags }} | |
- name: Docker meta (target and arch) | |
if: needs.generate_matrix.outputs.version == 'SNAPSHOT' | |
id: meta_target_arch | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/openwrt/sdk | |
docker.io/openwrt/sdk | |
quay.io/openwrt/sdk | |
flavor: | | |
latest=false | |
prefix=${{ github.event.inputs.prefix }} | |
tags: ${{ matrix.tags }} | |
- name: Docker meta (latest) | |
if: needs.generate_matrix.outputs.version == 'SNAPSHOT' && matrix.target == 'x86/64' | |
id: meta_latest | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/openwrt/sdk | |
docker.io/openwrt/sdk | |
quay.io/openwrt/sdk | |
tags: latest | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
no-cache: true | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: | | |
${{ steps.meta_ref.outputs.tags }} | |
${{ steps.meta_version.outputs.tags }} | |
${{ steps.meta_master.outputs.tags }} | |
${{ steps.meta_target_arch.outputs.tags }} | |
${{ steps.meta_latest.outputs.tags }} | |
build-args: | | |
DOWNLOAD_FILE=sdk-.*.Linux-x86_64.tar.[xz|zst] | |
VERSION_PATH=${{ needs.generate_matrix.outputs.version_path }} | |
TARGET=${{ matrix.target }} | |
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }} | |
labels: ${{ steps.meta_ref.outputs.labels }} | |
- name: Cleanup Docker containers | |
run: docker system prune -f | |
push-rootfs-container: | |
name: RootFS | |
runs-on: ${{ (github.event_name != 'pull_request') && fromJSON('[ "docker-builder", "Linux", "X64" ]') || 'ubuntu-latest' }} | |
needs: generate_matrix | |
if: needs.generate_matrix.outputs.rootfs != '{"include":[]}' | |
strategy: | |
fail-fast: False | |
matrix: ${{fromJson(needs.generate_matrix.outputs.rootfs)}} | |
steps: | |
- name: Set up QEMU | |
if: github.event_name == 'pull_request' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y qemu-user-static binfmt-support | |
sudo update-binfmts --import | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Docker.io Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Login to Quay.io Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAY_USER }} | |
password: ${{ secrets.QUAY_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/openwrt/rootfs | |
docker.io/openwrt/rootfs | |
quay.io/openwrt/rootfs | |
flavor: | | |
latest=false | |
prefix=${{ github.event.inputs.prefix }} | |
tags: | | |
${{ matrix.target }}-${{ needs.generate_matrix.outputs.ref }} | |
${{ matrix.target }}-${{ needs.generate_matrix.outputs.version }} | |
${{ matrix.target }}-master,enable=${{ needs.generate_matrix.outputs.ref == 'main' }} | |
${{ matrix.target }},enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' }} | |
${{ matrix.arch }}-${{ needs.generate_matrix.outputs.ref }} | |
${{ matrix.arch }}-${{ needs.generate_matrix.outputs.version }} | |
${{ matrix.arch }}-master,enable=${{ needs.generate_matrix.outputs.ref == 'main' }} | |
${{ matrix.arch }},enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' }} | |
latest,enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' && matrix.target == 'x86/64'}} | |
- name: Generate build args | |
id: build_args | |
run: | | |
echo 'args<<EOF | |
DOWNLOAD_FILE=openwrt-.*-rootfs.tar.gz | |
WORKDIR=/ | |
USER=root | |
VERSION_PATH=${{ needs.generate_matrix.outputs.version_path }} | |
TARGET=${{ matrix.target }} | |
BASE_IMAGE=scratch | |
CMD=ash | |
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }} | |
EOF' >> $GITHUB_OUTPUT | |
- name: Build | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
no-cache: true | |
push: false | |
tags: ${{ steps.meta.outputs.tags }} | |
load: true | |
build-args: ${{ steps.build_args.outputs.args }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/${{ matrix.arch }} | |
- name: Smoke test | |
run: docker run --platform=linux/${{ matrix.arch }} ${{ steps.build.outputs.imageid }} uname -m | |
- name: Push | |
if: github.event_name != 'pull_request' | |
uses: docker/build-push-action@v6 | |
with: | |
no-cache: true | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
build-args: ${{ steps.build_args.outputs.args }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/${{ matrix.arch }} | |
- name: Cleanup Docker containers | |
run: docker system prune -f |