diff --git a/Makefile b/Makefile index f5ae27f..3f94f53 100644 --- a/Makefile +++ b/Makefile @@ -1,112 +1,70 @@ -GRAY = "\e[0;30m" -RED = "\e[0;31m" -GREEN = "\e[0;32m" -YELLOW = "\e[0;33m" -BLUE = "\e[0;34m" -PURPLE = "\e[0;35m" -CYAN = "\e[0;36m" -WHITE = "\e[0;37m" +GRAY := "\e[0;30m" +RED := "\e[0;31m" +GREEN := "\e[0;32m" +YELLOW := "\e[0;33m" +BLUE := "\e[0;34m" +PURPLE := "\e[0;35m" +CYAN := "\e[0;36m" +WHITE := "\e[0;37m" -B_GRAY = "\e[1;30m" -B_RED = "\e[1;31m" -B_GREEN = "\e[1;32m" -B_YELLOW = "\e[1;33m" -B_BLUE = "\e[1;34m" -B_PURPLE = "\e[1;35m" -B_CYAN = "\e[1;36m" -B_WHITE = "\e[1;37m" +B_GRAY := "\e[1;30m" +B_RED := "\e[1;31m" +B_GREEN := "\e[1;32m" +B_YELLOW := "\e[1;33m" +B_BLUE := "\e[1;34m" +B_PURPLE := "\e[1;35m" +B_CYAN := "\e[1;36m" +B_WHITE := "\e[1;37m" -RESET = "\e[0m" +RESET := "\e[0m" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value \ . := no reevaluat when used # +# VARIABLES . value . != set result of command # +# . name is case sensitive . ?= set if not already set # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -COMPOSE_FILE = ./srcs/docker-compose.yml +COMPOSE_FILE := ./srcs/docker-compose.yml +ENV_PATH := ./srcs/.env -# in makefile you can use an env variable directly as a make variable : -# -> https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html#SEC68 -# so if you want to get the home directory you can use $(HOME) -# however, this will not give the same result if you run make in sudo, ex : -# make : /home/asususus -# sudo make : /root -# but you can use this command `eval echo "~$SUDO_USER"` to get -# the home directory of the user using sudo, it works in non-sudo also : -# - echo "$SUDO_USER" : -# - in normal mode it output : "" -# - in sudo mode it output the user : "username" -# - same as $USER in normal mode -# - echo "~$SUDO_USER" : -# - in linux "~USER" is the home directory of a user -# - but echo "something" will treat ~ as a string litteral -# - so the output in mormal mode will be : "~" -# - and in sudo mode it will be : "~username" -# - eval echo "~$SUDO_USER" : -# - eval will evaluate the expression and perform expansion one more time -# - so it will evaluate the output of `echo "~$SUDO_USER"` -# - in normal mode : -# - it will evaluate : "~" -# - and ouptput : "/home/username" -# - in sudo mode : -# - it will evaluate : "~username" -# - and output : "/home/username" -# - because "~username" expand in the home (~) directory of given user -# https://stackoverflow.com/questions/77088135/makefile-subst-doesnt-use-make-variable-as-expected -USER_HOME := $(shell eval echo "~$$SUDO_USER") -# extract env variables in .env file -# then expend the home path -# then expend the pwd path -# and finally remove the leading "EXPEND_" word -EXPENDED_ENV_VAR := $(shell grep "^#EXPEND_" ./srcs/.env) -EXPENDED_ENV_VAR := $(subst $$HOME_PATH,$(USER_HOME),$(EXPENDED_ENV_VAR)) -EXPENDED_ENV_VAR := $(subst $$PWD_PATH,$(shell pwd),$(EXPENDED_ENV_VAR)) -EXPENDED_ENV_VAR := $(EXPENDED_ENV_VAR:#EXPEND_%=%) - -# this creates a list of the path from the list of the variables : -# VAR_1=/path/to_1 VAR_2=/path/to_2 -# becomes : -# /path/to_1 /path/to_2 -# first, foreach execute an action on each space separated parts : the variables -# - VAR_1=/path/to_1 -# - VAR_2=/path/to_2 -# then on each of them, it substitute the "=" with a space " " : -# - VAR_1 /path/to_1 -# - VAR_2 /path/to_2 -# and it only keeps the second word : -# - /path/to_1 -# - /path/to_2 -VOLUMES_D = $(foreach val,$(EXPENDED_ENV_VAR),$(word 2, $(subst =, ,$(val)))) +# list of volumes +SOURCE_ENV := . $(ENV_PATH) +VOLUME_ENV := set | grep "^HOST_VOLUME_" | cut -d "=" -f 2 +VOLUMES_D = $(shell $(SOURCE_ENV) ; $(VOLUME_ENV) ) # url for wordpress, use in makefile to change local -WP_URL = $(shell grep "WP_URL" ./srcs/.env | cut -d "=" -f 2) +WP_URL := $(shell grep "WP_URL" $(ENV_PATH) | cut -d "=" -f 2) # list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile -RUNNING = $(shell docker ps -q) +RUNNING := $(shell docker ps -q) # list of volumes -VOLUMES = $(shell docker volume ls -q) +VOLUMES := $(shell docker volume ls -q) + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + all: require build up logs: require build_logs up require: -# remove all the lines starting with "HOST_VOLUME_" in .env - @echo $(B_PURPLE)"removes all lines starting with 'HOST_VOLUMES' in .env"$(RESET) - sed -i "/^HOST_VOLUME_/d" ./srcs/.env -# add new expended lines starting with "HOST_VOLUME_" after the line "# EXPENDED LINES :" in .env - @echo $(B_PURPLE)"add new expended lines starting with 'HOST_VOLUME_' in .env"$(RESET) - $(foreach val,$(EXPENDED_ENV_VAR),sed -i "/^# EXPENDED LINES/a\$(val)" ./srcs/.env;) +# create .env file + @echo $(B_PURPLE)"create the .env file"$(RESET) + ./srcs/env_generator/create_env.sh ./srcs/model.env # create the volumes directories @echo $(B_PURPLE)"create the volumes directories"$(RESET) mkdir -p $(VOLUMES_D) # verify if the wordpress url is added to the local path @echo $(B_PURPLE)"verify if the wordpress url is added to the local path"$(RESET) - - 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 \ echo $(B_PURPLE)"nop ! adding it"$(RESET) \ - bash -c 'echo -e "\n# adding for lejourduprof (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'; + bash -c 'echo -e "\n# adding for lejourduprof (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'; \ fi build: diff --git a/srcs/.env b/srcs/.env index fddeca5..fea73ab 100644 --- a/srcs/.env +++ b/srcs/.env @@ -1,22 +1,18 @@ DB_HOST=mariadb -DB_NAME=db_wp_inception -DB_PSWD='too bad you have read this now i have to erase your memory' -DB_USER=user_wp_inception +DB_NAME=db_wp_jipf +DB_PSWD='you dont want to know' +DB_USER=user_wp_jipf EXECUTION_TIME=300 HOME_PATH=/home/asususus HOST_VOLUME_DB=/home/asususus/data/lejourduprof/db_volume -HOST_VOLUME_PLUGINS=/srcs/plugins HOST_VOLUME_WP=/home/asususus/data/lejourduprof/wp_volume MAX_UPLOAD_SIZE=512 NG_VOLUME_CERTS=/etc/ssl -WP_ADMIN_EMAIL=hulamy@42.fr -WP_ADMIN=hulamy +PROJECT=jipf +WP_ADMIN=admin +WP_ADMIN_EMAIL=admin@email.fr WP_ADMIN_PSWD='you shall not password !' WP_PORT=3003 WP_TITLE=title WP_URL=local_lejourduprof.com -WP_USER_EMAIL=moehu36@42.fr -WP_USER=moehu36 -WP_USER_PSWD='it'\''s a secret for nobody' WP_VOLUME_DIR=/var/www/html -WP_VOLUME_PLUGINS=/home/www-data diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index de16f84..257993c 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -17,14 +17,12 @@ services: - "${WP_PORT}:443" volumes: - wp_volume:${WP_VOLUME_DIR} - - wp_plugins:${WP_VOLUME_PLUGINS} 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 @@ -61,12 +59,10 @@ services: - inception volumes: - wp_volume:${WP_VOLUME_DIR} - - wp_plugins:${WP_VOLUME_PLUGINS} build: context: ./requirements/wordpress args: - WP_VOLUME_DIR=${WP_VOLUME_DIR} - - WP_VOLUME_PLUGINS=${WP_VOLUME_PLUGINS} - MAX_UPLOAD_SIZE=${MAX_UPLOAD_SIZE} - EXECUTION_TIME=${EXECUTION_TIME} image: wordpress @@ -89,12 +85,6 @@ volumes: type: none o: "bind" device: ${HOST_VOLUME_WP} - wp_plugins: - driver: local - driver_opts: - type: none - o: "bind" - device: ${HOST_VOLUME_PLUGINS} networks: inception: diff --git a/srcs/env_generator/create_env.sh b/srcs/env_generator/create_env.sh old mode 100644 new mode 100755 diff --git a/srcs/model.env b/srcs/model.env index e9a1bd9..543a1d0 100644 --- a/srcs/model.env +++ b/srcs/model.env @@ -1,4 +1,6 @@ +PROJECT=jipf + # NGINX SETUP NG_VOLUME_CERTS=/etc/ssl @@ -7,25 +9,21 @@ MAX_UPLOAD_SIZE=512 # MARIADB SETUP DB_HOST=mariadb -DB_NAME=db_wp_inception -DB_USER=user_wp_inception -DB_PSWD="too bad you have read this now i have to erase your memory" +DB_NAME=db_wp_${PROJECT} +DB_USER=user_wp_${PROJECT} +DB_PSWD="you dont want to know" # WORDPRESS SETUP WP_URL=local_lejourduprof.com WP_PORT=3003 WP_VOLUME_DIR=/var/www/html -WP_VOLUME_PLUGINS=/home/www-data +#WP_VOLUME_PLUGINS=/home/www-data WP_TITLE=title -WP_ADMIN=hulamy +WP_ADMIN=admin WP_ADMIN_PSWD="you shall not password !" -WP_ADMIN_EMAIL=hulamy@42.fr - -WP_USER=moehu36 -WP_USER_PSWD="it's a secret for nobody" -WP_USER_EMAIL=moehu36@42.fr +WP_ADMIN_EMAIL=admin@email.fr # MAP @@ -61,5 +59,4 @@ HOME_PATH=$(eval echo "~$SUDO_USER") HOST_VOLUME_WP=${HOME_PATH}/data/lejourduprof/wp_volume HOST_VOLUME_DB=${HOME_PATH}/data/lejourduprof/db_volume -HOST_VOLUME_PLUGINS=${PWD_PATH}/srcs/plugins diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 47cda04..4ca42fc 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -24,7 +24,6 @@ RUN adduser -S www-data && \ ARG WP_URL ARG MAX_UPLOAD_SIZE ARG WP_VOLUME_DIR -ARG WP_VOLUME_PLUGINS ARG NG_VOLUME_CERTS # replace WP_URL diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index 1ac4399..360c7cd 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -27,7 +27,6 @@ COPY ./conf/www.conf /etc/php7/php-fpm.d/ RUN mkdir /run/php/ ARG WP_VOLUME_DIR -ARG WP_VOLUME_PLUGINS ARG MAX_UPLOAD_SIZE ARG EXECUTION_TIME diff --git a/srcs/requirements/wordpress/conf/wp_entrypoint.sh b/srcs/requirements/wordpress/conf/wp_entrypoint.sh index c5386da..406101f 100644 --- a/srcs/requirements/wordpress/conf/wp_entrypoint.sh +++ b/srcs/requirements/wordpress/conf/wp_entrypoint.sh @@ -61,26 +61,16 @@ then --skip-email \ --path="${WP_VOLUME_DIR}" --allow-root - #wp user create \ - echo -e ${YELLOW}wp user create...${RESET} - php wp-cli.phar user create \ - "${WP_USER}" "${WP_USER_EMAIL}" \ - --user_pass="${WP_USER_PSWD}" \ - --path="${WP_VOLUME_DIR}" --allow-root - echo -e ${YELLOW}chown and chmod...${RESET} chown -R www-data:www-data /var/www/* chmod 755 -R /var/www/* - echo -e ${YELLOW}plugins...${RESET} - plugins=$(ls ${WP_VOLUME_PLUGINS}) - for dir in $plugins; do - ln -s ${WP_VOLUME_PLUGINS}/$dir ${WP_VOLUME_DIR}/wp-content/plugins/$dir - done echo -e ${GREEN}done !${RESET} + else echo -e ${GREEN}wp is installed${RESET} + #https://stackoverflow.com/questions/56344567/wordpress-prevent-redirection-to-main-url echo -e ${YELLOW}checking config.php file with current url...${RESET} HOME=$(php wp-cli.phar config get WP_HOME --path=${WP_VOLUME_DIR}) if [ ${HOME} != ${COMPLETE_URL} ] ; then @@ -93,20 +83,5 @@ else fi -# HOME=$(php wp-cli.phar config get WP_HOME --path=${WP_VOLUME_DIR}) -# echo -e "HOME : ${HOME}\n" -# SITEURL=$(php wp-cli.phar config get WP_SITEURL --path=${WP_VOLUME_DIR}) -# echo -e "SITEURL : ${SITEURL}\n" - LIST=$(php wp-cli.phar config list --path=${WP_VOLUME_DIR} --format="dotenv") - echo -e "LIST : ${LIST}\n" -# -# #DB_HOME=$(php wp-cli.phar db query "SELECT option_value FROM wp_options WHERE option_name = 'home'" --path=${WP_VOLUME_DIR}) -# #DB_HOME=$(php wp-cli.phar db query 'SELECT * FROM wp_options WHERE option_name LIKE "%home%"' --skip-column-names --path=${WP_VOLUME_DIR}) -# DB_HOME=$(php wp-cli.phar db query 'SELECT * FROM wp_options WHERE option_name="home"' --skip-column-names --path=${WP_VOLUME_DIR}) -# echo -e "DB_HOME :\n${DB_HOME}\n" -# DB_URL=$(php wp-cli.phar db query 'SELECT * FROM wp_options WHERE option_name="siteurl"' --skip-column-names --path=${WP_VOLUME_DIR}) -# echo -e "DB_URL :\n${DB_URL}\n" - - exec "${PHP_VERSION}" -FR