Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: now building ngx_http_redis_module.so on nginx image build #137

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
TeKrop marked this conversation as resolved.
Show resolved Hide resolved
interval: 5s
timeout: 2s
Loading