in makefile fixed user var to be hulamy when sudo && rm volumes directories
This commit is contained in:
38
Makefile
38
Makefile
@@ -24,16 +24,18 @@ RESET = "\e[0m"
|
|||||||
|
|
||||||
COMPOSE = ./srcs/docker-compose.yml
|
COMPOSE = ./srcs/docker-compose.yml
|
||||||
|
|
||||||
V_USER = $(shell echo $(USER))
|
#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 who | head -1 | cut -d " " -f 1)
|
||||||
VOLUMES_D = /home/$(V_USER)/data/wp_volume \
|
VOLUMES_D = /home/$(V_USER)/data/wp_volume \
|
||||||
/home/$(V_USER)/data/db_volume
|
/home/$(V_USER)/data/db_volume
|
||||||
|
|
||||||
SUDO =
|
|
||||||
|
|
||||||
# list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile
|
# list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile
|
||||||
RUNNING = $(shell $(SUDO) docker ps -q)
|
RUNNING = $(shell docker ps -q)
|
||||||
# list of volumes
|
# list of volumes
|
||||||
VOLUMES = $(shell $(SUDO) docker volume ls -q)
|
VOLUMES = $(shell docker volume ls -q)
|
||||||
|
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
@@ -45,37 +47,39 @@ $(VOLUMES_D):
|
|||||||
mkdir -p $(VOLUMES_D)
|
mkdir -p $(VOLUMES_D)
|
||||||
|
|
||||||
build:
|
build:
|
||||||
$(SUDO) docker-compose -f $(COMPOSE) build
|
docker-compose -f $(COMPOSE) build
|
||||||
|
|
||||||
up: $(VOLUMES_D)
|
up: $(VOLUMES_D)
|
||||||
$(SUDO) docker-compose -f $(COMPOSE) up
|
docker-compose -f $(COMPOSE) up
|
||||||
|
|
||||||
# list images, containers, volumes
|
# list images, containers, volumes
|
||||||
list:
|
list:
|
||||||
@echo $(B_YELLOW)"\nimages:"$(RESET)
|
@echo $(B_YELLOW)"\nimages:"$(RESET)
|
||||||
@$(SUDO) docker images -a
|
@docker images -a
|
||||||
@echo $(B_YELLOW)"\nvolumes:"$(RESET)
|
@echo $(B_YELLOW)"\nvolumes:"$(RESET)
|
||||||
@$(SUDO) docker volume ls
|
@docker volume ls
|
||||||
@echo $(B_YELLOW)"\nvolumes content:"$(RESET)
|
@echo $(B_YELLOW)"\nvolumes content:"$(RESET)
|
||||||
@ls $(VOLUMES_D)
|
@ls $(VOLUMES_D)
|
||||||
@echo $(B_YELLOW)"\nnetworks:"$(RESET)
|
@echo $(B_YELLOW)"\nnetworks:"$(RESET)
|
||||||
@$(SUDO) docker network ls
|
@docker network ls
|
||||||
@echo $(B_YELLOW)"\ncontainers:"$(RESET)
|
@echo $(B_YELLOW)"\ncontainers:"$(RESET)
|
||||||
@$(SUDO) docker ps -a
|
@docker ps -a
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
# remove project images and containers not used
|
# remove project images and containers not used
|
||||||
clean:
|
clean:
|
||||||
- $(SUDO) docker stop $(RUNNING)
|
- docker stop $(RUNNING)
|
||||||
$(SUDO) docker network prune -f
|
docker network prune -f
|
||||||
$(SUDO) docker system prune -f
|
docker system prune -f
|
||||||
|
|
||||||
# remove everything
|
# remove everything
|
||||||
fclean-images: clean
|
fclean-images: clean
|
||||||
- $(SUDO) docker stop $(RUNNING)
|
- docker stop $(RUNNING)
|
||||||
$(SUDO) docker system prune -af
|
docker system prune -af
|
||||||
fclean-volumes: clean
|
fclean-volumes: clean
|
||||||
- $(SUDO) docker volume rm $(VOLUMES)
|
- docker volume rm $(VOLUMES)
|
||||||
|
fclean-test:
|
||||||
|
- rm -rf $(VOLUMES_D)
|
||||||
fclean: fclean-images fclean-volumes
|
fclean: fclean-images fclean-volumes
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|||||||
Reference in New Issue
Block a user