Multi-Arch Images #34
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
#================================================= | |
# https://github.com/P3TERX/Actions-OpenWrt | |
# Description: Build OpenWrt using GitHub Actions | |
# Lisence: MIT | |
# Author: P3TERX | |
# Blog: https://p3terx.com | |
#================================================= | |
name: Multi-Arch Images | |
env: | |
WRT_VER: 23.05.1 | |
PREFIX_URL: https://downloads.immortalwrt.org/releases/23.05.1/targets | |
on: | |
workflow_dispatch: | |
inputs: | |
INPUT_TARGET: | |
description: "Target to build (platform/target/subtarget)" | |
required: false | |
default: "all" | |
schedule: | |
- cron: '05 10 * * 4' | |
jobs: | |
Config: | |
name: Generate Config | |
runs-on: ubuntu-latest | |
outputs: | |
TARGETS: ${{ steps.find-targets.outputs.TARGETS }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@main | |
- name: Find Targets | |
id: find-targets | |
env: | |
INPUT_TARGET: ${{ github.event.inputs.INPUT_TARGET }} | |
run: | | |
if [ "$INPUT_TARGET" = "all" ] || [ "$INPUT_TARGET" = "" ]; then | |
export TARGETS="$(cat config/platform.config)" | |
else | |
export TARGETS="$INPUT_TARGET" | |
fi | |
JSON='{"config": ["default"], "targets":[' | |
FIRST=1 | |
for TARGET in $TARGETS; do | |
[[ $FIRST -ne 1 ]] && JSON="$JSON"',' | |
JSON="$JSON"'"'"${TARGET}"'"' | |
FIRST=0 | |
done | |
JSON="$JSON"']}' | |
echo $JSON | |
echo "::set-output name=TARGETS::$JSON" | |
Docker-Images: | |
name: ${{ matrix.TARGETS }} | |
needs: [Config] | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: ${{fromJson(needs.Config.outputs.TARGETS)}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@main | |
- name: Initialization Environment | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
sudo -E apt-get -qq update | |
sudo -E apt-get -qq install build-essential libncurses5-dev libncursesw5-dev \ | |
zlib1g-dev gawk git gettext libssl-dev xsltproc rsync wget unzip python3 qemu-utils genisoimage | |
- name: Set Up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set Up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login To Alibaba Cloud Container Registry | |
run: | | |
docker login -u ${{ secrets.ALIYUN_USERNAME }} -p ${{ secrets.ALIYUN_PWD }} registry.cn-beijing.aliyuncs.com | |
- name: Generate Variables | |
id: env | |
run: | | |
export DEVICE_PLATFORM=$(echo ${{ matrix.TARGETS }} | awk -F '/' '{print $1}') | |
echo "DEVICE_PLATFORM=$DEVICE_PLATFORM" >> $GITHUB_ENV | |
export DEVICE_TARGET=$(echo ${{ matrix.TARGETS }} | awk -F '/' '{print $2}') | |
echo "DEVICE_TARGET=$DEVICE_TARGET" >> $GITHUB_ENV | |
export DEVICE_SUBTARGET=$(echo ${{ matrix.TARGETS }} | awk -F '/' '{print $3}') | |
echo "DEVICE_SUBTARGET=$DEVICE_SUBTARGET" >> $GITHUB_ENV | |
export DOCKER_IMAGE_ARCH=$(echo ${{ matrix.TARGETS }} | awk -F '/' '{print $4}' | sed 's/-/\//g') | |
echo "DOCKER_IMAGE_ARCH=$DOCKER_IMAGE_ARCH" >> $GITHUB_ENV | |
export DOCKER_EXTERA_TAG=$(echo ${{ matrix.TARGETS }} | awk -F '/' '{print $5}') | |
echo "DOCKER_EXTERA_TAG=$DOCKER_EXTERA_TAG" >> $GITHUB_ENV | |
- name: Download Image Builder | |
run: | | |
wget -q $PREFIX_URL/$DEVICE_TARGET/$DEVICE_SUBTARGET/immortalwrt-imagebuilder-$WRT_VER-$DEVICE_TARGET-$DEVICE_SUBTARGET.Linux-x86_64.tar.xz | |
- name: Set Image Builder | |
run: | | |
tar -xJf *.tar.xz | |
cd immortalwrt-imagebuilder-$WRT_VER-$DEVICE_TARGET-$DEVICE_SUBTARGET.Linux-x86_64 | |
cp -rf $GITHUB_WORKSPACE/files . | |
chmod +x files/etc/rc.local | |
- name: Build RootFS | |
run: | | |
cd immortalwrt-imagebuilder-$WRT_VER-$DEVICE_TARGET-$DEVICE_SUBTARGET.Linux-x86_64 | |
chmod +x $GITHUB_WORKSPACE/scripts/* | |
$GITHUB_WORKSPACE/scripts/preset-terminal-tools.sh | |
export CONFIG_PACKAGES=$(cat $GITHUB_WORKSPACE/config/packages.config | tr -s "\n" " ") | |
make image PACKAGES="$CONFIG_PACKAGES" FILES="files" | |
cp bin/targets/$DEVICE_TARGET/$DEVICE_SUBTARGET/*rootfs.tar.gz $GITHUB_WORKSPACE | |
cd $GITHUB_WORKSPACE | |
rm -rf immortalwrt-imagebuilder* | |
- name: Build & Push Image (Default) | |
if: env.DOCKER_EXTERA_TAG == null | |
uses: docker/build-push-action@v2 | |
with: | |
platforms: ${{ env.DOCKER_IMAGE_ARCH }} | |
file: Dockerfile | |
context: . | |
push: true | |
tags: | | |
registry.cn-beijing.aliyuncs.com/${{ secrets.ALIYUN_NAMESPACES }}/openwrt:latest | |
registry.cn-beijing.aliyuncs.com/${{ secrets.ALIYUN_NAMESPACES }}/openwrt:${{ env.DEVICE_PLATFORM }} | |
- name: Build & Push Image (Extra Tag) | |
if: env.DOCKER_EXTERA_TAG != null | |
uses: docker/build-push-action@v2 | |
with: | |
platforms: ${{ env.DOCKER_IMAGE_ARCH }} | |
file: Dockerfile | |
context: . | |
push: true | |
tags: | | |
registry.cn-beijing.aliyuncs.com/${{ secrets.ALIYUN_NAMESPACES }}/openwrt:latest | |
registry.cn-beijing.aliyuncs.com/${{ secrets.ALIYUN_NAMESPACES }}/openwrt:${{ env.DEVICE_PLATFORM }} | |
registry.cn-beijing.aliyuncs.com/${{ secrets.ALIYUN_NAMESPACES }}/openwrt:${{ env.DOCKER_EXTERA_TAG }} |