Files
42_INT_13_inception/Makefile
hulamy a7ba45c4ad makefile added down rule
+ makefile change back to user instead of home
2022-09-26 16:38:19 +02:00

92 lines
2.3 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"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
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
# 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)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
all: build up
volumes:
sed -i "s/^LOGIN=.*/LOGIN=$(V_USER)/g" ./srcs/.env
mkdir -p $(VOLUMES_D)
build:
docker-compose -f $(COMPOSE) build
up: volumes
docker-compose -f $(COMPOSE) up -d
down:
docker-compose -f $(COMPOSE) 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
fclean-images: clean
- docker stop $(RUNNING)
docker system prune -af
fclean-volumes: clean
- docker volume rm $(VOLUMES)
- rm -rf $(VOLUMES_D)
fclean: fclean-images fclean-volumes
re: fclean all
.PHONY : all $(VOLUMES_D) build up list clean fclean re