forked from zzsrv/OpenWrt-Docker
-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·149 lines (129 loc) · 5.3 KB
/
Actions OpenWrt Docker Images.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#=================================================
# 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