Skip to content

Commit

Permalink
feat: now building ngx_http_redis_module.so on nginx image build (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
TeKrop authored Jun 12, 2024
1 parent 9169bbf commit 037fc09
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
FROM python:3.12-alpine AS main
# Build arguments
ARG PYTHON_VERSION=3.12
ARG POETRY_VERSION=1.8.2

FROM python:${PYTHON_VERSION}-alpine AS main

WORKDIR /code

# Environment variables
ARG POETRY_VERSION
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.8.2
POETRY_VERSION=${POETRY_VERSION}

# Install required system packages and install poetry
RUN apk add build-base && \
apk add libffi-dev && \
pip install poetry==1.8.2
pip install poetry==$POETRY_VERSION

# Copy only requirements (caching in Docker layer)
COPY pyproject.toml /code/
Expand Down
41 changes: 37 additions & 4 deletions build/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
FROM nginx:1.20.2-alpine
# Build arguments
ARG NGINX_VERSION=1.20.2
ARG NGX_HTTP_REDIS_VERSION=0.3.8

# Copy specific configuration files and libraries
FROM nginx:${NGINX_VERSION}-alpine

# Environment variables
ARG NGINX_VERSION
ENV NGINX_VERSION=${NGINX_VERSION}
ARG NGX_HTTP_REDIS_VERSION
ENV NGX_HTTP_REDIS_VERSION=${NGX_HTTP_REDIS_VERSION}

# Copy specific configuration files
COPY nginx.conf /etc/nginx/nginx.conf
COPY ngx_http_redis_module.so /usr/lib/nginx/modules/ngx_http_redis_module.so
COPY overfast-api.conf /etc/nginx/conf.d/default.conf
COPY overfast-api.conf /etc/nginx/conf.d/default.conf

# Download nginx and ngx_http_redis sources
RUN wget https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz && \
tar -xzvf nginx-$NGINX_VERSION.tar.gz && \
wget http://people.freebsd.org/~osa/ngx_http_redis-$NGX_HTTP_REDIS_VERSION.tar.gz && \
tar -xzvf ngx_http_redis-$NGX_HTTP_REDIS_VERSION.tar.gz

# Download build dependencies
RUN apk add build-base linux-headers pcre-dev openssl-dev zlib-dev

# Configure nginx with ngx_http_redis module. We must use the same configuration
# settings than the ones used in nginx compilation. We then only build the
# modules, and copy the resulting ngx_http_redis_module.so into nginx modules directory
RUN cd nginx-$NGINX_VERSION && \
nginx_configure_args=$(nginx -V 2>&1 | grep 'configure arguments:' | sed -e "s/configure arguments://") && \
echo "./configure $nginx_configure_args --add-dynamic-module=../ngx_http_redis-$NGX_HTTP_REDIS_VERSION" > configure.sh && \
chmod +x configure.sh && \
./configure.sh && \
make modules && \
cp objs/ngx_http_redis_module.so /usr/lib/nginx/modules/ngx_http_redis_module.so

# Clean everything
RUN rm -rf nginx-$NGINX_VERSION* && \
rm -rf ngx_http_redis-$NGX_HTTP_REDIS_VERSION*
Binary file removed build/nginx/ngx_http_redis_module.so
Binary file not shown.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ services:
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -O /dev/null http://localhost || exit 1"]
test: ["CMD-SHELL", "wget --spider --quiet http://localhost || exit 1"]
interval: 5s
timeout: 2s

0 comments on commit 037fc09

Please sign in to comment.