Skip to content

Commit

Permalink
build(front): simplifie l'image nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot committed Oct 29, 2024
1 parent ce7cc40 commit 24e6914
Showing 1 changed file with 8 additions and 62 deletions.
70 changes: 8 additions & 62 deletions front/dockerfile
Original file line number Diff line number Diff line change
@@ -1,66 +1,12 @@
# build environment
FROM nginx:mainline-alpine as nginx-modules-builder
ENV ENABLED_MODULES="brotli"
COPY ./ /modules/
FROM nginx:1.27-alpine

RUN set -ex \
&& apk update \
&& apk add linux-headers openssl-dev pcre-dev zlib-dev openssl abuild \
musl-dev libxslt libxml2-utils make gcc unzip git \
xz g++ \
# allow abuild as a root user \
&& printf "#!/bin/sh\\n/usr/bin/abuild -F \"\$@\"\\n" > /usr/local/bin/abuild \
&& chmod +x /usr/local/bin/abuild \
&& curl -f -sSLO https://github.com/nginx/pkg-oss/archive/${NGINX_VERSION}-${PKG_RELEASE}.tar.gz \
&& mkdir pkg-oss \
&& tar xzvf ${NGINX_VERSION}-${PKG_RELEASE}.tar.gz -C pkg-oss --strip-components 1 \
&& cd pkg-oss \
&& mkdir /tmp/packages \
&& for module in "$ENABLED_MODULES"; do \
echo "Building $module for nginx-$NGINX_VERSION"; \
if [ -d /modules/$module ]; then \
echo "Building $module from user-supplied sources"; \
# check if module sources file is there and not empty
if [ ! -s /modules/$module/source ]; then \
echo "No source file for $module in modules/$module/source, exiting"; \
exit 1; \
fi; \
# some modules require build dependencies
if [ -f /modules/$module/build-deps ]; then \
echo "Installing $module build dependencies"; \
apk update && apk add $(cat /modules/$module/build-deps | xargs); \
fi; \
# if a module has a build dependency that is not in a distro, provide a
# shell script to fetch/build/install those
# note that shared libraries produced as a result of this script will
# not be copied from the builder image to the main one so build static
if [ -x /modules/$module/prebuild ]; then \
echo "Running prebuild script for $module"; \
/modules/$module/prebuild; \
fi; \
/pkg-oss/build_module.sh -v $NGINX_VERSION -f -y -o /tmp/packages -n $module $(cat /modules/$module/source); \
elif make -C /pkg-oss/alpine list | grep -E "^$module\s+\d+" > /dev/null; then \
echo "Building $module from pkg-oss sources"; \
cd /pkg-oss/alpine; \
make abuild-module-$module BASE_VERSION=$NGINX_VERSION NGINX_VERSION=$NGINX_VERSION; \
apk add $(. ./abuild-module-$module/APKBUILD; echo $makedepends;); \
make module-$module BASE_VERSION=$NGINX_VERSION NGINX_VERSION=$NGINX_VERSION; \
find ~/packages -type f -name "*.apk" -exec mv -v {} /tmp/packages/ \;; \
else \
echo "Don't know how to build $module module, exiting"; \
exit 1; \
fi; \
done

# production environment
FROM nginx:mainline-alpine
ENV ENABLED_MODULES="brotli"
COPY --from=nginx-modules-builder /tmp/packages /tmp/packages
RUN set -ex \
&& for module in $ENABLED_MODULES; do \
apk add --no-cache --allow-untrusted /tmp/packages/nginx-module-${module}-${NGINX_VERSION}*.apk; \
done \
&& rm -rf /tmp/packages
RUN apk del -r nginx \
&& apk add --no-cache \
nginx \
nginx-mod-http-vts \
nginx-mod-http-brotli \
nginx-mod-http-cache-purge \
nginx-mod-http-headers-more

COPY nginx-default.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
Expand Down

0 comments on commit 24e6914

Please sign in to comment.