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

Added configurations for Nginx and PHP-FPM #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Added configurations for Nginx and PHP-FPM
  • Loading branch information
alexmanno committed Oct 15, 2019
commit 6b7f810a2d567f85a2d3169280897b22f3da23a0
22 changes: 17 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -11,22 +11,33 @@ services:
image: mariadb
ports:
- '3307:3306'

nginx:
build: docker/dockerfiles/nginx
container_name: nginx
command: sh -c "wait-for-backend && nginx -g 'daemon off;'"
depends_on:
- wp-headless
volumes:
- ./wordpress:/var/www/html
- ./docker/wait-for-backend.sh:/usr/local/bin/wait-for-backend
ports:
- 8080:80

wp-headless:
build: .
command: bash -c 'install_wordpress && apache2-foreground'
build: docker/dockerfiles/wordpress
command: bash -c 'install_wordpress && php-fpm'
container_name: wp-headless
depends_on:
- db-headless
env_file: ./.env
ports:
- '8080:8080'
user: www-data
volumes:
- ./wordpress:/var/www/html
- ./docker/install_wordpress.sh:/usr/local/bin/install_wordpress
- ./docker/migratedb_import.sh:/usr/local/bin/migratedb_import
- ./docker/postlightheadlesswpstarter.wordpress.xml:/var/www/postlightheadlesswpstarter.wordpress.xml
- ./docker/plugins:/var/www/plugins

frontend:
command: bash -c 'yarn && yarn start'
container_name: frontend
@@ -39,6 +50,7 @@ services:
volumes:
- ./frontend:/home/node/app
working_dir: /home/node/app

frontend-graphql:
command: bash -c 'yarn && yarn start'
container_name: frontend-graphql
5 changes: 5 additions & 0 deletions docker/dockerfiles/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.17-alpine

COPY configs/default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
33 changes: 33 additions & 0 deletions docker/dockerfiles/nginx/configs/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
server {
listen 80;
server_name _;

root /var/www/html;

index index.php;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass wp-headless:9000;
}

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
34 changes: 34 additions & 0 deletions docker/dockerfiles/wordpress/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM wordpress:5.2.3-php7.2-fpm

RUN mv "$PHP_INI_DIR"/php.ini-development "$PHP_INI_DIR"/php.ini

# install_wordpress.sh & misc. dependencies
RUN apt-get update; \
apt-get install -yq mariadb-client netcat sudo less git unzip

# wp-cli
RUN curl -sL https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -o wp; \
chmod +x wp; \
mv wp /usr/local/bin/; \
mkdir /var/www/.wp-cli; \
chown www-data:www-data /var/www/.wp-cli

# composer
RUN curl -sL https://raw.githubusercontent.com/composer/getcomposer.org/master/web/installer | php; \
mv composer.phar /usr/local/bin/composer; \
mkdir /var/www/.composer; \
chown www-data:www-data /var/www/.composer

# phpunit, phpcs, wpcs
RUN sudo -u www-data composer global require \
phpunit/phpunit \
dealerdirect/phpcodesniffer-composer-installer \
phpcompatibility/phpcompatibility-wp \
automattic/vipwpcs

# include composer-installed executables in $PATH
ENV PATH="/var/www/.composer/vendor/bin:${PATH}"

WORKDIR /var/www/html

EXPOSE 9000
2 changes: 2 additions & 0 deletions docker/install_wordpress.sh
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

set -e

alias wp='wp --allow-root'

mysql_ready='nc -z db-headless 3306'

if ! $mysql_ready
14 changes: 14 additions & 0 deletions docker/wait-for-backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh

backend_ready='nc -z wp-headless 9000'

if ! $backend_ready
then
printf 'Waiting for Backend.'
while ! $backend_ready
do
printf '.'
sleep 1
done
echo
fi
2 changes: 1 addition & 1 deletion frontend/config.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ let wpUrl = 'http://localhost:8080/wp-json';

// If we're running on Docker, use the WordPress container hostname instead of localhost.
if (process.env.HOME === '/home/node') {
wpUrl = 'http://wp-headless:8080/wp-json';
wpUrl = 'http://nginx/wp-json';
}
const Config = {
apiUrl: wpUrl,