├── .github └── workflows │ ├── release.yml │ └── test.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── builder.sh ├── docker ├── Dockerfile ├── home │ ├── .bashrc │ └── .quiltrc └── usr │ └── local │ └── bin │ └── entrypoint.sh ├── example ├── config-rpi └── example.sh └── workdir └── .gitignore /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | on: 2 | release: 3 | types: [created] 4 | 5 | jobs: 6 | push_image: 7 | env: 8 | REGISTRY: ghcr.io 9 | IMAGE_NAME: ${{ github.repository }} 10 | runs-on: ubuntu-latest 11 | name: push image 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | - name: Log in to the Container registry 16 | uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 17 | with: 18 | registry: ${{ env.REGISTRY }} 19 | username: ${{ github.actor }} 20 | password: ${{ secrets.GITHUB_TOKEN }} 21 | 22 | - name: build Docker image 23 | run: | 24 | docker pull ${REGISTRY}/${IMAGE_NAME} || true 25 | ./builder.sh build-docker-image --skip-sudo 26 | - name: push Docker image 27 | run: | 28 | TAG=${GITHUB_REF#refs/tags/} 29 | docker tag ${IMAGE_NAME} ${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA} 30 | docker tag ${IMAGE_NAME} ${REGISTRY}/${IMAGE_NAME}:${TAG} 31 | docker tag ${IMAGE_NAME} ${REGISTRY}/${IMAGE_NAME}:latest 32 | docker push ${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA} 33 | docker push ${REGISTRY}/${IMAGE_NAME}:${TAG} 34 | docker push ${REGISTRY}/${IMAGE_NAME}:latest 35 | 36 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | on: 3 | pull_request: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | test: 10 | env: 11 | REGISTRY: ghcr.io 12 | runs-on: ubuntu-latest 13 | name: test 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | 18 | - name: shellcheck 19 | run: shellcheck builder.sh example/example.sh 20 | 21 | - name: Log in to the container registry 22 | uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 23 | with: 24 | registry: ${{ env.REGISTRY }} 25 | username: ${{ github.actor }} 26 | password: ${{ secrets.GITHUB_TOKEN }} 27 | 28 | - name: test build Docker image 29 | env: 30 | IMAGE_NAME: ${{ env.REGISTRY }}/${{ github.repository }} 31 | run: | 32 | docker pull ${IMAGE_NAME} || true 33 | DOCKER_OPTS="--cache-from ${IMAGE_NAME}:latest" 34 | ./builder.sh build-docker-image --skip-sudo --docker-opts "$DOCKER_OPTS" 35 | 36 | - name: test run command in container using shell command 37 | run: | 38 | OUT=$(echo "pwd" | ./builder.sh shell --skip-sudo) 39 | if [ "$OUT" != "/workdir" ]; then 40 | echo "ERROR (shell): expected pwd in builder container to return /workdir but got $OUT" 41 | exit 1 42 | fi 43 | - name: test run command in container 44 | run: | 45 | OUT=$(./builder.sh run --skip-sudo -o workdir -- sh -c "pwd") 46 | if [ "$OUT" != "/workdir" ]; then 47 | echo "ERROR (run): expected pwd in builder container to return /workdir but got $OUT" 48 | exit 1 49 | fi 50 | 51 | - name: test build OpenWrt image 52 | env: 53 | OPENWRT_VERSION: "v21.02.0-rc4" 54 | run: | 55 | mkdir -p workdir 56 | ./builder.sh run --skip-sudo\ 57 | -o workdir\ 58 | --docker-opts "-v=$(pwd)/example:/workdir/example"\ 59 | --docker-opts "-e=OPENWRT_VERSION=${OPENWRT_VERSION}" \ 60 | -- sh -c "./example/example.sh example/config-rpi" 61 | 62 | - uses: actions/upload-artifact@v2 63 | with: 64 | name: example image 65 | path: workdir/openwrt/bin/targets/bcm27xx/bcm2709/ 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | workdir/* 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog for lede-dockercompiler 2 | 3 | ## 1.2.1 [2021-08-22] 4 | 5 | * use `exec chroot` instead of `gosu` 6 | 7 | ## 1.2.0 - [2021-08-21] 8 | 9 | * bumped to OpenWrt 21.02.0-rc4 10 | 11 | ## 1.1.0 - [2021-08-20] 12 | 13 | * bumped to OpenWrt 19.07.7 14 | * use ghcr.io container registry 15 | 16 | ## 1.0.0 - [2020-04-16] 17 | 18 | * changelog and versioning started 19 | * new optional argument `--docker-opts` 20 | * ditch travis-ci, use github actions due to travis reliability problems 21 | * added simple example script which is executed in the build container 22 | 23 | 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockerized LEDE/OpenWrt compile environment 2 | 3 | [![test](https://github.com/jandelgado/lede-dockercompiler/actions/workflows/test.yml/badge.svg)](https://github.com/jandelgado/lede-dockercompiler/actions/workflows/test.yml) 4 | 5 | A docker image to compile LEDE/OpenWrt images from source. 6 | 7 | 8 | 9 | * [Quickstart](#quickstart) 10 | * [Build and run docker image](#build-and-run-docker-image) 11 | * [Using the image](#using-the-image) 12 | * [Basic usage](#basic-usage) 13 | * [Find build configurations](#find-build-configurations) 14 | * [Compile an individual package](#compile-an-individual-package) 15 | * [Adding a new package](#adding-a-new-package) 16 | * [Build the OpenWrt SDK](#build-the-openwrt-sdk) 17 | * [Create package structure (in-tree version)](#create-package-structure-in-tree-version) 18 | * [Create package structure (custom feed version)](#create-package-structure-custom-feed-version) 19 | * [Working with patches](#working-with-patches) 20 | * [Change an existing patch](#change-an-existing-patch) 21 | * [Author and Copyright](#author-and-copyright) 22 | 23 | 24 | 25 | Note: Look [here](https://github.com/jandelgado/lede-dockerbuilder) for a 26 | version which uses the LEDE/OpenWrt imager builder, which uses pre-compiled 27 | packages to build the actual image (which is much faster, but has more 28 | limitations regarding customizations). 29 | 30 | ## Quickstart 31 | 32 | You can directly start the image builder from the github container registry 33 | ghcr.io: 34 | 35 | ``` 36 | $ mkdir -p workdir 37 | $ docker run --rm -e GOSU_UID="$(id -ur)" -e GOSU_GID="$(id -g)" \ 38 | -v $(cd workdir; pwd):/workdir:z \ 39 | -ti --rm ghcr.io/jandelgado/lede-dockercompiler:latest bash 40 | ``` 41 | 42 | This will take you to a bash shell with an OpenWrt build environment. Local 43 | directory `workdir` will be mounted to `/workdir` in the container. See below 44 | for how to use the image. 45 | 46 | ## Build and run docker image 47 | 48 | Use the `builder.sh` to build and run the docker image: 49 | 50 | ``` 51 | Dockerized OpenWRT compile environment. 52 | 53 | Usage: ./builder.sh COMMAND [OPTIONS] 54 | COMMAND is one of: 55 | build-docker-image - build docker image 56 | run CMD -- [ARGS...] - run given command in docker container 57 | shell - start shell in docker container 58 | 59 | OPTIONS: 60 | -o WORK_DIR - working directory (default /home/paco/src/lede-dockercompiler/workdir) 61 | --docker-opts OPTS - additional options to pass to docker run 62 | (can occur multiple times) 63 | --rootfs-overlay DIR - rootfs overlay directory 64 | --skip-sudo - call docker directly, without sudo 65 | 66 | Environment: 67 | IMAGE_NAME - Tag to be used for docker image. 68 | (default: jandelgado/openwrt-imagecompiler) 69 | 70 | Example: 71 | ./builder.sh shell 72 | ./builder.sh shell --docker-opts "-v=/tmp:/host-tmp" 73 | ./builder.sh run -- sh -c "cd lede && make menuconfig defconfig world" 74 | ``` 75 | 76 | First build the docker image with `./builder.sh build-docker-image`, 77 | then put your source files in the `workdir/` directory and start the actual 78 | container with the OpenWrt build environment with `./builder.sh shell`. 79 | 80 | The last command will open a shell in the docker container with local the 81 | `workdir/` mounted to the directory `/workdir` in the container. Since 82 | workdir is externally mounted, it's contents will survive container restarts. 83 | 84 | ## Using the image 85 | 86 | Some tipps on Using the OpenWrt image, working with patches and the quilt tool 87 | to build your own OpenWrt package. 88 | 89 | ### Basic usage 90 | 91 | Start a container as described above. This will take you straight into a shell 92 | in the container, with the local `workdir` directory mounted as a volume to 93 | `/workdir` inside the container. On success, you'll see a prompt like 94 | `builder@567cbabfb36b:/workdir$`. If you need to have additional files or 95 | directories available in the container, they can be mounted using the 96 | `--docker-opts` option, by providing the corresponding `docker run` mount 97 | commands. The [ci test workflow](.github/workflows/test.yml) provides an 98 | [example](example/). 99 | 100 | Now execute the following commands in the container to prepare the OpenWrt 101 | source (see [this page for more 102 | details](https://lede-project.org/docs/guide-developer/quickstart-build-images)): 103 | 104 | ``` 105 | git clone https://github.com/openwrt/openwrt lede && cd lede 106 | git checkout v19.07.2 107 | ./scripts/feeds update -a 108 | ./scripts/feeds install -a 109 | make menuconfig # 1. set target , 2. set sub target 110 | make defconfig # to set default config for target 111 | make kernel_menuconfig # optional 112 | make 113 | ``` 114 | 115 | See also [image 116 | comfiguration](https://openwrt.org/docs/guide-developer/build-system/use-buildsystem#image_configuration) 117 | in the OpenWrt documentation. 118 | 119 | The resulting images can be found in `workdir/lede/bin/target` (on the host), 120 | or in `/workdir/lede/bin/target` in the container. 121 | 122 | #### Find build configurations 123 | 124 | The originally used build configuration used to build the official OpenWrt 125 | images [can be found e.g. here](https://downloads.openwrt.org/releases/19.07.2/targets/ar71xx/generic/config.buildinfo). 126 | 127 | ### Compile an individual package 128 | 129 | ``` 130 | $ make packages/network/utils/tcpdump/{clean,compile} 131 | ``` 132 | 133 | Add `V=s` to make , e.g. `make V=s` for enhanced verbosity. 134 | 135 | ### Adding a new package 136 | 137 | This describes how to add a new OpenWrt package. We use the 138 | [udptunnel](http://www.cs.columbia.edu/~lennox/udptunnel/) tool as an 139 | example. 140 | 141 | See also 142 | 143 | * https://openwrt.org/docs/guide-developer/packages 144 | * https://github.com/openwrt/packages/blob/master/CONTRIBUTING.md 145 | * https://openwrt.org/docs/guide-developer/build-system/use-buildsystem 146 | 147 | #### Build the OpenWrt SDK 148 | 149 | First we need to build the OpenWrt SDK: 150 | 151 | ```bash 152 | $ make tools/install 153 | $ make toolchain/install 154 | ``` 155 | 156 | #### Create package structure (in-tree version) 157 | 158 | We need to create a directory in a suitable place under the `package/` 159 | directory and create at least a [Makefile as described 160 | here.](https://openwrt.org/docs/guide-developer/packages). We will place our 161 | package in `package/network/util/udptunnel`. 162 | 163 | ``` 164 | udptunnel 165 | ├── Makefile 166 | └── patches 167 | ├── 001-multicast.patch 168 | └── 002-main_code_fix.patch 169 | ``` 170 | 171 | Build the package with 172 | 173 | ``` 174 | $ make packages/network/utils/tcpdump/{clean,compile} 175 | ``` 176 | 177 | #### Create package structure (custom feed version) 178 | 179 | This time we place the package in a custom feed, outside the OpenWrt root. We 180 | put our package to `/workdir/myfeed/net/udptunnel` (container path). 181 | 182 | The custom feed needs to be added to `feeds.conf.default`: 183 | 184 | ``` 185 | src-link myfeed /workdir/myfeed 186 | ``` 187 | 188 | Install the feed with 189 | 190 | ``` bash 191 | $ ./scripts/feed update myfeed && ./scripts/feed install -a myfeed` 192 | ``` 193 | 194 | Now run `make menuconfig` and activate the custom feed under `[*] Image 195 | configuration` -> `[*] Separate feed repositories` -> `<*> enable feed myfeed`. 196 | 197 | The package should now be available within the `Network` category (because we 198 | chose `Network` as category in the Makefile). Compile the package with 199 | 200 | ```bash 201 | $ make package/udptunnel/{clean,compile} 202 | ``` 203 | 204 | See [OpenWrt Hello, 205 | world!](https://openwrt.org/docs/guide-developer/helloworld/start) for an 206 | in-depth description. 207 | 208 | ### Working with patches 209 | 210 | (Adapted from https://openwrt.org/docs/guide-developer/patches) 211 | 212 | To make the package udptunnel compile properly, we need to patch tbefore. 213 | OpenWrt uses the [quilt](https://en.wikipedia.org/wiki/Quilt_(software) quilt 214 | tool for patch management. 215 | 216 | From the root of your OpenWrt tree, execute: 217 | 218 | ``` 219 | $ make package/network/util/udptunnel/{clean,prepare} V=s QUILT=1 220 | ``` 221 | 222 | Then `cd` into the prepared source directory with 223 | ``` 224 | $ cd build_dir/target-*/udptunnel-* 225 | ``` 226 | 227 | First we have to apply existing patches (in case your are working on an 228 | exisiting OpenWrt package which already contains patches): 229 | 230 | ``` 231 | $ quilt push -a 232 | ``` 233 | 234 | Then start the first patch: 235 | 236 | ``` 237 | $ quilt new 010-main_code_fix.patch 238 | Patch patches/010-main_code_fix.patch is now on top 239 | ``` 240 | 241 | Now edit the sources using `quilt edit`, in our case we will edit the file 242 | `host2ip.c`: 243 | 244 | ``` 245 | $ quilt edit host2ip.c 246 | File host2ip.c added to patch patches/010-main_code_fix.patch 247 | ``` 248 | 249 | The `quilt` command will automatically start an editor for you, according your 250 | [~/.quiltc file](https://openwrt.org/docs/guide-developer/build-system/use-patches-with-buildsystem#prepare_quilt_configuration). 251 | 252 | Check the changes with `quilt diff` and `quilt files`. If everything is ok, 253 | we can update the patch file, `010-main_code_fix.patch`: 254 | 255 | ``` 256 | $ quilt refresh 257 | ``` 258 | 259 | Change back to root of your OpenWrt tree and update the package with the 260 | patch: 261 | 262 | ``` 263 | $ (cd ../../.. && make package/network/utils/udptunnel/update V=s) 264 | make[1]: Entering directory '/workdir/lede' 265 | make[2]: Entering directory '/workdir/lede/package/network/utils/udptunnel' 266 | if [ -s "/workdir/lede/build_dir/target-mipsel_24kc_musl/udptunnel-full/udptunnel-1.1/patches/series" ]; then (cd "/workdir/lede/build_dir/target-mipsel_24kc_musl/udptunnel-full/udptunnel-1.1"; if quilt --quiltrc=- next >/dev/null 2>&1; then quilt --quiltrc=- push -a; else quilt --quiltrc=- top >/dev/null 2>&1; fi ); fi 267 | touch "/workdir/lede/build_dir/target-mipsel_24kc_musl/udptunnel-full/udptunnel-1.1/.quilt_checked" 268 | mkdir -p ./patches 269 | rm -f ./patches/* 2>/dev/null >/dev/null 270 | '/workdir/lede/build_dir/target-mipsel_24kc_musl/udptunnel-full/udptunnel-1.1/patches/010-main_code_fix.patch' -> './patches/010-main_code_fix.patch' 271 | make[2]: Leaving directory '/workdir/lede/package/network/utils/udptunnel' 272 | time: package/network/utils/udptunnel/full/update#0.07#0.04#0.12 273 | make[1]: Leaving directory '/workdir/lede' 274 | ``` 275 | 276 | As you can see, the patch `010-main_code_fix.patch` was applied. 277 | 278 | Now the patched package can be built: 279 | 280 | ``` 281 | $ (cd ../../.. && make package/network/utils/udptunnel/{clean,compile} V=s) 282 | ``` 283 | 284 | Depending on your architecture, the resulting `ipk` package can be found under 285 | `bin/packages//base`, e.g. 286 | `./bin/packages/mipsel_24kc/base/udptunnel_1.1-1_mipsel_24kc.ipk`. 287 | 288 | #### Change an existing patch 289 | 290 | The workflow to change an exisiting patch is similar to the above described 291 | workflow: 292 | 293 | ``` 294 | # start in root of your OpenWrt source tree 295 | $ make package/network/utils/udptunnel/{clean,compile} V=s 296 | $ cd build_dir/target-*/udptunnel-* 297 | $ quilt series 298 | 001-multicast.patch 299 | 002-main_code_fix.patch 300 | $ quilt push 002-main_code_fix.patch 301 | $ quilt edit udptunnel.c 302 | $ quilt diff 303 | $ quilt refresh 304 | $ ( cd ../../.. && make package/network/utils/udptunnel/update V=s ) # apply patches 305 | $ ( cd ../../.. && make package/network/utils/udptunnel/{clean,compile} V=s ) 306 | ``` 307 | 308 | ## Author and Copyright 309 | 310 | (C) Copyright 2019-2020 Jan Delgado 311 | 312 | -------------------------------------------------------------------------------- /builder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Docker based LEDE/OpenWRT build environment 3 | # (c) 2019-2020 Jan Delgado 4 | set -euo pipefail 5 | 6 | DEF_IMAGE_NAME=ghcr.io/jandelgado/lede-dockercompiler 7 | IMAGE_NAME=${IMAGE_NAME:-$DEF_IMAGE_NAME} 8 | SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 9 | WORK_DIR=$SCRIPT_DIR/workdir 10 | 11 | function usage { 12 | cat<&2 76 | exit 1 77 | } 78 | 79 | if [ $# -lt 1 ]; then 80 | usage "$0" 81 | exit 0 82 | fi 83 | 84 | COMMAND=$1; shift 85 | SUDO=sudo 86 | DOCKER_OPTS=() 87 | 88 | # parse cli args, can override config file params 89 | while [[ $# -ge 1 ]]; do 90 | key="$1" 91 | case $key in 92 | -o) WORK_DIR="$2"; shift ;; 93 | --rootfs-overlay) ROOTFS_OVERLAY="$2"; shift ;; 94 | --skip-sudo) SUDO="" ;; 95 | --docker-opts) DOCKER_OPTS+=("$2"); shift ;; 96 | --) shift; break ;; 97 | *) fail "invalid option: $key";; 98 | esac 99 | shift 100 | done 101 | 102 | [ ! -d "$WORK_DIR" ] && fail "output-dir: no such directory $WORK_DIR" 103 | [ -n "${ROOTFS_OVERLAY+x}" ] && [ ! -d "$ROOTFS_OVERLAY" ] && fail "roofs-overlay: no such directory $ROOTFS_OVERLAY" 104 | 105 | case $COMMAND in 106 | build-docker-image) 107 | build_docker_image ;; 108 | run) 109 | run_cmd_in_container "$@" ;; 110 | shell) 111 | run_cmd_in_container bash ;; 112 | *) usage "$0"; exit 0 ;; 113 | esac 114 | 115 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | LABEL maintainer "Jan Delgado " 3 | 4 | RUN apt-get update \ 5 | && apt-get install -y build-essential libncurses5-dev wget \ 6 | zlib1g-dev gawk gcc-multilib flex git-core gettext libssl-dev unzip \ 7 | python3 python3-distutils python rsync\ 8 | && rm -rf /var/cache/apk/* \ 9 | && mkdir /workdir /lede 10 | 11 | ADD home/ /lede 12 | ADD usr/local/bin/entrypoint.sh /usr/local/bin/ 13 | RUN chmod 755 /usr/local/bin/entrypoint.sh 14 | 15 | WORKDIR "/workdir" 16 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 17 | CMD ["/bin/bash"] 18 | 19 | -------------------------------------------------------------------------------- /docker/home/.bashrc: -------------------------------------------------------------------------------- 1 | export PATH=$PATH:/workdir/lede/staging_dir/host/bin 2 | 3 | -------------------------------------------------------------------------------- /docker/home/.quiltrc: -------------------------------------------------------------------------------- 1 | QUILT_DIFF_ARGS="--no-timestamps --no-index -p ab --color=auto" 2 | QUILT_REFRESH_ARGS="--no-timestamps --no-index -p ab" 3 | QUILT_SERIES_ARGS="--color=auto" 4 | QUILT_PATCH_OPTS="--unified" 5 | QUILT_DIFF_OPTS="-p" 6 | EDITOR="vi" 7 | -------------------------------------------------------------------------------- /docker/usr/local/bin/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # If GOSU_UID:GOSU_GID environment variable set to something other than 0:0 (root:root), 5 | # become user:group set within and exec command passed in args 6 | if [ "$GOSU_UID:$GOSU_GID" != "0:0" ] && [ "$GOSU_UID:$GOSU_GID" != ":" ]; then 7 | export HOME="/lede" 8 | 9 | # only needed when run with docker 10 | if [ -f /.dockerenv ]; then 11 | chown -R "$GOSU_UID:$GOSU_GID" /lede 12 | fi 13 | groupadd -f -g "$GOSU_GID" builder 14 | useradd -u "$GOSU_UID" -g "$GOSU_GID" -s /bin/bash -d "/lede" builder || : 15 | exec chroot --userspec "$GOSU_UID:$GOSU_GID" --skip-chdir / "$@" 16 | fi 17 | 18 | # If GOSU_UID:GOSU_GID was 0:0 exec command passed in args 19 | # without gosu (assume already root) 20 | exec "$@" 21 | -------------------------------------------------------------------------------- /example/config-rpi: -------------------------------------------------------------------------------- 1 | CONFIG_TARGET_bcm27xx=y 2 | CONFIG_TARGET_bcm27xx_bcm2709=y 3 | CONFIG_TARGET_bcm27xx_bcm2709_DEVICE_rpi-2=y 4 | -------------------------------------------------------------------------------- /example/example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script is run in the container and demonstrates a typical OpenWrt 4 | # build session. Currently it is called from the ci. 5 | # 6 | # usage: example.sh CONFIG-FILE 7 | # where CONFIG-FILE is an OpenWrt .config file 8 | # 9 | # Environment variables: 10 | # OPENWRT_VERSION - Version to check out, defaults to v19.07.7 11 | 12 | set -eou pipefail 13 | 14 | OPENWRT_VERSION=${OPENWRT_VERSION:-v19.07.7} 15 | 16 | if [ ! -d openwrt ]; then 17 | git clone --depth 1 --branch "$OPENWRT_VERSION" https://github.com/openwrt/openwrt 18 | fi 19 | 20 | cp "$1" openwrt/.config 21 | cd openwrt 22 | git pull 23 | 24 | ./scripts/feeds update -a 25 | ./scripts/feeds install -a 26 | 27 | # expand configuration 28 | make defconfig 29 | # build 30 | make -j $(( $(nproc) + 1)) 31 | 32 | -------------------------------------------------------------------------------- /workdir/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | */ 3 | !.gitignore 4 | --------------------------------------------------------------------------------