From 4dca5a47602919ddac3181044e9a2ed1d0418853 Mon Sep 17 00:00:00 2001 From: lenovo Date: Sat, 29 Oct 2022 17:11:25 +0200 Subject: [PATCH] there is a map with a marker, and the docker don't generate a new certificate all the time --- .gitignore | 2 + Makefile | 19 ++++---- srcs/.env | 17 +++++-- srcs/docker-compose.yml | 48 +++++++++++-------- srcs/plugins/google_map/google_map | 1 + srcs/plugins/google_map/index.php | 3 +- srcs/plugins/map_prof/map_prof | 1 + srcs/plugins/map_prof/map_prof.php | 31 +++++++++--- srcs/plugins/map_prof/style.css | 4 ++ srcs/requirements/mariadb/Dockerfile | 38 ++++----------- srcs/requirements/nginx/Dockerfile | 28 ++++++----- .../nginx/conf/inception_nginx.conf | 8 ---- srcs/requirements/nginx/conf/index.html | 1 - srcs/requirements/wordpress/Dockerfile | 10 ++-- .../wordpress/conf/wp_entrypoint.sh | 24 ++++++---- 15 files changed, 129 insertions(+), 106 deletions(-) create mode 120000 srcs/plugins/google_map/google_map create mode 120000 srcs/plugins/map_prof/map_prof mode change 100755 => 100644 srcs/plugins/map_prof/map_prof.php create mode 100644 srcs/plugins/map_prof/style.css delete mode 100644 srcs/requirements/nginx/conf/index.html diff --git a/.gitignore b/.gitignore index edf39e5..4665bea 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ Thumbs.db *.wmv *.iso +# ssl certificates +ssl/ diff --git a/Makefile b/Makefile index 4bd5a05..304cdb3 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,10 @@ RESET = "\e[0m" COMPOSE = ./srcs/docker-compose.yml -VOLUME_PATH = $(shell grep -w "MAP_VOLUMES" ./srcs/.env | cut -d "=" -f 2) -VOLUMES_D = $(VOLUME_PATH)/wp_volume \ - $(VOLUME_PATH)/db_volume +VOLUMES_D = $(shell grep "^HOST_VOLUME" ./srcs/.env | cut -d "=" -f 2) +#VOLUME_PATH = $(shell grep "^HOST_VOLUME" ./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 @@ -37,18 +38,18 @@ VOLUMES = $(shell docker volume ls -q) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -all: build up +all: volumes build up volumes: mkdir -p $(VOLUMES_D) build: - - if ! grep "127.0.0.1 ${WP_URL}" /etc/hosts 2> /dev/null; then \ + - 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 +up: docker-compose -f $(COMPOSE) up -d down: @@ -86,8 +87,8 @@ re: fclean all # !! remove everything everything erase_v: - - rm -rf ${VOLUMES_D} -hard: erase_v re + - rm -rf $(VOLUMES_D) +new: erase_v re -.PHONY : all $(VOLUMES_D) build up list clean fclean re +.PHONY : all $(VOLUMES_D) build up list clean fclean re erase_v new diff --git a/srcs/.env b/srcs/.env index 95f4b25..a04deb8 100644 --- a/srcs/.env +++ b/srcs/.env @@ -1,4 +1,8 @@ +# NGINX SETUP + +NG_VOLUME_CERTS=/etc/ssl + # MARIADB SETUP DB_HOST=mariadb @@ -9,8 +13,8 @@ DB_PSWD="too bad you have read this now i have to erase your memory" # WORDPRESS SETUP WP_URL=local_lejourduprof.com -WP_DIR=/var/www/html -WP_PLUGIN_DIR=/home/www-data/ +WP_VOLUME_DIR=/var/www/html +WP_VOLUME_PLUGINS=/home/www-data WP_TITLE=title WP_ADMIN=hulamy @@ -25,6 +29,11 @@ WP_USER_EMAIL=moehu36@42.fr MAX_UPLOAD_SIZE=512 EXECUTION_TIME=300 -MAP_VOLUMES=/home/lenovo/data/lejourduprof -MAP_VOLUMES_PLUGINS=/home/lenovo/42/lejourduprof/srcs/plugins + +# HOST (start with "HOST_VOLUME" for makefile) + +HOST_VOLUME_WP=/home/lenovo/data/lejourduprof/wp_volume +HOST_VOLUME_DB=/home/lenovo/data/lejourduprof/db_volume +HOST_VOLUME_PLUGINS=/home/lenovo/42/lejourduprof/srcs/plugins +HOST_VOLUME_CERTS=/home/lenovo/42/lejourduprof/srcs/requirements/nginx/conf/ssl diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 1d30288..a31e998 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -22,15 +22,18 @@ services: - inception ports: - "443:443" - #- "80:80" volumes: - - wp_volume:${WP_DIR} - - wp_plugins:${WP_PLUGIN_DIR} + - wp_volume:${WP_VOLUME_DIR} + - wp_plugins:${WP_VOLUME_PLUGINS} + - ng_certs:${NG_VOLUME_CERTS} build: context: ./requirements/nginx args: - WP_URL=${WP_URL} - MAX_UPLOAD_SIZE=${MAX_UPLOAD_SIZE} + - WP_VOLUME_DIR=${WP_VOLUME_DIR} + - WP_VOLUME_PLUGINS=${WP_VOLUME_PLUGINS} + - NG_VOLUME_CERTS=${NG_VOLUME_CERTS} image: nginx container_name: nginx_container depends_on: @@ -65,12 +68,13 @@ services: networks: - inception volumes: - - wp_volume:${WP_DIR} - - wp_plugins:${WP_PLUGIN_DIR} + - wp_volume:${WP_VOLUME_DIR} + - wp_plugins:${WP_VOLUME_PLUGINS} build: context: ./requirements/wordpress args: - - WP_DIR=${WP_DIR} + - WP_VOLUME_DIR=${WP_VOLUME_DIR} + - WP_VOLUME_PLUGINS=${WP_VOLUME_PLUGINS} - MAX_UPLOAD_SIZE=${MAX_UPLOAD_SIZE} - EXECUTION_TIME=${EXECUTION_TIME} image: wordpress @@ -81,24 +85,30 @@ services: # specify path to named volumes : https://docs.docker.com/compose/compose-file/compose-file-v3/#volume-configuration-reference volumes: - wp_volume: - driver: local - driver_opts: - type: none - o: "bind" - device: ${MAP_VOLUMES}/wp_volume - wp_plugins: - driver: local - driver_opts: - type: none - o: "bind" - device: ${MAP_VOLUMES_PLUGINS} db_volume: driver: local driver_opts: type: none o: "bind" - device: ${MAP_VOLUMES}/db_volume + device: ${HOST_VOLUME_DB} + wp_volume: + driver: local + driver_opts: + type: none + o: "bind" + device: ${HOST_VOLUME_WP} + wp_plugins: + driver: local + driver_opts: + type: none + o: "bind" + device: ${HOST_VOLUME_PLUGINS} + ng_certs: + driver: local + driver_opts: + type: none + o: "bind" + device: ${HOST_VOLUME_CERTS} networks: inception: diff --git a/srcs/plugins/google_map/google_map b/srcs/plugins/google_map/google_map new file mode 120000 index 0000000..3704f62 --- /dev/null +++ b/srcs/plugins/google_map/google_map @@ -0,0 +1 @@ +/home/www-data//google_map \ No newline at end of file diff --git a/srcs/plugins/google_map/index.php b/srcs/plugins/google_map/index.php index 5025caf..e5065fa 100644 --- a/srcs/plugins/google_map/index.php +++ b/srcs/plugins/google_map/index.php @@ -56,6 +56,7 @@ function my_init_script() { wp_enqueue_script('my_script', $script_path, array('jquery')); $style_path = plugins_url('style.css', __FILE__); wp_enqueue_style('my_style', $style_path); + console_log("urlencode : " . urlencode("128 rue de la croix nivert, paris")); } function show_google_map() { @@ -65,7 +66,7 @@ function show_google_map() { $GoogleMap_zoom = get_option('map_zoom_value'); //src="https://maps.googleapis.com/maps/api/geocode/json?address=paris&key=AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE ?> -
diff --git a/srcs/plugins/map_prof/map_prof b/srcs/plugins/map_prof/map_prof new file mode 120000 index 0000000..5fcaf6e --- /dev/null +++ b/srcs/plugins/map_prof/map_prof @@ -0,0 +1 @@ +/home/www-data//map_prof \ No newline at end of file diff --git a/srcs/plugins/map_prof/map_prof.php b/srcs/plugins/map_prof/map_prof.php old mode 100755 new mode 100644 index ba8b8c2..03c6fe7 --- a/srcs/plugins/map_prof/map_prof.php +++ b/srcs/plugins/map_prof/map_prof.php @@ -1,8 +1,4 @@ @@ -43,7 +45,7 @@ function print_content($content){ // print only on the page 'map', and other conditions // https://developer.wordpress.org/reference/hooks/the_content/ - if (!( is_page('map') && in_the_loop() && is_main_query() )) + if (!( is_page('map_prof') && in_the_loop() && is_main_query() )) return $content; // https://developer.wordpress.org/reference/functions/get_posts/ @@ -90,9 +92,24 @@ function print_content($content){ // $content .= "

"; //} - //$content .= "

OSM map 2

"; + $content .= '
'; + $content .= ''; + $content .= ''; + return $content; }; -//add_action('the_content', 'print_content', 1); +add_action('the_content', 'print_content', 1); ?> diff --git a/srcs/plugins/map_prof/style.css b/srcs/plugins/map_prof/style.css new file mode 100644 index 0000000..9c0458b --- /dev/null +++ b/srcs/plugins/map_prof/style.css @@ -0,0 +1,4 @@ +#map { + height: 500px; + width: 100%; +} diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile index 461e42f..528e8ba 100644 --- a/srcs/requirements/mariadb/Dockerfile +++ b/srcs/requirements/mariadb/Dockerfile @@ -1,34 +1,16 @@ -# debian ----------------------------------------------------- -# FROM debian:buster -# -# # vim and bash for debug -# RUN apt update && apt install -y \ -# mariadb-client \ -# mariadb-server \ -# vim bash \ -# && \ -# rm -rf /var/lib/apt/lists/* -# -# # config file .cnf : -# COPY ./conf/50-server.cnf.debian /etc/mysql/mariadb.conf.d/50-server.cnf +FROM alpine:3.15 -# alpine ----------------------------------------------------- +# vim and bash for debug +RUN apk update && apk add \ + mariadb \ + mariadb-client \ + vim bash \ + && \ + rm -rf /var/cache/apk* - FROM alpine:3.15 - - # vim and bash for debug - RUN apk update && apk add \ - mariadb \ - mariadb-client \ - vim bash \ - && \ - rm -rf /var/cache/apk* - - # config file .cnf : - COPY ./conf/mariadb-server.cnf.alpine /etc/my.cnf.d/mariadb-server.cnf - -# common ----------------------------------------------------- +# config file .cnf : +COPY ./conf/mariadb-server.cnf.alpine /etc/my.cnf.d/mariadb-server.cnf ARG DB_HOST ARG DB_NAME diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 1de31fd..549d028 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -16,10 +16,15 @@ COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ RUN adduser -S www-data && \ adduser www-data www-data -RUN mkdir -p /var/www/html - ARG WP_URL ARG MAX_UPLOAD_SIZE +ARG WP_VOLUME_DIR +ARG WP_VOLUME_PLUGINS +ARG NG_VOLUME_CERTS + +# create and empty volumes dir +RUN mkdir -p ${WP_VOLUME_DIR} ${WP_VOLUME_PLUGINS} ${NG_VOLUME_CERTS} && \ + rm -rf ${WP_VOLUME_DIR}/* ${WP_VOLUME_PLUGINS}/* ${NG_VOLUME_CERTS}/* # replace WP_URL RUN sed -i "s/\${WP_URL}/${WP_URL}/g" /etc/nginx/http.d/inception_nginx.conf @@ -27,18 +32,15 @@ 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/ - # create ssl certificate -RUN mkdir -p /etc/ssl/private /etc/ssl/certs -RUN openssl req -newkey rsa:2048 -nodes -x509 -days 365 \ - -subj "/C=fr/ST=ile-de-france/L=paris/O=42/OU=inception/CN=${WP_URL}" \ - -keyout /etc/ssl/private/${WP_URL}.key \ - -out /etc/ssl/certs/${WP_URL}.crt +COPY ./conf/ssl ${NG_VOLUME_CERTS} +RUN if [ -z "$(ls -A ${NG_VOLUME_CERTS} 2>/dev/null)" ]; then \ + mkdir ${NG_VOLUME_CERTS}/private ${NG_VOLUME_CERTS}/certs; \ + openssl req -newkey rsa:2048 -nodes -x509 -days 365 \ + -subj "/C=fr/ST=ile-de-france/L=paris/O=42/OU=inception/CN=${WP_URL}" \ + -keyout ${NG_VOLUME_CERTS}/private/${WP_URL}.key \ + -out ${NG_VOLUME_CERTS}/certs/${WP_URL}.crt; \ + fi ENTRYPOINT [ "nginx", "-g", "daemon off;" ] diff --git a/srcs/requirements/nginx/conf/inception_nginx.conf b/srcs/requirements/nginx/conf/inception_nginx.conf index c49b32c..b4df861 100644 --- a/srcs/requirements/nginx/conf/inception_nginx.conf +++ b/srcs/requirements/nginx/conf/inception_nginx.conf @@ -1,13 +1,5 @@ # doc : https://nginx.org/en/docs/dirindex.html -# WIP redirect http to https -#server { -# listen 80; -# listen [::]:80; -# server_name _; -# return 301 https://$host$request_uri; -#} - server { listen 443 ssl; # for ipv4, on port 443, specifying that accepted connections should works in ssl mode listen [::]:443 ssl; # for ipv6 diff --git a/srcs/requirements/nginx/conf/index.html b/srcs/requirements/nginx/conf/index.html deleted file mode 100644 index a95200f..0000000 --- a/srcs/requirements/nginx/conf/index.html +++ /dev/null @@ -1 +0,0 @@ -hello world ! diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index a574839..b7c7bc4 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -18,12 +18,13 @@ RUN rm -rf /var/lib/apt/lists/* COPY ./conf/www.conf /etc/php7/php-fpm.d/ RUN mkdir /run/php/ -ARG WP_DIR +ARG WP_VOLUME_DIR ARG MAX_UPLOAD_SIZE ARG EXECUTION_TIME -# create wp directory -RUN mkdir -p ${WP_DIR} +# create and empty volume dir +RUN mkdir -p ${WP_VOLUME_DIR} && \ + rm -rf ${WP_VOLUME_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 && \ @@ -36,9 +37,6 @@ RUN adduser -S www-data && \ ENV PHP_VERSION="php-fpm7" -# 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 &&\ chmod +x wp-cli.phar && \ diff --git a/srcs/requirements/wordpress/conf/wp_entrypoint.sh b/srcs/requirements/wordpress/conf/wp_entrypoint.sh index 1a4dc02..fd2e9aa 100644 --- a/srcs/requirements/wordpress/conf/wp_entrypoint.sh +++ b/srcs/requirements/wordpress/conf/wp_entrypoint.sh @@ -13,31 +13,31 @@ RESET="\e[0m" # install wordpress with cli : https://make.wordpress.org/cli/handbook/how-to-install/ # commands : https://developer.wordpress.org/cli/commands/ echo -e ${YELLOW}download wordpress :${RESET} -if ! wp core version --path="${WP_DIR}" 2> /dev/null +if ! wp core version --path="${WP_VOLUME_DIR}" 2> /dev/null then - mkdir -p ${WP_DIR} - wp core download --path="${WP_DIR}" --allow-root + mkdir -p ${WP_VOLUME_DIR} + wp core download --path="${WP_VOLUME_DIR}" --allow-root else echo -e ${GREEN}already there !${RESET} fi # create config file : echo -e ${YELLOW}config wordpress :${RESET} -if ! wp config path --path="${WP_DIR}" --quiet 2> /dev/null +if ! wp config path --path="${WP_VOLUME_DIR}" --quiet 2> /dev/null then wp config create \ --dbhost="${DB_HOST}" \ --dbname="${DB_NAME}" \ --dbuser="${DB_USER}" \ --dbpass="${DB_PSWD}" \ - --path="${WP_DIR}" --allow-root + --path="${WP_VOLUME_DIR}" --allow-root else echo -e ${GREEN}already configured !${RESET} fi # install wordpress : echo -e ${YELLOW}install wordpress :${RESET} -if ! wp core is-installed --path="${WP_DIR}" 2> /dev/null +if ! wp core is-installed --path="${WP_VOLUME_DIR}" 2> /dev/null then wp core install \ --url="${WP_URL}" \ @@ -46,19 +46,19 @@ then --admin_email="${WP_ADMIN_EMAIL}" \ --admin_password="${WP_ADMIN_PSWD}" \ --skip-email \ - --path="${WP_DIR}" --allow-root + --path="${WP_VOLUME_DIR}" --allow-root else echo -e ${GREEN}already installed !${RESET} fi # create user : echo -e ${YELLOW}create wordpress user :${RESET} -if ! wp user get ${WP_USER} --path="${WP_DIR}" --field=login 2> /dev/null +if ! wp user get ${WP_USER} --path="${WP_VOLUME_DIR}" --field=login 2> /dev/null then wp user create \ "${WP_USER}" "${WP_USER_EMAIL}" \ --user_pass="${WP_USER_PSWD}" \ - --path="${WP_DIR}" --allow-root + --path="${WP_VOLUME_DIR}" --allow-root else echo -e ${GREEN}already created !${RESET} fi @@ -68,7 +68,11 @@ chown -R www-data:www-data /var/www/* chmod 755 -R /var/www/* # symlinks for folders found in host plugins/ -# todo +plugins=$(ls ${WP_VOLUME_PLUGIN}) +for dir in $plugins; do + ln -s ${WP_VOLUME_PLUGIN}/$dir ${WP_VOLUME_DIR}/wp-content/plugins/$dir +done + exec "${PHP_VERSION}" -FR