build from inception
This commit is contained in:
93
Makefile
Normal file
93
Makefile
Normal file
@@ -0,0 +1,93 @@
|
||||
|
||||
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
|
||||
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)
|
||||
# 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:
|
||||
- bash -c 'echo -e "\n# adding for inception (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user