Skip to content

Instantly share code, notes, and snippets.

@lcrilly
Created November 27, 2023 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcrilly/cb5d0ba52da9af8687fa2233f1ec2e7f to your computer and use it in GitHub Desktop.
Save lcrilly/cb5d0ba52da9af8687fa2233f1ec2e7f to your computer and use it in GitHub Desktop.
Dockerfile for building NGINX Unit from source

This Dockerfile builds NGINX Unit from source, including njs, and by applying any .patch files found in the current directory. The latest Docker Official Image is used to select the code branch and copies the configure arguments so that the lanauge module in the Docker Image is compatible with the new unitd binary.

Build by specifying the tag of the most suitable Docker Official Image as

docker build --build-arg TAG=php -t unit:test .
# This Dockerfile builds NGINX Unit from source, including njs, and
# by applying any .patch files found in the current directory. The
# latest Docker Official Image is used to select the code branch and
# copies the configure arguments so that the lanauge module in the
# Docker Image is compatible with the new unitd binary.
#
# Build by specifying the tag of the most suitable Docker Official Image
# from <https://hub.docker.com/_/unit/tags> as
# docker build --build-arg TAG=php -t unit:test .
#
ARG TAG=minimal
FROM unit:${TAG} as builder
# Install build tools and dependencies
#
RUN apt update -qq && apt install -y --no-install-recommends \
build-essential git mercurial patch gcc make libssl-dev libpcre2-dev zlib1g-dev
# Get Unit sources and apply any local patch files
# (do this first in case the patch fails)
#
WORKDIR /src
RUN hg clone http://hg.nginx.org/unit -u $(unitd --version 2>&1 | head -1 | cut -f3 -d' ')
COPY *.patch unit/
RUN cd unit && touch null.patch && cat *.patch | patch -p1 --verbose
# Build njs
#
RUN hg clone http://hg.nginx.org/njs -u 0.8.2 && \
cd njs && \
./configure --no-libxml2 --no-zlib && \
make
# Build Unit
#
WORKDIR /src/unit
RUN ./configure --njs --cc-opt="-I../njs/src -I../njs/build" --ld-opt="-L../njs/build" \
$(unitd --version 2>&1 | grep ^configured | sed -e 's/ \-\-/\n--/g' | grep ^-- | grep -ve ^--njs -e ^--..-opt=) && \
make
# Create final image by copying the freshly-built unitd binary into the base image
#
FROM unit:${TAG}
COPY --from=builder /src/unit/build/sbin/unitd /usr/sbin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment