Skip to content

Commit

Permalink
切换到构建ubuntu的deb
Browse files Browse the repository at this point in the history
  • Loading branch information
Seshiria committed Jul 3, 2024
1 parent 8c6e055 commit f4c2cb8
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 84 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/*.*"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM centos:7
FROM ubuntu:22.04

ADD ./file /file

Expand Down
5 changes: 2 additions & 3 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -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/ ./
docker run --name nginx-build nginx-build bash -x /file/run.sh
docker cp nginx-build:/root/build/release/ ./
2 changes: 1 addition & 1 deletion file/add/headers-more-nginx-module.add
Original file line number Diff line number Diff line change
Expand Up @@ -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"
ADDCONFIG "--add-module=\$(CURDIR)\/debian\/modules\/headers-more-nginx-module"
11 changes: 8 additions & 3 deletions file/add/ngx_brotli.add
Original file line number Diff line number Diff line change
@@ -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"
ADDCONFIG "--add-module=\$(CURDIR)\/debian\/modules\/ngx_brotli"
18 changes: 8 additions & 10 deletions file/configure
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
#exit 0
46 changes: 25 additions & 21 deletions file/install.so
Original file line number Diff line number Diff line change
@@ -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
git \
debhelper \
quilt \
libssl-dev \
libpcre2-dev \
zlib1g-dev
58 changes: 16 additions & 42 deletions file/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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/

0 comments on commit f4c2cb8

Please sign in to comment.