Skip to content

Commit

Permalink
Add simple playbook to build OpenWRT target
Browse files Browse the repository at this point in the history
  • Loading branch information
danpawlik committed Mar 25, 2023
1 parent 81aa50d commit f497258
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 17 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ podman build -t openwrt-builder -f Dockerfile
## Example

how to use:
```

```shell
mkdir -p openwrt-builder
podman run -it -u user -v $(pwd)/openwrt-builder/:/home/user:z,rw quay.io/dpawlik/openwrt:f37 /bin/bash
```
Expand Down Expand Up @@ -68,3 +69,23 @@ Build the firmware image:
```shell
make -j $(nproc) defconfig download clean world
```

## With Ansible

* Install Ansible:

```sh
sudo dnf install -y ansible-core git
```

* Clone builder project

```sh
git clone https://github.com/danpawlik/openwrt-builder && cd openwrt-builder
```

* Run Ansible playbook

```sh
ansible-playbook -i ansible/inventory.yaml ansible/openwrt-build.yaml
```
6 changes: 6 additions & 0 deletions ansible/inventory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:
hosts:
openwrt.dev:
ansible_port: 22
ansible_host: localhost
ansible_user: fedora
105 changes: 105 additions & 0 deletions ansible/openwrt-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
- name: Build OpenWRT
hosts: openwrt.dev
gather_facts: no
vars:
# available targets:
# ath79/generic -> TP-Link mr3420v3
# ath79/mikrotik -> Mikrotik 962uigs-5hact2hnt - hAP AC
# lantiq/xrx200 -> TP-Link TD-W8970
# ramips/mt7621 -> Ubiquiti U6Lite / Xiaomi 4A Gigabit version
# mediatek/mt7622 -> Xiaomi AX3200 / Redmi AX6S
target: mediatek/mt7622
config_version: extended
build_path: /mnt/build
container_uid: 1000
container_gid: 1000
tasks:
- name: Install required packages
become: true
yum:
name:
- vim
- podman

- name: Create build dir
become: true
file:
path: "{{ build_path }}"
state: directory
mode: "0777"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
setype: container_file_t
selevel: s0

- name: Ensure file exists
become: true
file:
path: "{{ build_path }}/openwrt-config"
state: touch
mode: "0777"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"

- name: Download snapshot config file
shell: |
curl -SL https://downloads.openwrt.org/snapshots/targets/{{ target }}/config.buildinfo > {{ build_path }}/openwrt-config
- name: Execude sed
shell: |
sed -i '/CONFIG_TARGET_DEVICE_/d' {{ build_path }}/openwrt-config
sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' {{ build_path }}/openwrt-config
- name: Add custom config
shell: |
curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/{{ target }}/{{ config_version }} >> {{ build_path }}/openwrt-config
- name: Create podman container
shell: >
podman create
--name openwrt-build
--network host
--uidmap {{ container_uid }}:1000:1
--gidmap {{ container_gid }}:1000:1
--uidmap 0:4000:999
--gidmap 0:4000:999
-v {{ build_path }}:/home/user/:rw
quay.io/dpawlik/openwrt:f38
/usr/bin/sleep 10000000000
ignore_errors: true

- name: Start podman container
shell: |
podman start openwrt-build
ignore_errors: true

- name: Clone OpenWRT project
shell: >
podman exec -it openwrt-build
/bin/bash -c 'if ! [ -d openwrt ]; then git clone https://git.openwrt.org/openwrt/openwrt.git; fi'
- name: Copy openwrt-config to build
shell: |
podman exec -it openwrt-build /bin/bash -c "cp openwrt-config openwrt/.config"
- name: Run feeds update
shell: |
podman exec -it openwrt-build /bin/bash -c "cd openwrt && ./scripts/feeds update -a"
- name: Run feeds install
shell: |
podman exec -it openwrt-build /bin/bash -c "cd openwrt && ./scripts/feeds install -a"
# FIXME: Change commands
- name: Run make menuconfig
shell: |
podman exec -it openwrt-build /bin/bash -c "cd openwrt && make menuconfig"
- name: Run kernel_menuconfig
shell: |
podman exec -it openwrt-build /bin/bash -c "cd openwrt && make -j $(nproc) kernel_menuconfig"
- name: Run build
shell: |
podman exec -it openwrt-build /bin/bash -c "cd openwrt && make -j $(nproc) defconfig download clean world"
4 changes: 2 additions & 2 deletions configs/ath79/mikrotik/basic
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/ath79/mikrotik/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/mikrotik/952ui-5ac2nd/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/ath79/mikrotik/basic >> .config

CONFIG_TARGET_DEVICE_ath79_mikrotik_DEVICE_mikrotik_routerboard-962uigs-5hact2hnt=y
CONFIG_TARGET_DEVICE_PACKAGES_ath79_mikrotik_DEVICE_mikrotik_routerboard-962uigs-5hact2hnt=""
Expand Down
4 changes: 2 additions & 2 deletions configs/ath79/mikrotik/extended
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/ath79/mikrotik/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/mikrotik/952ui-5ac2nd/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/ath79/mikrotik/extended >> .config

CONFIG_TARGET_DEVICE_ath79_mikrotik_DEVICE_mikrotik_routerboard-962uigs-5hact2hnt=y
CONFIG_TARGET_DEVICE_PACKAGES_ath79_mikrotik_DEVICE_mikrotik_routerboard-962uigs-5hact2hnt=""
Expand Down
4 changes: 2 additions & 2 deletions configs/lantiq/xrx200/basic
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/lantiq/xrx200/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/tp-link/w8970/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/lantiq/xrx200/basic >> .config

CONFIG_TARGET_DEVICE_lantiq_xrx200_DEVICE_tplink_tdw8970=y
CONFIG_TARGET_DEVICE_PACKAGES_lantiq_xrx200_DEVICE_tplink_tdw8970=""
Expand Down
4 changes: 2 additions & 2 deletions configs/lantiq/xrx200/extended
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/lantiq/xrx200/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/tp-link/w8970/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/lantiq/xrx200/extended >> .config

CONFIG_TARGET_DEVICE_lantiq_xrx200_DEVICE_tplink_tdw8970=y
CONFIG_TARGET_DEVICE_PACKAGES_lantiq_xrx200_DEVICE_tplink_tdw8970=""
Expand Down
4 changes: 2 additions & 2 deletions configs/mediatek/mt7622/basic
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/mediatek/mt7622/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/xiaomi/ax3200/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/mediatek/mt7622/basic >> .config

CONFIG_TARGET_DEVICE_mediatek_mt7622_DEVICE_xiaomi_redmi-router-ax6s=y
CONFIG_TARGET_DEVICE_PACKAGES_mediatek_mt7622_DEVICE_xiaomi_redmi-router-ax6s=""
Expand Down
4 changes: 2 additions & 2 deletions configs/mediatek/mt7622/extended
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/mediatek/mt7622/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/xiaomi/ax3200/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/mediatek/mt7622/extended >> .config

CONFIG_TARGET_DEVICE_mediatek_mt7622_DEVICE_xiaomi_redmi-router-ax6s=y
CONFIG_TARGET_DEVICE_PACKAGES_mediatek_mt7622_DEVICE_xiaomi_redmi-router-ax6s=""
Expand Down
4 changes: 2 additions & 2 deletions configs/ramips/mt7621/basic
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/ramips/mt7621/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/ubiquiti/u6lite/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/ramips/mt7621/basic >> .config

CONFIG_TARGET_DEVICE_ramips_mt7621_DEVICE_ubnt_unifi-6-lite=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt7621_DEVICE_ubnt_unifi-6-lite=""
Expand Down
4 changes: 2 additions & 2 deletions configs/ramips/mt7621/extended
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: Take the snapshot configuration file and attach the content to it.
# STEPS:
# curl -SL https://downloads.openwrt.org/snapshots/targets/ramips/mt7621/config.buildinfo > .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/ubiquiti/u6lite/extended >> .config
# sed -i '/CONFIG_TARGET_DEVICE_/d' .config; sed -i 's/CONFIG_TARGET_MULTI_PROFILE=y/CONFIG_TARGET_MULTI_PROFILE=n/g' .config
# curl -SL https://raw.githubusercontent.com/danpawlik/openwrt-builder/master/configs/ramips/mt7621/extended >> .config

CONFIG_TARGET_DEVICE_ramips_mt7621_DEVICE_ubnt_unifi-6-lite=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt7621_DEVICE_ubnt_unifi-6-lite=""
Expand Down

0 comments on commit f497258

Please sign in to comment.