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

chore: upgrade dockerfile #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
83 changes: 61 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
FROM nginx:stable-alpine as ngx-php

COPY config /build/config
COPY src /build/src
COPY third_party /build/third_party

# Nginx Docker Playground (https://github.com/nginx-with-docker/nginx-docker-playground)
FROM soulteary/prebuilt-nginx-modules:base-1.23.1-alpine AS Builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, try to use official docker images.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soulteary I think joanhey is right. haha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this change, and will update this PR once I've finished a piece of content with a better scene, hopefully within the last two months of this year.

eg: https://www.zhihu.com/question/21483073/answer/2647942304

@rryqszq4 @joanhey

RUN apk update && apk --no-cache add curl gcc g++ make musl-dev linux-headers gd-dev geoip-dev libxml2-dev libxslt-dev openssl-dev pcre-dev perl-dev pkgconf zlib-dev libedit-dev ncurses-dev php8-dev php8-embed git unzip argon2-dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add OPcache extension

ENV PHP_LIB=/usr/lib
WORKDIR /usr/src

WORKDIR /build
# Nginx Development Kit (https://github.com/vision5/ngx_devel_kit)
ARG DEVEL_KIT_MODULE_CHECKSUM=e15316e13a7b19a3d2502becbb26043a464a135a
ARG DEVEL_KIT_VERSION=0.3.1
ARG DEVEL_KIT_NAME=ngx_devel_kit
RUN curl -L "https://github.com/vision5/ngx_devel_kit/archive/v${DEVEL_KIT_VERSION}.tar.gz" -o "v${DEVEL_KIT_VERSION}.tar.gz" && \
echo "${DEVEL_KIT_MODULE_CHECKSUM} v${DEVEL_KIT_VERSION}.tar.gz" | shasum -c && \
tar -zxC /usr/src -f v${DEVEL_KIT_VERSION}.tar.gz && \
mv ${DEVEL_KIT_NAME}-${DEVEL_KIT_VERSION}/ ${DEVEL_KIT_NAME}

RUN apk --no-cache add curl gcc g++ make musl-dev linux-headers gd-dev geoip-dev libxml2-dev libxslt-dev openssl-dev paxmark pcre-dev perl-dev pkgconf zlib-dev libedit-dev ncurses-dev php7-dev php7-embed argon2-dev \
&& NGINX_VERSION=$(nginx -v 2>&1 | sed 's/^[^0-9]*//') \
&& curl -sL -o nginx-${NGINX_VERSION}.tar.gz http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
&& tar -xf nginx-${NGINX_VERSION}.tar.gz \
&& cd nginx-${NGINX_VERSION} \
&& ./configure $(nginx -V 2>&1 | tail -1 | sed -e 's/configure arguments://' -e 's| --add-dynamic-module=[^ ]*||g') --with-ld-opt="-Wl,-rpath,${PHP_LIB}" --add-dynamic-module=../third_party/ngx_devel_kit --add-dynamic-module=.. \
&& make \
&& mkdir -p /usr/lib/nginx/modules \
&& cp objs/ndk_http_module.so /usr/lib/nginx/modules \
&& cp objs/ngx_http_php_module.so /usr/lib/nginx/modules
# Nginx PHP Module Stable Version
ARG MODULE_CHECKSUM=9fe0ee2ca753cf82b8d982fef1e9888b1a59d8b1
ARG MODULE_VERSION=0.0.26
ARG MODULE_NAME=ngx-php
ARG MODULE_SOURCE=https://github.com/rryqszq4/ngx-php
RUN curl -L "${MODULE_SOURCE}/archive/refs/tags/v${MODULE_VERSION}.zip" -o "v${MODULE_VERSION}.zip" && \
echo "${MODULE_CHECKSUM} v${MODULE_VERSION}.zip" | shasum -c && \
unzip "v${MODULE_VERSION}.zip" && \
mv "$MODULE_NAME-$MODULE_VERSION" "$MODULE_NAME"

# Build with Nginx
RUN cd /usr/src/nginx && \
CONFARGS=$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p') \
CONFARGS=${CONFARGS/-Os -fomit-frame-pointer -g/-Os} && \
echo $CONFARGS && \
./configure --with-compat $CONFARGS --with-ld-opt="-Wl,-rpath,${PHP_LIB}" --add-dynamic-module=../${DEVEL_KIT_NAME} --add-dynamic-module=../${MODULE_NAME} && \
make modules

FROM nginx:stable-alpine
# Generate Ngx-PHP configuration demo
RUN apk add bash
SHELL ["/bin/bash", "-c"]
RUN echo $' \n\
load_module modules/ndk_http_module.so; \n\
load_module modules/ngx_http_php_module.so; \n\
events { worker_connections 1024; } \n\
http { \n\
include /etc/nginx/mime.types; \n\
php_ini_path /etc/php8/php.ini; \n\
gzip on; \n\
server { \n\
listen 80; \n\
server_name localhost; \n\
location = / { \n\
content_by_php_block { \n\
echo "hello world via ngx_php"; \n\
} \n\
} \n\
} \n\
} \n\
'> /nginx.conf

RUN apk --no-cache add php7-embed \
&& sed -i "s|events {|include /etc/nginx/modules/\*.conf;\n\nevents {|" /etc/nginx/nginx.conf \
&& echo -e "load_module \"/usr/lib/nginx/modules/ndk_http_module.so\";\nload_module \"/usr/lib/nginx/modules/ngx_http_php_module.so\";" > /etc/nginx/modules/php.conf

COPY --from=ngx-php /usr/lib/nginx/modules/ /usr/lib/nginx/modules/
# Build Final Nginx Docker Image
FROM nginx:1.23.1-alpine
LABEL [email protected]
COPY --from=Builder /usr/lib/libphp.so /usr/lib/
COPY --from=Builder /usr/lib/libargon2.so.1 /usr/lib/
COPY --from=Builder /lib/libz.so.1 /lib/
COPY --from=Builder /etc/php8/php.ini /etc/php8/
COPY --from=Builder /nginx.conf /etc/nginx/nginx.conf
COPY --from=Builder /usr/src/nginx/objs/ndk_http_module.so /etc/nginx/modules/
COPY --from=Builder /usr/src/nginx/objs/ngx_http_php_module.so /etc/nginx/modules/
ENV PHP_LIB=/usr/lib
29 changes: 29 additions & 0 deletions Dockerfile.php7
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM nginx:stable-alpine as ngx-php

COPY config /build/config
COPY src /build/src
COPY third_party /build/third_party

ENV PHP_LIB=/usr/lib

WORKDIR /build

RUN apk --no-cache add curl gcc g++ make musl-dev linux-headers gd-dev geoip-dev libxml2-dev libxslt-dev openssl-dev paxmark pcre-dev perl-dev pkgconf zlib-dev libedit-dev ncurses-dev php7-dev php7-embed argon2-dev \
&& NGINX_VERSION=$(nginx -v 2>&1 | sed 's/^[^0-9]*//') \
&& curl -sL -o nginx-${NGINX_VERSION}.tar.gz http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
&& tar -xf nginx-${NGINX_VERSION}.tar.gz \
&& cd nginx-${NGINX_VERSION} \
&& ./configure $(nginx -V 2>&1 | tail -1 | sed -e 's/configure arguments://' -e 's| --add-dynamic-module=[^ ]*||g') --with-ld-opt="-Wl,-rpath,${PHP_LIB}" --add-dynamic-module=../third_party/ngx_devel_kit --add-dynamic-module=.. \
&& make \
&& mkdir -p /usr/lib/nginx/modules \
&& cp objs/ndk_http_module.so /usr/lib/nginx/modules \
&& cp objs/ngx_http_php_module.so /usr/lib/nginx/modules


FROM nginx:stable-alpine

RUN apk --no-cache add php7-embed \
&& sed -i "s|events {|include /etc/nginx/modules/\*.conf;\n\nevents {|" /etc/nginx/nginx.conf \
&& echo -e "load_module \"/usr/lib/nginx/modules/ndk_http_module.so\";\nload_module \"/usr/lib/nginx/modules/ngx_http_php_module.so\";" > /etc/nginx/modules/php.conf

COPY --from=ngx-php /usr/lib/nginx/modules/ /usr/lib/nginx/modules/