diff --git a/Dockerfile b/Dockerfile index 463fbc0f..37b2f651 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/build/nginx/Dockerfile b/build/nginx/Dockerfile index fc29ace4..45ccd3c8 100644 --- a/build/nginx/Dockerfile +++ b/build/nginx/Dockerfile @@ -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 \ No newline at end of file +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* \ No newline at end of file diff --git a/build/nginx/ngx_http_redis_module.so b/build/nginx/ngx_http_redis_module.so deleted file mode 100644 index 1f6b2884..00000000 Binary files a/build/nginx/ngx_http_redis_module.so and /dev/null differ diff --git a/docker-compose.yml b/docker-compose.yml index 43fe3c33..a841a33e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 \ No newline at end of file