Files
2023_WEBSITE_jipf/Makefile

128 lines
4.1 KiB
Makefile

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"
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
ENV_PATH := ./srcs/.env
# get env variables from .env file :
SOURCE_ENV := . $(ENV_PATH)
# list of volumes
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 $(SOURCE_ENV) ; echo $$WP_URL )
WP_COMPLETE_URL = $(shell $(SOURCE_ENV) ; echo $$WP_COMPLETE_URL )
# list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile
RUNNING := $(shell docker ps -q)
# list of volumes
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:
# 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 ! awk "/127.0.0.1/ && /$(WP_URL)/" /etc/hosts 2> /dev/null; then \
echo $(B_PURPLE)"nop ! trying to add it (might need sudo)"$(RESET); \
bash -c 'echo -e "\n adding for lejourduprof (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'; \
if ! awk "/127.0.0.1/ && /$(WP_URL)/" /etc/hosts 2> /dev/null; then \
echo $(B_RED)"it didn't succeed :/ try again with sudo"$(RESET); \
else \
echo $(B_GREEN)"it has been succesfully added :)"$(RESET); \
fi \
fi
build:
docker compose -f $(COMPOSE_FILE) build
# --progress plain : everything will be output at build time, you can see commands like "echo" or "ls" in RUN command in dockerfile
# --no-cache : this will prevent builder to use previous cached action, so it rebuild everything
build_logs:
docker compose -f $(COMPOSE_FILE) build --progress plain --no-cache
up:
docker compose -f $(COMPOSE_FILE) up -d
@echo $(B_PURPLE)"you can now connect at "$(B_YELLOW)"https://$(WP_COMPLETE_URL)"$(B_PURPLE)" or 127.0.0.1"$(RESET)
down:
docker compose -f $(COMPOSE_FILE) down
# list images, containers, volumes
list:
@echo $(B_YELLOW)"\nimages:"$(RESET)
@docker images -a
@echo $(B_YELLOW)"\nvolumes:"$(RESET)
@docker volume ls
@echo $(B_YELLOW)"\nvolumes content:"$(RESET)
- @ls $(VOLUMES_D)
@echo $(B_YELLOW)"\nnetworks:"$(RESET)
@docker network ls
@echo $(B_YELLOW)"\ncontainers:"$(RESET)
@docker ps -a
@echo ""
# remove project images and containers not used
clean:
- docker stop $(RUNNING)
docker network prune -f
docker system prune -f
# remove everything except local volumes data
fclean-images: clean
- docker stop $(RUNNING)
docker system prune -af
fclean-volumes: clean
- docker volume rm $(VOLUMES)
fclean: fclean-images fclean-volumes
re: fclean all
# !! remove everything everything
erase:
- rm -rf $(VOLUMES_D)
$(MAKE) fclean
new: erase $(NAME)
.PHONY : all $(VOLUMES_D) require build up list clean fclean re erase new require