fixed an error with path to volumes

This commit is contained in:
asus
2023-09-11 13:45:00 +02:00
parent 14a1ae7120
commit 0b78df0d5d
3 changed files with 86 additions and 19 deletions

View File

@@ -22,30 +22,61 @@ RESET = "\e[0m"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
COMPOSE = ./srcs/docker-compose.yml
COMPOSE = ./srcs/docker-compose.yml
VOLUMES_D = $(shell grep "^HOST_VOLUME" ./srcs/.env | cut -d "=" -f 2)
# 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,$(HOME),$(EXPENDED_ENV_VAR))
EXPENDED_ENV_VAR := $(subst $$PWD_PATH,$(shell pwd),$(EXPENDED_ENV_VAR))
EXPENDED_ENV_VAR := $(EXPENDED_ENV_VAR:EXPEND_%=%)
WP_URL = $(shell grep "WP_URL" ./srcs/.env | cut -d "=" -f 2)
# 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))))
# url for wordpress, use in makefile to change local
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
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)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
all: volumes build up
all: require build up
volumes:
require:
# remove all the lines starting with "HOST_VOLUME_" in .env
@sed -i "/^HOST_VOLUME_/d" ./srcs/.env
# add new expended lines starting with "HOST_VOLUME_" after the line "# EXPENDED LINES :" in .env
@$(foreach val,$(EXPENDED_ENV_VAR),sed -i "/^# EXPENDED LINES/a\$(val)" ./srcs/.env;)
# create the volumes directories
mkdir -p $(VOLUMES_D)
# create the ssl folder to avoid pbm at nginx docker creation
mkdir -p ./srcs/requirements/nginx/conf/ssl
# verify if the wordpress url is added to the local path
- if ! grep "127.0.0.1 $(WP_URL)" /etc/hosts 2> /dev/null; then \
bash -c 'echo -e "\n# adding for lejourduprof (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'; \
fi
build:
- 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
mkdir -p ./srcs/requirements/nginx/conf/ssl
docker compose -f $(COMPOSE) build
up:
@@ -89,5 +120,5 @@ erase_v:
- rm -rf $(VOLUMES_D)
new: erase_v re
.PHONY : all $(VOLUMES_D) build up list clean fclean re erase_v new
.PHONY : all $(VOLUMES_D) require build up list clean fclean re erase_v new