From f4c2cb8d538ae51560ef744d3fbd1c842eecafbc Mon Sep 17 00:00:00 2001 From: Seshiria <57834968+Seshiria@users.noreply.github.com> Date: Wed, 3 Jul 2024 20:13:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=B0=E6=9E=84=E5=BB=BAub?= =?UTF-8?q?untu=E7=9A=84deb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 6 +-- Dockerfile | 2 +- ci.sh | 5 +-- file/add/headers-more-nginx-module.add | 2 +- file/add/ngx_brotli.add | 11 +++-- file/configure | 18 ++++---- file/install.so | 46 ++++++++++---------- file/run.sh | 58 +++++++------------------- 8 files changed, 64 insertions(+), 84 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 19b7c23..80913df 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,10 +3,10 @@ on: workflow_dispatch: push: branches: - - master + - ubuntu jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -19,7 +19,7 @@ jobs: uses: ncipollo/release-action@v1.7.3 with: allowUpdates: true - tag: "test" + tag: "ubuntu" body: ${{ github.event.release.body }} prerelease: "true" artifacts: "x86_64/*.*" diff --git a/Dockerfile b/Dockerfile index f62dd01..c878069 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM centos:7 +FROM ubuntu:22.04 ADD ./file /file diff --git a/ci.sh b/ci.sh index c9b176a..1a42c90 100644 --- a/ci.sh +++ b/ci.sh @@ -1,7 +1,6 @@ #/bin/bash set -ex cd ${GITHUB_WORKSPACE} -docker pull centos:7 docker build -t nginx-build . -docker run --name nginx-build nginx-build sh -x /file/run.sh -docker cp nginx-build:/root/rpmbuild/RPMS/x86_64/ ./ \ No newline at end of file +docker run --name nginx-build nginx-build bash -x /file/run.sh +docker cp nginx-build:/root/build/release/ ./ \ No newline at end of file diff --git a/file/add/headers-more-nginx-module.add b/file/add/headers-more-nginx-module.add index 15c1227..8d954c5 100644 --- a/file/add/headers-more-nginx-module.add +++ b/file/add/headers-more-nginx-module.add @@ -6,4 +6,4 @@ if [ -e headers-more-nginx-module/ ];then else git clone --depth=1 https://github.com/openresty/headers-more-nginx-module.git fi -ADDCONFIG "--add-module=./headers-more-nginx-module" \ No newline at end of file +ADDCONFIG "--add-module=\$(CURDIR)\/debian\/modules\/headers-more-nginx-module" \ No newline at end of file diff --git a/file/add/ngx_brotli.add b/file/add/ngx_brotli.add index dda080b..e05921d 100644 --- a/file/add/ngx_brotli.add +++ b/file/add/ngx_brotli.add @@ -1,10 +1,15 @@ #/bin/bash +apt install -y cmake if [ -e ngx_brotli/ ];then cd ./ngx_brotli git pull &&git submodule update --init --depth=1 cd .. else - git clone --depth=1 https://github.com/eustas/ngx_brotli.git --recurse-submodules - #cd ngx_brotli && git submodule update --init --depth=1 && cd ../ + git clone --depth=1 https://github.com/Seshiria/ngx_brotli.git --recurse-submodules + cd ./ngx_brotli && git submodule update --init + cd deps/brotli/ + mkdir out && cd out + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. + cmake --build . --config Release --target brotlienc fi -ADDCONFIG "--add-module=./ngx_brotli" \ No newline at end of file +ADDCONFIG "--add-module=\$(CURDIR)\/debian\/modules\/ngx_brotli" \ No newline at end of file diff --git a/file/configure b/file/configure index 9051cbc..897d6b1 100644 --- a/file/configure +++ b/file/configure @@ -1,5 +1,4 @@ #/bin/bash -#idtmp=$(ls ~/rpmbuild/SOURCES |grep "nginx-"*".tar.gz"|awk -F '-' "{print \$2}"|awk -F '.' "{print "\$1"\".\""\$2"\".\""\$3"}") buildpath=`pwd` readonly buildpath echo $buildpath @@ -10,22 +9,21 @@ ADDCONFIG(){ } #加载添加模块的初始化脚本 #缓存模块文件,避免开发时候多次拉取模块 -mkdir ~/gitfile -cd ~/gitfile +mkdir ~/build/gitfile +cd ~/build/gitfile for addmodular in $(find /file/add/ -name "*.add") ;do echo 当前加载扩展:${addmodular} #read -s -n1 -p "按任意键继续 ... " source ${addmodular} - cd ~/gitfile + cd ~/build/gitfile done #复制添加的模块文件到指定目录 -cp -R ~/gitfile/* ${buildpath} +mkdir ${buildpath}/debian/modules/ +cp -R ~/build/gitfile/* ${buildpath}/debian/modules/ #初始化模块后需要回到nginx的源码根目录 cd ${buildpath} -./configured ${BASE_CONFIGURE_ARGS} \ - --with-cc-opt="${WITH_CC_OPT}" \ - --with-ld-opt="${WITH_LD_OPT}" \ - ${MAKE_ADD_CONFIG} +sed -i "/CFLAGS=/s/\$/ ${MAKE_ADD_CONFIG}/" "${buildpath}/debian/rules" + #read -s -n1 -p "按任意键继续 ... " -exit 0 \ No newline at end of file +#exit 0 \ No newline at end of file diff --git a/file/install.so b/file/install.so index c7674be..12d7fae 100644 --- a/file/install.so +++ b/file/install.so @@ -1,25 +1,29 @@ #!/bin/bash #系统检查 set -ex -(cat /etc/*-release |grep centos |grep 7) || (echo "仅支持centos 7 !请检测系统版本。"&& exit 1 ) -#启用nginx官方的repo -cat << 'EOF' > /etc/yum.repos.d/nginx.repo -[nginx] -name=nginx repo -baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ -gpgcheck=0 -enabled=1 -EOF -#新版本git -#curl https://setup.ius.io/ | bash||(echo "无法获取新版本git" && exit 1) -#nginx编译依赖 -yum install -y \ - git2u \ - gcc \ - openssl-devel \ - pcre-devel \ +(cat /etc/*-release |grep ubuntu) || (echo "仅支持ubuntu !请检测系统版本。"&& exit 1 ) +apt update +#nginx 依赖 +#https://nginx.org/en/linux_packages.html#Ubuntu +apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring -y +curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ + | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null +(gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg |grep -q "573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62") || (echo "nginx库签名密钥验证失败" && exit 1) +#配置为stable +echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ +http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ + | tee /etc/apt/sources.list.d/nginx.list +echo "deb-src [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ +http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ + | tee /etc/apt/sources.list.d/nginx-src.list +echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \ + | tee /etc/apt/preferences.d/99nginx +#编译依赖 +apt install -y \ make \ - rpm-build \ - git -#清理 -yum clean all \ No newline at end of file + git \ + debhelper \ + quilt \ + libssl-dev \ + libpcre2-dev \ + zlib1g-dev \ No newline at end of file diff --git a/file/run.sh b/file/run.sh index 11d3f15..3212ec2 100644 --- a/file/run.sh +++ b/file/run.sh @@ -5,46 +5,20 @@ if [ -f /file/install.so ];then mv /file/install.so /file/install exit 0 fi -mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} -cd ~/rpmbuild/SOURCES/ -rm -rf ~/rpmbuild/SOURCES/* +mkdir -p ~/build/ +cd ~/build/ +rm -rf ~/build/* #获取nginx源码 -NGINX_VERSION=$(yum list nginx |grep nginx |awk -F ':' '{print $2}'|awk -F ' ' '{print $1}') -if [ -f /file/nginx-${NGINX_VERSION}.src.rpm ];then - cp /file/nginx-${NGINX_VERSION}.src.rpm ./ -else - curl -O http://nginx.org/packages/centos/7/SRPMS/nginx-${NGINX_VERSION}.src.rpm -fi -rpm2cpio nginx-${NGINX_VERSION}.src.rpm |cpio -dvi -#hook nginx.spec 文件 -#hook %setup宏 -#sed -i '/cp %{SOURCE2} ./a\. /file/hook.sh' nginx.spec -if `grep -q "%autosetup" nginx.spec` ;then - #nginx version 1.20.0 and up - sed -i -e '/%autosetup -p1/a\mv ./configure ./configured \ncp /file/configure ./configure \nchmod +x ./configure\n#hockpoint' \ - -e '/%build/a\export BASE_CONFIGURE_ARGS=%{BASE_CONFIGURE_ARGS} \nexport WITH_CC_OPT="\%{WITH_CC_OPT}\" \nexport WITH_LD_OPT=\"%{WITH_LD_OPT}\"' \ - nginx.spec -elif `grep -q "%setup" nginx.spec ` ;then - #nginx version 1.18.0 and lower - sed -i -e '/cp %{SOURCE2} ./a\mv ./configure ./configured \ncp /file/configure ./configure \nchmod +x ./configure\n#hockpoint' \ - -e '/%build/a\export BASE_CONFIGURE_ARGS=%{BASE_CONFIGURE_ARGS} \nexport WITH_CC_OPT="\%{WITH_CC_OPT}\" \nexport WITH_LD_OPT=\"%{WITH_LD_OPT}\"' \ - nginx.spec -else - echo "error:Unsupported nginx.spec, the following information may be useful" - echo "--------------------------------------------" - #cat nginx.spec - echo "--------------------------------------------" - exit 1 -fi -#check -if `grep -q "#hockpoint" nginx.spec` ;then - echo "hock point check is ok" -else - echo "error: hock point not written" - echo "Please check nginx.spec,the following information may be useful" - echo "--------------------------------------------" - cat nginx.spec - echo "--------------------------------------------" - exit 1 -fi -rpmbuild -ba nginx.spec \ No newline at end of file +apt update +NGINX_VERSION=$(apt list nginx |grep nginx |awk -F ' ' '{print $2}'|awk -F '~' '{print $1}') +NGINX_VERSION_MAIN=$(echo "$NGINX_VERSION" |awk -F '-' '{print $1}') +apt source nginx +cd nginx-"${NGINX_VERSION_MAIN}" + +. /file/configure + +dpkg-buildpackage -uc -b +#发布文件 +cd ~/build/ +mkdir release +mv *.deb release/