From 3100a62b0741f15ef51cb7a0d76fad715f6515b3 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sun, 22 Sep 2024 16:05:26 +0800 Subject: [PATCH] feat: nginx & php image --- .github/workflows/docker-release.yml | 2 ++ docker-compose.yml | 45 +++++++++++++++++++++++++ nginx/Dockerfile | 21 ++++++++++++ nginx/default.conf | 50 ++++++++++++++++++++++++++++ nginx/fastcgi-php.conf | 4 +++ php/Dockerfile | 28 ++++++++++++++++ 6 files changed, 150 insertions(+) create mode 100644 docker-compose.yml create mode 100644 nginx/Dockerfile create mode 100644 nginx/default.conf create mode 100644 nginx/fastcgi-php.conf create mode 100644 php/Dockerfile diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 48dc198..bee86da 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -21,6 +21,8 @@ jobs: matrix: context: - all-in-one + - nginx + - php steps: - name: Checkout repository diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..747f5a1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +name: WordPress + +networks: + wordpress: + driver: bridge + +volumes: + db_data: {} + wordpress_data: {} + +services: + db: + image: mariadb:lts + volumes: + - db_data:/var/lib/mysql + restart: always + environment: + MYSQL_ROOT_PASSWORD: somewordpress + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress + networks: + - wordpress + + nginx: + build: + context: nginx + depends_on: + - php + ports: + - "8080:80" + networks: + - wordpress + volumes: + - wordpress_data:/var/www/html/wp-content + + php: + build: + context: php + depends_on: + - db + networks: + - wordpress + volumes: + - wordpress_data:/var/www/html/wp-content diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..0b67bea --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,21 @@ +ARG NGINX_VERSION=1.26.2 +FROM nginx:${NGINX_VERSION}-alpine + +# Install nginx +RUN mkdir -p /etc/nginx/snippets +COPY fastcgi-php.conf /etc/nginx/snippets/fastcgi-php.conf +COPY default.conf /etc/nginx/conf.d/default.conf + +WORKDIR /var/www/html + +# Download WordPress +ARG WORDPRESS_VERSION=latest +RUN curl -o /tmp/wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" +RUN tar -xzf /tmp/wordpress.tar.gz -C /var/www/html --strip-components=1 +RUN rm -f /tmp/wordpress.tar.gz +RUN chmod -R 755 /var/www/html +RUN chown -R nginx:nginx /var/www/html + +EXPOSE 80 + +ENTRYPOINT ["nginx", "-g", "daemon off;"] diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..8f6225f --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,50 @@ +upstream php { + server php:9000; +} + +server { + listen 80; + server_name localhost; + root /var/www/html; + + index index.php index.html index.htm; + + # Access log + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location = /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + location / { + # This is cool because no php is touched for static content. + # include the "?$args" part so non-default permalinks doesn't break when using query string + try_files $uri $uri/ /index.php?$args; + } + + location /healthcheck { + return 200 'healthy'; + } + + # PHP-FPM configuration + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + # Deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + location ~ /\.ht { + deny all; + } +} diff --git a/nginx/fastcgi-php.conf b/nginx/fastcgi-php.conf new file mode 100644 index 0000000..6952f8e --- /dev/null +++ b/nginx/fastcgi-php.conf @@ -0,0 +1,4 @@ +fastcgi_split_path_info ^(.+\.php)(/.+)$; +fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; +fastcgi_index index.php; +include fastcgi_params; diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 0000000..f1e8b38 --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,28 @@ +ARG PHP_VERSION=8.0 +FROM php:${PHP_VERSION}-fpm + +# Install PHP extensions +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +ARG PHP_EXTENSIONS="gd opcache zip pdo_mysql mysqli redis xdebug imagick exif mbstring zip" +RUN install-php-extensions ${PHP_EXTENSIONS} + +RUN echo "opcache.enable=1" >> /usr/local/etc/php/conf.d/opcache.ini +RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/opcache.ini +RUN echo "opcache.memory_consumption=256" >> /usr/local/etc/php/conf.d/opcache.ini +RUN echo "memory_limit=2048M" >> /usr/local/etc/php/conf.d/performance.ini +RUN echo "upload_max_filesize=100M" >> /usr/local/etc/php/conf.d/performance.ini +RUN echo "post_max_size=100M" >> /usr/local/etc/php/conf.d/performance.ini + +# Download WordPress +ARG WORDPRESS_VERSION=latest +RUN curl -o /tmp/wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" +RUN tar -xzf /tmp/wordpress.tar.gz -C /var/www/html --strip-components=1 +RUN rm -f /tmp/wordpress.tar.gz +RUN chmod -R 755 /var/www/html +RUN chown -R www-data:www-data /var/www/html + +EXPOSE 9000 + +WORKDIR /var/www/html + +ENTRYPOINT ["php-fpm", "-F"]