云樾
踏浪而来
云樾

利用Github Actions云编译并自定义OpenWrt固件

自从得知可以使用Github Actions 云编译OpenWrt固件后,喜出望外,再也不需要在本地Ubuntu里折腾了,还可避免因无法全局科学出国而引起的编译失败。

首先需要fork大佬的固件,也可clone后自行修改,然后再push到GayHub。

我这里选择Lienol定制的Lean-Lede固件:

修改workflow

修改/.github/workflow/下的yml文件,可以直接复制下面我修改后的workflow。

此处关键在于固件定制部分的自定义。

使用make menuconfig 选择好相关配置后,将 /.config 中相应的配置条目复制到workflow中固件定制部分的对应位置。

下面是我修改后workflow,已编译成功,链接

name: Jarvis-OpenWrt-CI

    on:
      push:
        branches: 
          # master为你需要编译的当前固件的分支
          - master
      schedule:
        - cron: 0 20 * * *
      # release:
      #   types: [published]

    jobs:

      build:

        runs-on: ubuntu-latest

        steps:

          - name: Checkout
            uses: actions/checkout@master
            # with中的master为你需要编译的当前固件的分支
            with:
              ref: master

          - name: Space cleanup
            env:
              DEBIAN_FRONTEND: noninteractive
            run: |
              docker rmi docker images -q
              sudo rm -rf /usr/share/dotnet /etc/mysql /etc/php /etc/apt/sources.list.d
              sudo -E apt-get -y purge azure-cli ghc* zulu* hhvm llvm* firefox google* dotnet* powershell openjdk* mysql* php*
              sudo -E apt-get update
              sudo -E apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler
              sudo -E apt-get -y autoremove --purge
              sudo -E apt-get clean
              # sudo mkdir -p -m 777 /mnt/openwrt/bin /mnt/openwrt/build_dir/host /mnt/openwrt/build_dir/hostpkg /mnt/openwrt/dl /mnt/openwrt/feeds /mnt/openwrt/staging_dir
              # ln -s /mnt/openwrt/bin ./bin
              # mkdir -p ./build_dir/host && ln -s /mnt/openwrt/build_dir/host ./build_dir/host
              # mkdir -p ./build_dir/host && ln -s /mnt/openwrt/build_dir/hostpkg ./build_dir/hostpkg
              # ln -s /mnt/openwrt/dl ./dl
              # ln -s /mnt/openwrt/feeds ./feeds
              # ln -s /mnt/openwrt/staging_dir ./staging_dir
              df -h
          - name: Update feeds
            run: |
              ./scripts/feeds update -a
              ./scripts/feeds install -a
          - name: Generate configuration file
            run: |
              rm -f ./.config*
              touch ./.config
              #
              # ========================固件定制部分========================
              # 
              # 
              # 如果不对本区块做出任何编辑, 则生成默认配置固件. 
              # 
              # 以下为定制化固件选项和说明:
              #
              #
              # 有些插件/选项是默认开启的, 如果想要关闭, 请参照以下示例进行编写:
              # 
              #          =========================================
              #         |  # 取消编译VMware镜像:                   |
              #         |  cat >> .config <<EOF                   |
              #         |  # CONFIG_VMDK_IMAGES is not set        |
              #         |  EOF                                    |
              #          =========================================
              #
              # 
              # 以下是一些提前准备好的一些插件选项.
              # 直接取消注释相应代码块即可应用. 不要取消注释代码块上的汉字说明.
              # 如果不需要代码块里的某一项配置, 只需要删除相应行.
              #
              # 如果需要其他插件, 请按照示例自行添加.
              # 注意, 只需添加依赖链顶端的包. 如果你需要插件 A, 同时 A 依赖 B, 即只需要添加 A.
              # 
              # 无论你想要对固件进行怎样的定制, 都需要且只需要修改 EOF 回环内的内容.
              # 
              # 编译x64固件:
              cat >> .config <<EOF
              CONFIG_TARGET_x86=y
              CONFIG_TARGET_x86_64=y
              CONFIG_TARGET_x86_64_Generic=y
              EOF
              # 固件压缩, 编译ext4格式固件
                        # 注意如果选的插件数目多,CONFIG_TARGET_ROOTFS_PARTSIZE要设置大一些
              cat >> .config <<EOF
              CONFIG_TARGET_ROOTFS_EXT4FS=y
              CONFIG_TARGET_IMAGES_GZIP=y
              CONFIG_TARGET_ROOTFS_PARTSIZE=800
              EOF
              # 编译UEFI固件:
              # cat >> .config <<EOF
              # CONFIG_EFI_IMAGES=y
              # EOF
              # IPv6支持:
              # cat >> .config <<EOF
              # CONFIG_PACKAGE_dnsmasq_full_dhcpv6=y
              # CONFIG_PACKAGE_ipv6helper=y
              # EOF
              # 多文件系统支持:
              cat >> .config <<EOF
              CONFIG_PACKAGE_kmod-fs-nfs=y
              CONFIG_PACKAGE_kmod-fs-nfs-common=y
              CONFIG_PACKAGE_kmod-fs-nfs-v3=y
              CONFIG_PACKAGE_kmod-fs-nfs-v4=y
              CONFIG_PACKAGE_kmod-fs-ntfs=y
              CONFIG_PACKAGE_kmod-fs-squashfs=y
              EOF
              # USB3.0支持:
              cat >> .config <<EOF
              CONFIG_PACKAGE_kmod-usb-ohci=y
              CONFIG_PACKAGE_kmod-usb-ohci-pci=y
              CONFIG_PACKAGE_kmod-usb2=y
              CONFIG_PACKAGE_kmod-usb2-pci=y
              CONFIG_PACKAGE_kmod-usb3=y
              EOF
              # 常用LuCI插件选择, 主要定制passwall与ssr-plus
              cat >> .config <<EOF
              CONFIG_PACKAGE_luci-app-adbyby-plus=y
              CONFIG_PACKAGE_luci-app-aria2=y
              CONFIG_PACKAGE_luci-app-baidupcs-web=y
              CONFIG_PACKAGE_luci-app-docker=y
              CONFIG_PACKAGE_luci-app-frpc=y
              CONFIG_PACKAGE_luci-app-kodexplorer=y
              CONFIG_PACKAGE_luci-app-minidlna=y
              CONFIG_PACKAGE_luci-app-openvpn=y
              CONFIG_PACKAGE_luci-app-openvpn-server=y
              CONFIG_PACKAGE_luci-app-passwall=y
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ipt2socks=y
              # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks is not set
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR=y
              # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks_socks is not set
              # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR_socks is not set
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_V2ray=y
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan=y
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Brook=y
              # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_kcptun is not set
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_haproxy=y
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ChinaDNS_NG=y
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_pdnsd=y
              CONFIG_PACKAGE_luci-app-passwall_INCLUDE_dns2socks=y
              # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_v2ray-plugin is not set
              # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_simple-obfs is not set
              CONFIG_PACKAGE_luci-app-qbittorrent=y
              CONFIG_PACKAGE_luci-app-ssr-plus=y
              CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Shadowsocks=y
              CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Simple_obfs=y
              CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray_plugin=y
              CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray=y
              CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan=y
              # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Kcptun is not set
              CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_ShadowsocksR_Server=y
              CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_ShadowsocksR_Socks=y
              CONFIG_PACKAGE_luci-app-ttyd=y
              CONFIG_PACKAGE_luci-app-v2ray-server=y
              CONFIG_PACKAGE_luci-app-verysync=y
              CONFIG_PACKAGE_luci-app-webadmin=y
              CONFIG_PACKAGE_luci-app-wireguard=y
              CONFIG_PACKAGE_luci-app-wrtbwmon=y
              EOF
              # LuCI主题:
              cat >> .config <<EOF
              CONFIG_PACKAGE_luci-theme-argon-dark-mod=y
              CONFIG_PACKAGE_luci-theme-argon-light-mod=y
              CONFIG_PACKAGE_luci-theme-material=y
              CONFIG_PACKAGE_luci-theme-netgear=y
              EOF
              # 常用软件包:
              cat >> .config <<EOF
              CONFIG_PACKAGE_curl=y
              CONFIG_PACKAGE_htop=y
              CONFIG_PACKAGE_nano=y
              CONFIG_PACKAGE_screen=y
              CONFIG_PACKAGE_tree=y
              CONFIG_PACKAGE_vim-fuller=y
              CONFIG_PACKAGE_wget=y
              EOF
              # 取消编译VMware镜像以及镜像填充 (不要删除被缩进的注释符号):
              # cat >> .config <<EOF
              # # CONFIG_TARGET_IMAGES_PAD is not set
              # # CONFIG_VMDK_IMAGES is not set
              # EOF
              # 
              # ========================固件定制部分结束========================
              # 
              sed -i 's/^[ \\t]*//g' ./.config
              make defconfig
          - name: Make download
            run: |
              make download -j8
              find ./dl/ -size -1024c -exec rm -f {} \\;
              df -h
          - name: Compile firmware
            run: |
              make -j$(nproc) || make -j1 V=s
              echo "======================="
              echo "Space usage:"
              echo "======================="
              df -h
              echo "======================="
              du -h --max-depth=1 ./ --exclude=build_dir --exclude=bin
              du -h --max-depth=1 ./build_dir
              du -h --max-depth=1 ./bin
          # - name: Prepare artifact
          #   run: find ./bin/targets/ -type d -name "packages" | xargs rm -rf {}

          # 因为我需要得到编译后的ipk插件,所以我选择将完整的/bin/上传
          - name: Upload artifact
            uses: actions/upload-artifact@master
            with:
              name: OpenWrt firmware
              path: ./bin/

修改workflow后,actions中会自动开始编译,成功后即可下载编译完成的固件压缩包。

https://cdn.imcavoy.com/images/20200304133118.png#vwid=2880&vhei=1236

附录

OpenWrt固件版本区分

这里参考恩山社区的回答。

https://cdn.imcavoy.com/images/20200304124314.png#vwid=1200&vhei=1118

声明:转载文章《利用Github Actions云编译并自定义OpenWrt固件》请务必注明出处,谢谢
# #
首页      技术笔记      利用Github Actions云编译并自定义OpenWrt固件

发表评论

textsms
account_circle
email

  • sacai

    点进去https://github.com/Lienol/openwrt/tree/dev-19.07/.github 根本就没有.yml的文件。。。

    1年前 回复
    • 玄霄博主

      @sacai: yml文件写法参考这个:https://github.com/KFERMercer/OpenWrt-CI,大佬仓库的yml文件可能删了

      1年前 回复
  • Yhua

    兄嘚~~你的工程你的源码,编译失败

    1年前 回复
    • 玄霄博主

      @Yhua: 合并大佬分支没那么勤快 :&(蛆音娘_OK) 可能配置项有更改,我有空重新拉一下

      1年前 回复

云樾

利用Github Actions云编译并自定义OpenWrt固件
自从得知可以使用Github Actions 云编译OpenWrt固件后,喜出望外,再也不需要在本地Ubuntu里折腾了,还可避免因无法全局科学出国而引起的编译失败。 首先需要fork大佬的固件,也可clone后…
扫描二维码继续阅读
2020-03-04