Added ability build for custom nginx version for distributive build
This commit is contained in:
8
BUILD.md
8
BUILD.md
@@ -29,6 +29,14 @@ To build the package, run the command:
|
|||||||
bash package_preparer.sh prepare "almalinux:9"
|
bash package_preparer.sh prepare "almalinux:9"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or if a specific nginx version is required for the distribution, use this command:
|
||||||
|
|
||||||
|
```
|
||||||
|
bash package_preparer.sh prepare "almalinux:9" "1.30.2"
|
||||||
|
```
|
||||||
|
|
||||||
|
in this case the module will be built for nginx=1.30.2.
|
||||||
|
|
||||||
The build was tested on the following images:
|
The build was tested on the following images:
|
||||||
|
|
||||||
* almalinux:9
|
* almalinux:9
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ docker run --name nginx-mod_rewrite -p 8080:80 -p 8081:8081 nginx-mod_rewrite
|
|||||||
bash package_preparer.sh prepare "almalinux:9"
|
bash package_preparer.sh prepare "almalinux:9"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
или если для дистрибутива нужна конкретная версия nginx, то такая команда:
|
||||||
|
|
||||||
|
```
|
||||||
|
bash package_preparer.sh prepare "almalinux:9" "1.30.2"
|
||||||
|
```
|
||||||
|
|
||||||
|
в этом случае будет собран модуль, для nginx=1.30.2.
|
||||||
|
|
||||||
Сборка проверялась на образах:
|
Сборка проверялась на образах:
|
||||||
|
|
||||||
* almalinux:9
|
* almalinux:9
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ function download_nginx() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
echo "Built for nginx ${NGINX_VER}" > BUILDINFO.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND="$1"
|
COMMAND="$1"
|
||||||
@@ -56,6 +57,7 @@ case "$COMMAND" in
|
|||||||
prepare)
|
prepare)
|
||||||
|
|
||||||
DOCKER_IMAGE="$2"
|
DOCKER_IMAGE="$2"
|
||||||
|
NGINX_CUSTOM_VER="$3"
|
||||||
|
|
||||||
if [ -z "$DOCKER_IMAGE" ]; then
|
if [ -z "$DOCKER_IMAGE" ]; then
|
||||||
echo "Set docker image for build"
|
echo "Set docker image for build"
|
||||||
@@ -153,6 +155,9 @@ EOF
|
|||||||
# Copy Dockerfile into tmpbuild and replace placeholder image name
|
# Copy Dockerfile into tmpbuild and replace placeholder image name
|
||||||
cp packages/Dockerfile tmpbuild/Dockerfile
|
cp packages/Dockerfile tmpbuild/Dockerfile
|
||||||
sed -i "s|^FROM image|FROM ${DOCKER_IMAGE}|g" tmpbuild/Dockerfile
|
sed -i "s|^FROM image|FROM ${DOCKER_IMAGE}|g" tmpbuild/Dockerfile
|
||||||
|
if [ -n "$NGINX_CUSTOM_VER" ]; then
|
||||||
|
sed -i "s|^ENTRYPOINT \[ \"bash\", \"package_preparer.sh\", \"packageprep\" \]|ENTRYPOINT [ \"bash\", \"package_preparer.sh\", \"packageprep\", \"$NGINX_CUSTOM_VER\" ]|g" tmpbuild/Dockerfile
|
||||||
|
fi
|
||||||
|
|
||||||
# Build a temporary Docker image based on the provided base image
|
# Build a temporary Docker image based on the provided base image
|
||||||
docker build -t tmpbuild_image -f tmpbuild/Dockerfile .
|
docker build -t tmpbuild_image -f tmpbuild/Dockerfile .
|
||||||
@@ -169,6 +174,8 @@ download)
|
|||||||
;;
|
;;
|
||||||
packageprep)
|
packageprep)
|
||||||
PKG_MGR=""
|
PKG_MGR=""
|
||||||
|
NGINX_CUSTOM_VER="$2"
|
||||||
|
|
||||||
# Determine package manager and install nginx
|
# Determine package manager and install nginx
|
||||||
if command -v dnf >/dev/null 2>&1; then
|
if command -v dnf >/dev/null 2>&1; then
|
||||||
PKG_MGR="dnf"
|
PKG_MGR="dnf"
|
||||||
@@ -185,9 +192,63 @@ packageprep)
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Auto-detect nginx version if not specified by user
|
||||||
|
DETECTED_NGINX_VERSION=""
|
||||||
|
if [ -z "$NGINX_CUSTOM_VER" ] || [ "$NGINX_CUSTOM_VER" == "." ]; then
|
||||||
|
echo "Auto-detecting nginx version..."
|
||||||
|
|
||||||
|
if command -v rpm >/dev/null 2>&1; then
|
||||||
|
# RPM-based systems: detect via package manager and runtime
|
||||||
|
PKG_VERSION=$(rpm -q nginx --queryformat '%{VERSION}' 2>/dev/null)
|
||||||
|
RUNTIME_VERSION=$(nginx -V 2>&1 | grep 'version:' | head -n 1 | sed -n 's/.*nginx\/\(.*\).*/\1/p')
|
||||||
|
|
||||||
|
if [ -n "$RUNTIME_VERSION" ]; then
|
||||||
|
DETECTED_NGINX_VERSION="$RUNTIME_VERSION"
|
||||||
|
elif [ -n "$PKG_VERSION" ]; then
|
||||||
|
# Fallback to package version (strip release part)
|
||||||
|
DETECTED_NGINX_VERSION=$(echo "$PKG_VERSION" | cut -d'-' -f1)
|
||||||
|
fi
|
||||||
|
elif command -v dpkg >/dev/null 2>&1; then
|
||||||
|
# Debian-based systems
|
||||||
|
PKG_VERSION=$(dpkg-query -W -f='${Version}\n' nginx 2>/dev/null | head -n 1)
|
||||||
|
RUNTIME_VERSION=$(nginx -V 2>&1 | grep 'version:' | head -n 1 | sed -n 's/.*nginx\/\(.*\).*/\1/p')
|
||||||
|
|
||||||
|
if [ -n "$RUNTIME_VERSION" ]; then
|
||||||
|
DETECTED_NGINX_VERSION="$RUNTIME_VERSION"
|
||||||
|
elif [ -n "$PKG_VERSION" ]; then
|
||||||
|
# Handle Debian version format (e.g., "1.24.0-1ubuntu1.1" -> "1.24.0")
|
||||||
|
DETECTED_NGINX_VERSION=$(echo "$PKG_VERSION" | cut -d'-' -f1)
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: Unsupported package manager. Unable to auto-detect nginx version."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$DETECTED_NGINX_VERSION" ]; then
|
||||||
|
echo "Detected nginx version: $DETECTED_NGINX_VERSION"
|
||||||
|
else
|
||||||
|
echo "Warning: Could not detect nginx version. Using generic download."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Using custom nginx version: $NGINX_CUSTOM_VER"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$PKG_MGR" == "yum" -o "$PKG_MGR" == "dnf" ]; then
|
if [ "$PKG_MGR" == "yum" -o "$PKG_MGR" == "dnf" ]; then
|
||||||
mkdir -p rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SOURCES rpmbuild/SPECS rpmbuild/SRPMS
|
mkdir -p rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SOURCES rpmbuild/SPECS rpmbuild/SRPMS
|
||||||
cp packages/rpm/nginx-mod-rewrite.spec rpmbuild/SPECS
|
cp packages/rpm/nginx-mod-rewrite.spec rpmbuild/SPECS
|
||||||
|
|
||||||
|
# Determine nginx version to use in spec file
|
||||||
|
if [ -n "$NGINX_CUSTOM_VER" ]; then
|
||||||
|
NGINX_VER_FOR_SPEC="$NGINX_CUSTOM_VER"
|
||||||
|
elif [ -n "$DETECTED_NGINX_VERSION" ]; then
|
||||||
|
NGINX_VER_FOR_SPEC="$DETECTED_NGINX_VERSION"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Modify spec file to use detected/custom nginx version
|
||||||
|
if [ -n "$NGINX_VER_FOR_SPEC" ]; then
|
||||||
|
sed -i "s|%global nginx_version .*|%global nginx_version $NGINX_VER_FOR_SPEC|" rpmbuild/SPECS/nginx-mod-rewrite.spec
|
||||||
|
fi
|
||||||
|
|
||||||
cp nginx-mod-rewrite-*.tar.gz rpmbuild/SOURCES
|
cp nginx-mod-rewrite-*.tar.gz rpmbuild/SOURCES
|
||||||
rpmbuild --define='_topdir /app/rpmbuild' -ba rpmbuild/SPECS/nginx-mod-rewrite.spec
|
rpmbuild --define='_topdir /app/rpmbuild' -ba rpmbuild/SPECS/nginx-mod-rewrite.spec
|
||||||
cp rpmbuild/RPMS/x86_64/* /app/tmpbuild
|
cp rpmbuild/RPMS/x86_64/* /app/tmpbuild
|
||||||
@@ -213,6 +274,16 @@ packageprep)
|
|||||||
# Extract, stripping the top-level directory
|
# Extract, stripping the top-level directory
|
||||||
tar --strip-components=1 -xzf "$(basename "$TARBALL")"
|
tar --strip-components=1 -xzf "$(basename "$TARBALL")"
|
||||||
|
|
||||||
|
# Use custom nginx version if specified, otherwise use auto-detected
|
||||||
|
NGINX_VER="${NGINX_CUSTOM_VER:-${DETECTED_NGINX_VERSION:-1.24.0}}"
|
||||||
|
|
||||||
|
# Generate debian/control with correct nginx version
|
||||||
|
bash control.sh "$NGINX_VER"
|
||||||
|
|
||||||
|
if [ -n "$NGINX_CUSTOM_VER" ]; then
|
||||||
|
sed -i "s|bash package_preparer.sh download . system|bash package_preparer.sh download \"$NGINX_CUSTOM_VER\"|g" rules
|
||||||
|
fi
|
||||||
|
|
||||||
dpkg-buildpackage -us -uc
|
dpkg-buildpackage -us -uc
|
||||||
|
|
||||||
cp ../nginx-mod-rewrite* /app/tmpbuild
|
cp ../nginx-mod-rewrite* /app/tmpbuild
|
||||||
|
|||||||
33
packages/deb/control.sh
Normal file
33
packages/deb/control.sh
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script generates the debian/control file with correct nginx version dependency
|
||||||
|
# Usage: control.sh [NGINX_VERSION]
|
||||||
|
# If NGINX_VERSION is not specified, it uses DETECTED_NGINX_VERSION from environment or default "1.24.0"
|
||||||
|
|
||||||
|
NGINX_VER="${1:-${DETECTED_NGINX_VERSION:-1.24.0}}"
|
||||||
|
|
||||||
|
cat > debian/control << EOF
|
||||||
|
Source: nginx-mod-rewrite
|
||||||
|
Section: web
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: Alexey Berezhok <a@bayrepo.ru>
|
||||||
|
Build-Depends: debhelper-compat (=13),
|
||||||
|
dh-autoreconf,
|
||||||
|
libssl-dev,
|
||||||
|
libpcre2-dev,
|
||||||
|
zlib1g-dev,
|
||||||
|
nginx (=${NGINX_VER})
|
||||||
|
Standards-Version: 4.7.0
|
||||||
|
Homepage: https://docs.brepo.ru/nginx-mod_rewrite
|
||||||
|
|
||||||
|
Package: nginx-mod-rewrite
|
||||||
|
Architecture: any
|
||||||
|
Depends: \${shlibs:Depends}, nginx (=${NGINX_VER})
|
||||||
|
Provides: nginx-http-module, nginx-apache-rewrite
|
||||||
|
Description: Nginx rewrite module – dynamic module adding mod_rewrite functionality
|
||||||
|
Dynamic Nginx module implementing Apache mod_rewrite functionality.
|
||||||
|
The package is built from Nginx sources and the module's own files, and then
|
||||||
|
installs only the compiled shared object into /etc/nginx/modules directory.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Generated debian/control for nginx version: $NGINX_VER"
|
||||||
14
packages/deb/debian/control
Normal file
14
packages/deb/debian/control
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
Source: nginx-mod-rewrite
|
||||||
|
Section: web
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: Alexey Berezhok <a@bayrepo.ru>
|
||||||
|
Build-Depends: debhelper (>= 13), bash, openssl-dev, libssl-dev
|
||||||
|
Standards-Version: 4.7.0
|
||||||
|
Homepage: https://docs.brepo.ru/nginx-mod_rewrite
|
||||||
|
|
||||||
|
Package: nginx-mod-rewrite
|
||||||
|
Architecture: any
|
||||||
|
Depends: ${shlibs:Depends}, nginx (>= 1.4.0)
|
||||||
|
Provides: nginx-http-module, nginx-apache-rewrite
|
||||||
|
Description: Nginx rewrite module – dynamic module adding mod_rewrite functionality
|
||||||
|
Dynamic Nginx module implementing Apache mod_rewrite functionality.
|
||||||
@@ -7,21 +7,26 @@ export DH_COMPAT=$(DEBHELPER_COMPAT)
|
|||||||
export BUILD_DIR = debian/build
|
export BUILD_DIR = debian/build
|
||||||
export INSTALDIR = debian/nginx-mod-rewrite/usr/share/nginx/modules
|
export INSTALDIR = debian/nginx-mod-rewrite/usr/share/nginx/modules
|
||||||
export CONFFDIR = debian/nginx-mod-rewrite/etc/nginx/modules
|
export CONFFDIR = debian/nginx-mod-rewrite/etc/nginx/modules
|
||||||
|
export DOCSDIR = debian/nginx-mod-rewrite/usr/share/info
|
||||||
|
|
||||||
|
# Package metadata (matches debian/control)
|
||||||
|
PACKAGE_NAME = nginx-mod-rewrite
|
||||||
|
|
||||||
# Set build options
|
|
||||||
override_dh_auto_build:
|
override_dh_auto_build:
|
||||||
bash package_preparer.sh download . system
|
bash package_preparer.sh download . system
|
||||||
bash package_preparer.sh build
|
bash package_preparer.sh build
|
||||||
|
|
||||||
override_dh_auto_install:
|
override_dh_auto_install:
|
||||||
mkdir -p $(INSTALDIR) $(CONFFDIR)
|
mkdir -p $(INSTALDIR) $(CONFFDIR) $(DOCSDIR)
|
||||||
cp *.so $(INSTALDIR)/
|
cp *.so $(INSTALDIR)/
|
||||||
echo 'load_module "$(INSTALDIR)/ngx_http_apache_rewrite_module.so";' > \
|
echo 'load_module "$(INSTALDIR)/ngx_http_apache_rewrite_module.so";' > \
|
||||||
$(CONFFDIR)/ngx_http_apache_rewrite_module.conf
|
$(CONFFDIR)/ngx_http_apache_rewrite_module.conf
|
||||||
|
cp BUILDINFO.txt $(DOCSDIR)/${PACKAGE_NAME}-BUILDINFO.txt
|
||||||
|
|
||||||
override_dh_auto_clean:
|
override_dh_auto_clean:
|
||||||
rm -rf debian/build
|
rm -rf debian/build
|
||||||
rm -f *.so
|
rm -f *.so
|
||||||
|
rm -f BUILDINFO.txt
|
||||||
rm -rf nginx-*
|
rm -rf nginx-*
|
||||||
|
|
||||||
%:
|
%:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
%define name nginx-mod-rewrite
|
%define name nginx-mod-rewrite
|
||||||
%define version 0.1
|
%define version 0.1
|
||||||
%define release 1%{?dist}
|
%define release 1%{?dist}
|
||||||
|
%global nginx_version ${NGINX_CUSTOM_VER:-$(rpm -q nginx --queryformat '%{VERSION}' | cut -d'-' -f1)}
|
||||||
|
|
||||||
%define summary "Nginx rewrite module – dynamic module adding mod_rewrite functionality"
|
%define summary "Nginx rewrite module – dynamic module adding mod_rewrite functionality"
|
||||||
%define license Apache-2.0
|
%define license Apache-2.0
|
||||||
%define url https://docs.brepo.ru/nginx-mod-rewrite
|
%define url https://docs.brepo.ru/nginx-mod-rewrite
|
||||||
@@ -21,7 +23,7 @@ BuildRequires: pcre-devel
|
|||||||
BuildRequires: zlib-devel
|
BuildRequires: zlib-devel
|
||||||
BuildRequires: bash
|
BuildRequires: bash
|
||||||
BuildRequires: wget
|
BuildRequires: wget
|
||||||
Requires: nginx
|
Requires: nginx=%{nginx_version}
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Dynamic Nginx module implementing Apache mod_rewrite functionality.
|
Dynamic Nginx module implementing Apache mod_rewrite functionality.
|
||||||
@@ -37,7 +39,8 @@ bash package_preparer.sh build
|
|||||||
|
|
||||||
%install
|
%install
|
||||||
# Install only the dynamic module
|
# Install only the dynamic module
|
||||||
mkdir -p %{buildroot}%{nginx_moduledir} %{buildroot}%{nginx_moduleconfdir}
|
mkdir -p %{buildroot}%{nginx_moduledir} %{buildroot}%{nginx_moduleconfdir} \
|
||||||
|
%{buildroot}%{_datarootdir}/info/
|
||||||
cp *.so %{buildroot}%{nginx_moduledir}
|
cp *.so %{buildroot}%{nginx_moduledir}
|
||||||
echo 'load_module "%{nginx_moduledir}/ngx_http_apache_rewrite_module.so";' \
|
echo 'load_module "%{nginx_moduledir}/ngx_http_apache_rewrite_module.so";' \
|
||||||
> %{buildroot}%{nginx_moduleconfdir}/ngx_http_apache_rewrite_module.conf
|
> %{buildroot}%{nginx_moduleconfdir}/ngx_http_apache_rewrite_module.conf
|
||||||
@@ -49,7 +52,7 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%license LICENSE
|
%license LICENSE BUILDINFO.txt
|
||||||
|
|
||||||
%attr(0640,root,root) %{nginx_moduleconfdir}/ngx_http_apache_rewrite_module.conf
|
%attr(0640,root,root) %{nginx_moduleconfdir}/ngx_http_apache_rewrite_module.conf
|
||||||
%attr(0755,root,root) %{nginx_moduledir}/ngx_http_apache_rewrite_module.so
|
%attr(0755,root,root) %{nginx_moduledir}/ngx_http_apache_rewrite_module.so
|
||||||
|
|||||||
Reference in New Issue
Block a user