diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..abdd7d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +data +db +.env diff --git a/Dockerfile b/Dockerfile index fb5520d..d579361 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,36 @@ -FROM debian:buster-slim as build +FROM debian:stable-slim RUN apt-get update && \ - apt-get -qy install \ - php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip \ - sudo wget curl ca-certificates less &&\ + apt-get -qy install \ + php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php-redis \ + wget sed curl tar ca-certificates less \ + mariadb-client && \ apt-get clean -RUN useradd wordpress -d /app/wordpress -COPY wordpress.conf /etc/php/7.3/fpm/pool.d/www.conf -RUN mkdir /run/php/ -#RUN mkdir logs -#USER wordpress -WORKDIR app -RUN wget -O wordpress.tar.gz "https://wordpress.org/latest.tar.gz" -RUN wget https://wordpress.org/latest.tar.gz -RUN tar -xzf wordpress.tar.gz -RUN rm latest.tar.gz -#ADD wordpress_files/wp-config.php /app/wordpress/wp-config.php -#ADD wordpress_files/themes/ /app/wordpress/wp-content/themes/ -#ADD wordpress_files/plugins/ /app/wordpress/wp-content/plugins/ -#ADD wordpress_files/sunrise.php /app/wordpress/wp-content/sunrise.php -RUN chown -R wordpress:wordpress /app/ +COPY config/php-fpm-wordpress.conf /tmp/www.conf -# ADD WP-CLI -RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -RUN chmod +x wp-cli.phar -RUN mv wp-cli.phar wp +RUN PHP_VERSION=$(php --version | head -n 1 | cut -f2 -d" " | cut -f1,2 -d".") && \ + cp /tmp/www.conf /etc/php/$PHP_VERSION/fpm/pool.d/www.conf && \ + mkdir /run/php/ && \ + ln -s /usr/sbin/php-fpm$PHP_VERSION /usr/sbin/php-fpm && \ + sed -i '/^error_log/cerror_log = /app/log/php-fpm.log' /etc/php/$PHP_VERSION/fpm/php-fpm.conf && \ + sed -i '/^pid/cpid = /app/log/php-fpm.pid' /etc/php/$PHP_VERSION/fpm/php-fpm.conf -## ESTO EN UN CRON DAILY -#RUN sudo -u wordpress -i -- /app/wp theme update --all --path="/app/wordpress/" -#RUN ./wp plugin update --all --path="/app/wordpress/" -#RUN ./wp core update --path="/app/wordpress/" +WORKDIR /app -#USER root +RUN curl -s -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \ + chmod +x wp-cli.phar && \ + mv wp-cli.phar /usr/local/bin/wp + +ADD wordpress /tmp/wordpress + +ADD entrypoint.sh /entrypoint.sh EXPOSE 9000 -VOLUME /app/wordpress -CMD ["/usr/sbin/php-fpm7.3","--nodaemonize"]] +VOLUME /app +ENTRYPOINT ["/bin/sh","/entrypoint.sh"] + +CMD ["/usr/sbin/php-fpm","--nodaemonize","-O"] diff --git a/README.md b/README.md index 9d15a31..c27032c 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,30 @@ -Simple custom template for a clean Wordpress installation. +# Simple custom template for a clean Wordpress installation. -# Install +## Pre + + $ mkdir data db + $ cp env.sample .env + $ vim .env + +Customize parameters + +## Build $ docker-compose build -# Run +## Run $ docker-compose up -d -# Config +Access: -Database credentials may edit on ENVIRONMENT on docker-compose.yml + $ w3m http://localhost: -# Auto update Wordpress +## Config + +Database credentials may edit on _.env_ file. + +## Auto update Wordpress User crontab on your hoster server. @@ -22,20 +34,20 @@ Use this script as template: #!/bin/bash echo "Update Wordrpress" -docker exec -it docker-wordpress-ahum_wordpress_1 sudo -u wordpress -i -- /app/wp theme update --all --path="/app/wordpress/" -docker exec -it docker-wordpress-ahum_wordpress_1 sudo -u wordpress -i -- /app/wp plugin update --all --path="/app/wordpress/" -docker exec -it docker-wordpress-ahum_wordpress_1 sudo -u wordpress -i -- /app/wp core update --path="/app/wordpress/" +docker-compose exec wordpress wp theme update --all --path="/app/wordpress/" +docker-compose exec wordpress wp plugin update --all --path="/app/wordpress/" +docker-compose exec wordpress wp core update --path="/app/wordpress/" ``` -# Backups +## Backups -.... +docker-compose exec db mysqldump --database > /.sql -# Restore +## Restore Database restore, like this examples: - $ cat .sql | docker exec -i mysql -u -p + $ cat .sql | docker-compose exec db mysql -u -p Data restore, bulk to volume directory, like: diff --git a/config/nginx-wordpress.conf b/config/nginx-wordpress.conf new file mode 100644 index 0000000..2690389 --- /dev/null +++ b/config/nginx-wordpress.conf @@ -0,0 +1,38 @@ +server { + listen 443 ssl default_server; + include snippets/snakeoil.conf; + + server_name _; + + root /app/wordpress; + index index.php index.html; + + client_max_body_size 25M; + + location ~ /\. { + deny all; + } + + location ~* /(?:uploads|files)/.*\.php$ { + deny all; + } + + location / { + try_files $uri $uri/ /index.php?$args ; + } + + location ~ \.php$ { + try_files $uri =404; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_index index.php; + fastcgi_read_timeout 300; + fastcgi_send_timeout 300; + fastcgi_pass wordpress:9000; + } + + access_log /app/log/wordpress.access.log; + error_log /app/log/wordpress.error.log; +} + diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..6159153 --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,61 @@ +worker_processes auto; +pid /run/nginx/nginx.pid; +error_log stderr info; +daemon off; +master_process off; + +include /etc/nginx/modules-enabled/*.conf; + + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + server_tokens off; + + server_names_hash_bucket_size 128; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /dev/stdout; + + ## + # Gzip Settings + ## + + gzip on; + gzip_disable "msie6"; + + ## + # Virtual Host Configs + ## + + include /etc/nginx/conf.d/*.conf; + #include /etc/nginx/sites-enabled/*; +} + + diff --git a/nginx.conf b/config/nginx.conf.alpine similarity index 100% rename from nginx.conf rename to config/nginx.conf.alpine diff --git a/config/php-fpm-wordpress.conf b/config/php-fpm-wordpress.conf new file mode 100644 index 0000000..bc81f21 --- /dev/null +++ b/config/php-fpm-wordpress.conf @@ -0,0 +1,23 @@ +[www] + +user = www-data +group = www-data +listen = 9000 + +listen.owner = www-data +listen.group = www-data + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 + +access.log = /app/log/access.log +catch_workers_output = yes +;php_admin_value[error_log] = /app/log/php-fpm.log +;php_admin_flag[log_errors] = on +php_flag[display_errors] = off +php_admin_value[allow_url_fopen] = off +php_admin_value[upload_max_filesize] = 50M +php_admin_value[post_max_size] = 50M diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3279ee7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +version: '2.4' + +services: + db: + image: mariadb + user: 1000:1000 + restart: always + volumes: + - ./db:/var/lib/mysql + environment: + - MYSQL_DATABASE + - MYSQL_USER + - MYSQL_RANDOM_ROOT_PASSWORD + - MYSQL_PASSWORD + + wordpress: + image: registry.audio-lab.org/wordpress + build: . + user: 1000:1000 + depends_on: + - db + volumes: + - ./data:/app + restart: always + links: + - db + environment: + - MYSQL_DATABASE + - MYSQL_USER + - MYSQL_PASSWORD + - MYSQL_HOST + - WP_USER + - WP_PASS + - WP_EMAIL + - WP_TITLE + - WP_URL + + + nginx: + image: registry.sindominio.net/nginx + ports: + - ${NGINX_PORT}:443 + volumes: + #- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro + - ./config/nginx.conf:/etc/nginx/nginx.conf:ro + - ./config/nginx-wordpress.conf:/etc/nginx/conf.d/wordpress.conf:ro + - ./data:/app + restart: always + links: + - wordpress diff --git a/docker-compose.yml.sample b/docker-compose.yml.sample deleted file mode 100644 index c3cbcf6..0000000 --- a/docker-compose.yml.sample +++ /dev/null @@ -1,33 +0,0 @@ -version: '3' - -volumes: - db: - data: - -services: - db: - image: mariadb - restart: always - volumes: - - db:/var/lib/mysql - environment: - MYSQL_DATABASE: wordpress - MYSQL_USER: wordpress - MYSQL_RANDOM_ROOT_PASSWORD: '1' - MYSQL_PASSWORD: wordpress - - wordpress: - build: . - volumes: - - data:/app/wordpress - restart: always - - nginx: - build: ./nginx/ - ports: - - 8180:443 - volumes: - - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro - volumes_from: - - wordpress - restart: always diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..0bf7444 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e; + +export WORDPRESS_ROOT=/app/wordpress + +install() { + echo "Install Wordpress $WORDPRESS_ROOT" + mkdir -p $WORDPRESS_ROOT + cd $WORDPRESS_ROOT + wp core download + config +} + +install_themes() { + echo "Install Themes" + cp -R /tmp/wordpress/themes/ /app/wordpress/wp-content/themes/ +} + +install_plugins() { + echo "Install Plugins" + cp -R /tmp/wordpress/themes/ /app/wordpress/wp-content/themes/ +} + +config() { + echo "Config Wordpress $WORDPRESS_ROOT" + cd $WORDPRESS_ROOT + echo "Create Config" + wp config create --dbname=$MYSQL_DATABASE --dbuser=$MYSQL_USER --dbpass=$MYSQL_PASSWORD --dbhost=$MYSQL_HOST --locale=es_ES + echo "Install Worpdress" + if ! wp core is-installed; then + wp core install --url="$WP_URL" --title="$WP_TITLE" --admin_user="$WP_USER" --admin_password="$WP_PASS" --admin_email="$WP_EMAIL" --path="/app/wordpress/" + fi +} + +update() { + echo "Update Wordpress" + cd $WORDPRESS_ROOT + #https://make.wordpress.org/cli/handbook/ + wp core update --path="/app/wordpress/" + wp plugin update --all --path="/app/wordpress/" + wp theme update --all --path="/app/wordpress/" +} + +mkdir -p /app/log/ + +[ -d /app/wordpress ] || install +[ -f /app/wordpress/wp-config.php ] || config + +# WP-CLI install +# https://www.cloudways.com/blog/install-wordpress-using-wp-cli/ + +update +install_themes +install_plugins + +echo "Starting Wordpress" + +exec $@ diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..bd0f6d3 --- /dev/null +++ b/env.sample @@ -0,0 +1,14 @@ +MYSQL_DATABASE=wordpress +MYSQL_USER=wordpress +MYSQL_RANDOM_ROOT_PASSWORD=1 +MYSQL_PASSWORD=wordpress +MYSQL_HOST=db + +NGINX_PORT=8443 +USER_GROUP=1000:1000 + +WP_USER=admin +WP_PASS=admin +WP_EMAIL=real@mail.org +WP_TITLE=Wordpress Title +WP_URL=http://docker:8180 diff --git a/nginx/Dockerfile b/nginx/Dockerfile deleted file mode 100644 index 2dc167b..0000000 --- a/nginx/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM nginx:alpine -RUN apk add openssl -RUN openssl req -x509 -nodes -days 365 -subj "/C=CA/ST=QC/O=Company, Inc./CN=mydomain.com" -addext "subjectAltName=DNS:mydomain.com" -newkey rsa:2048 -keyout /etc/ssl/private/nginx.key -out /etc/ssl/certs/nginx.crt diff --git a/wordpress.conf b/wordpress.conf deleted file mode 100644 index 9dac4be..0000000 --- a/wordpress.conf +++ /dev/null @@ -1,14 +0,0 @@ -[wordpress] - -user = wordpress -group = wordpress -listen = 9000 - -listen.owner = wordpress -listen.group = wordpress - -pm = dynamic -pm.max_children = 5 -pm.start_servers = 2 -pm.min_spare_servers = 1 -pm.max_spare_servers = 3