diff --git a/Makefile b/Makefile index 4b485e8..db79dce 100644 --- a/Makefile +++ b/Makefile @@ -24,14 +24,9 @@ RESET = "\e[0m" COMPOSE = ./srcs/docker-compose.yml -# same as 'LOGIN' var in .env file -#V_USER = hulamy -#V_USER = $(shell echo $(USER)) # gives root when make is run with sudo -#V_USER = $(shell who | head -1 | tr " " "\n" | head -1) # gives bad result when in `sudo su` -#V_USER = $(shell who | head -1 | cut -d " " -f 1) # gives bad result when in `sudo su` -V_USER = $(shell users | tr " " "\n" | head -1) -VOLUMES_D = /home/$(V_USER)/data/wp_volume \ - /home/$(V_USER)/data/db_volume +VOLUME_PATH = $(shell grep "MAP_VOLUMES" ./srcs/.env | cut -d "=" -f 2) +VOLUMES_D = $(VOLUME_PATH)/wp_volume \ + $(VOLUME_PATH)/db_volume WP_URL = $(shell grep "WP_URL" ./srcs/.env | cut -d "=" -f 2) # list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile @@ -45,11 +40,12 @@ VOLUMES = $(shell docker volume ls -q) all: build up volumes: - sed -i "s/^LOGIN=.*/LOGIN=$(V_USER)/g" ./srcs/.env mkdir -p $(VOLUMES_D) build: - - bash -c 'echo -e "\n# adding for inception (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts' + - if ! grep "127.0.0.1 ${WP_URL}" /etc/hosts 2> /dev/null; then \ + bash -c 'echo -e "\n# adding for inception (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'; \ + fi docker-compose -f $(COMPOSE) build up: volumes @@ -84,7 +80,6 @@ fclean-images: clean docker system prune -af fclean-volumes: clean - docker volume rm $(VOLUMES) - - rm -rf $(VOLUMES_D) fclean: fclean-images fclean-volumes re: fclean all diff --git a/srcs/.env b/srcs/.env index ba6211e..6d1e200 100644 --- a/srcs/.env +++ b/srcs/.env @@ -1,8 +1,4 @@ -# DOCKER-COMPOSE - -LOGIN=lenovo - # MARIADB SETUP DB_HOST=mariadb @@ -24,3 +20,9 @@ WP_USER=moehu36 WP_USER_PSWD="it's a secret for nobody" WP_USER_EMAIL=moehu36@42.fr +# MAP + +MAX_UPLOAD_SIZE=2046 +EXECUTION_TIME=2000 +MAP_VOLUMES=/home/lenovo/data/lejourduprof + diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index acd6515..4b81625 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -29,6 +29,7 @@ services: context: ./requirements/nginx args: - WP_URL=${WP_URL} + - MAX_UPLOAD_SIZE=${MAX_UPLOAD_SIZE} image: nginx container_name: nginx_container depends_on: @@ -68,6 +69,8 @@ services: context: ./requirements/wordpress args: - WP_DIR=${WP_DIR} + - MAX_UPLOAD_SIZE=${MAX_UPLOAD_SIZE} + - EXECUTION_TIME=${EXECUTION_TIME} image: wordpress container_name: wordpress_container depends_on: @@ -81,15 +84,13 @@ volumes: driver_opts: type: none o: "bind" - device: /home/${LOGIN}/data/wp_volume -# device: ${HOME}/data/wp_volume + device: ${MAP_VOLUMES}/wp_volume db_volume: driver: local driver_opts: type: none o: "bind" - device: /home/${LOGIN}/data/db_volume -# device: ${HOME}/data/db_volume + device: ${MAP_VOLUMES}/db_volume networks: inception: diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 713f1d1..1de31fd 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -1,45 +1,35 @@ -# debian (~ 180s) -------------------------------------------- -# FROM debian:buster -# -# # vim for debug -# RUN apt update && apt install -y \ -# nginx openssl \ -# vim \ -# && \ -# rm -rf /var/lib/apt/lists/* -# -# # nginx conf -# COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf -# COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/ +FROM alpine:3.15 -# alpine (~ 45s) --------------------------------------------- +# vim and bash for debug +RUN apk update && apk add \ + nginx openssl \ + vim bash \ + && \ + rm -rf /var/cache/apk* - FROM alpine:3.15 +# nginx conf +COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf +COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ - # vim and bash for debug - RUN apk update && apk add \ - nginx openssl \ - vim bash \ - && \ - rm -rf /var/cache/apk* +# create user www-data and assign it to group www-data +RUN adduser -S www-data && \ + adduser www-data www-data - # nginx conf - COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf - COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ +RUN mkdir -p /var/www/html - # create user www-data and assign it to group www-data - RUN adduser -S www-data && \ - adduser www-data www-data - - RUN mkdir -p /var/www/html - -# common ----------------------------------------------------- +ARG WP_URL +ARG MAX_UPLOAD_SIZE # replace WP_URL -ARG WP_URL RUN sed -i "s/\${WP_URL}/${WP_URL}/g" /etc/nginx/http.d/inception_nginx.conf +# replace max file size upload +RUN sed -i "s/\(client_max_body_size \).*\(m;\)/\1${MAX_UPLOAD_SIZE}\2/g" /etc/nginx/nginx.conf + +# empty /var/www/html folder to avoid it to rewrite volume +#RUN rm -rf /var/www/html/* + # personalized index.html COPY ./conf/index.html /data/www/ @@ -52,36 +42,3 @@ RUN openssl req -newkey rsa:2048 -nodes -x509 -days 365 \ ENTRYPOINT [ "nginx", "-g", "daemon off;" ] - -# -# -g 'daemon off' : -# daemon off, to avoid the main process of nginx to quit after creating its childs, and therefore make docker exit -# https://stackoverflow.com/questions/18861300/how-to-run-nginx-within-a-docker-container-without-halting -# -# ssl certificate : -# openssl faq : https://www.openssl.org/docs/faq.html -# openssl req : create ertificate request, and optionally create self signed certificates -# openssl req man : https://www.openssl.org/docs/man1.0.2/man1/openssl-req.html -# exemple of openssl with nginx on docker : https://www.johnmackenzie.co.uk/posts/using-self-signed-ssl-certificates-with-docker-and-nginx/ -# -# usually the steps are : -# - create a server private key : `openssl genrsa -out server.key 2048` -# - create a CSR (certificate signing request) with the key : `openssl req -new -key server.key -out www.exemple.com.csr` -# - it will ask for : -# - Country Name (2 letter code) -# - State or Province Name (full name) -# - Locality Name (eg, city) -# - Organization Name (eg, company) -# - Organizational Unit Name (eg, section) -# - Common Name (eg, fully qualified host name) -# - Email Address (put nothing) -# - now ask to a CA (certificate authority) for a certificate.crt by giving them your request.csr -# -# alternatively we can generate our self-signed certificate with the `openssl req` command : -# - `x509` option is used to output a certificate instead of a certificate request -# - a request is created from scratch, if it is not given with `-in` -# - `newkey` generate a new private key, unless `-key` is given -# - `nodes` create a private key without encryption (no passphrase needed) -# -# SO discussion about becomming a real CA to have a certificate that works in deployement : https://stackoverflow.com/questions/10175812/how-to-generate-a-self-signed-ssl-certificate-using-openssl -# diff --git a/srcs/requirements/nginx/conf/nginx.conf.alpine b/srcs/requirements/nginx/conf/nginx.conf.alpine index 68887fd..1cdac83 100644 --- a/srcs/requirements/nginx/conf/nginx.conf.alpine +++ b/srcs/requirements/nginx/conf/nginx.conf.alpine @@ -8,10 +8,6 @@ # # < ssl_protocols TLSv1.2 TLSv1.3; # > ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; -# -# http : -# < client_max_body_size 640m; -# > client_max_body_size 1m; # /etc/nginx/nginx.conf @@ -55,7 +51,7 @@ http { # indicated by the request header Content-Length. If the stated content # length is greater than this size, then the client receives the HTTP # error code 413. Set to 0 to disable. Default is '1m'. - client_max_body_size 640m; + client_max_body_size 1m; # Sendfile copies data between one FD and other from within the kernel, # which is more efficient than read() + write(). Default is off. diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index b933bb7..a574839 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -1,60 +1,43 @@ -# debian ----------------------------------------------------- -# FROM debian:buster -# -# # bash and vim for debug -# RUN apt update && apt install -y \ -# php7.3 \ -# php7.3-fpm \ -# php7.3-mysqli \ -# mariadb-client \ -# curl \ -# bash vim -# RUN rm -rf /var/lib/apt/lists/* -# -# # fpm config -# COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d/ -# RUN mkdir /run/php/ -# -# ENV PHP_VERSION="php-fpm7.3" +FROM alpine:3.15 -# alpine ----------------------------------------------------- +# bash and vim for debug +RUN apk update && apk add \ + php7 \ + php7-fpm \ + php7-mysqli \ + php7-phar \ + php7-json \ + php7-iconv \ + mariadb-client \ + curl \ + bash vim +RUN rm -rf /var/lib/apt/lists/* - FROM alpine:3.15 +# fpm config +COPY ./conf/www.conf /etc/php7/php-fpm.d/ +RUN mkdir /run/php/ - # bash and vim for debug - RUN apk update && apk add \ - php7 \ - php7-fpm \ - php7-mysqli \ - php7-phar \ - php7-json \ - php7-iconv \ - mariadb-client \ - curl \ - bash vim - RUN rm -rf /var/lib/apt/lists/* +ARG WP_DIR +ARG MAX_UPLOAD_SIZE +ARG EXECUTION_TIME - # fpm config - COPY ./conf/www.conf /etc/php7/php-fpm.d/ - RUN mkdir /run/php/ +# create wp directory +RUN mkdir -p ${WP_DIR} - # create wp directory - ARG WP_DIR - RUN mkdir -p ${WP_DIR} +# replace max file size upload and execution time +RUN sed -i "s/\(upload_max_filesize = \).*\(M\)/\1${MAX_UPLOAD_SIZE}\2/g" /etc/php7/php.ini && \ + sed -i "s/\(post_max_size = \).*\(M\)/\1${MAX_UPLOAD_SIZE}\2/g" /etc/php7/php.ini && \ + sed -i "s/\(max_execution_time = \).*/\1${EXECUTION_TIME}/g" /etc/php7/php.ini - # MAP for creation of map plugin - COPY ./conf/map_prof/ ${WP_DIR}/wp-content/plugins/map_prof - # modify .htaccess - COPY ./conf/htaccess ${WP_DIR}/.htaccess +# create www-data user and add to group +RUN adduser -S www-data && \ + adduser www-data www-data - # create www-data user and add to group - RUN adduser -S www-data && \ - adduser www-data www-data +ENV PHP_VERSION="php-fpm7" - ENV PHP_VERSION="php-fpm7" - -# common ----------------------------------------------------- +# empty /var/www/html folder to avoid it to rewrite volume +#RUN rm -rf ${WP_DIR}/* # install wp-cli : https://wp-cli.org/#installing RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&\ diff --git a/srcs/requirements/wordpress/conf/htaccess b/srcs/requirements/wordpress/conf/htaccess deleted file mode 100644 index 2aeca22..0000000 --- a/srcs/requirements/wordpress/conf/htaccess +++ /dev/null @@ -1,5 +0,0 @@ -php_value upload_max_filesize 640M -php_value post_max_size 640M -php_value memory_limit 640M -php_value max_execution_time 300 -php_value max_input_time 300 diff --git a/srcs/requirements/wordpress/conf/map_prof/map_prof.php b/srcs/requirements/wordpress/conf/map_prof/map_prof.php deleted file mode 100644 index 12a738a..0000000 --- a/srcs/requirements/wordpress/conf/map_prof/map_prof.php +++ /dev/null @@ -1,76 +0,0 @@ -%s %s

', -// __( 'Quote from Hello Dolly song, by Jerry Herman:' ), -// $lang, -// $chosen -// ); -// } -// -// // Now we set that function up to execute when the admin_notices action is called. -// add_action( 'admin_notices', 'hello_dolly' ); -// -// // We need some CSS to position the paragraph. -// function dolly_css() { -// echo " -// -// "; -// } -// -// add_action( 'admin_head', 'dolly_css' );