Actions OpenWrt Docker Images #32
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: Actions OpenWrt Docker Images | |
env: | |
PREFIX_URL: https://downloads.immortalwrt.org/releases/23.05-SNAPSHOT/targets/ | |
DEVICE_VERSION: 23.05-SNAPSHOT | |
on: | |
workflow_dispatch: | |
inputs: | |
INPUT_TARGET: | |
description: "Target to build (platform/target/subtarget)" | |
required: false | |
default: "all" | |
jobs: | |
Config: | |
name: Generate Config | |
runs-on: ubuntu-latest | |
outputs: | |
TARGETS: ${{ steps.find-targets.outputs.TARGETS }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- 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 "TARGETS=$JSON" >> $GITHUB_OUTPUT | |
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@v3 | |
- 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: Docker Setup QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Docker Setup Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Docker Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PWD }} | |
- 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-$DEVICE_VERSION-$DEVICE_TARGET-$DEVICE_SUBTARGET.Linux-x86_64.tar.xz | |
- name: Set Image Builder | |
run: | | |
tar -xJf *.tar.xz | |
cd immortalwrt-imagebuilder-$DEVICE_VERSION-$DEVICE_TARGET-$DEVICE_SUBTARGET.Linux-x86_64 | |
cp -rf $GITHUB_WORKSPACE/files . | |
chmod +x files/etc/rc.local | |
- name: Build RootFS (amd64) | |
if: env.DOCKER_EXTERA_TAG == 'amd64' | |
run: | | |
cd immortalwrt-imagebuilder-$DEVICE_VERSION-$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 -rf bin/targets/$DEVICE_TARGET/$DEVICE_SUBTARGET/*rootfs.tar.gz $GITHUB_WORKSPACE | |
- name: Delete Image Builder | |
run: | | |
cd $GITHUB_WORKSPACE | |
rm -rf openwrt-imagebuilder* | |
- name: Build & Push Image (amd64) | |
if: env.DOCKER_EXTERA_TAG == 'amd64' | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: ${{ env.DOCKER_IMAGE_ARCH }} | |
file: Dockerfile | |
context: . | |
push: true | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/openwrt:latest | |
${{ secrets.DOCKERHUB_USERNAME }}/openwrt:${{ env.DEVICE_PLATFORM }} | |
${{ secrets.DOCKERHUB_USERNAME }}/openwrt:${{ env.DOCKER_EXTERA_TAG }} | |
- name: Save Image | |
run: | | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/openwrt:latest | |
docker save -o openwrt.tar ${{ secrets.DOCKERHUB_USERNAME }}/openwrt:latest | |
- name: Upload Image | |
uses: actions/upload-artifact@v3 | |
with: | |
name: openwrt.tar | |
path: openwrt.tar |