ptut-virtenv/Makefile

79 lines
2.9 KiB
Makefile
Raw Normal View History

2018-02-16 00:49:02 +00:00
IMAGE_NAME="alp-mdb"
CONTAINER_NAME="inst1"
LOG="/tmp/ptut.virtenv.log"
LOCK="/tmp/ptut.virtenv.lock"
2018-02-16 00:49:02 +00:00
image: build
@echo -n "> Build image..................";
@docker build --force-rm -t $(IMAGE_NAME) . >>$(LOG) 2>&1 && echo "done" || echo "error";
2018-02-16 00:49:02 +00:00
build: docker/main docker/include/*
@echo -n "> Build Dockerfile.............";
2018-02-16 00:49:02 +00:00
@cpp -o Dockerfile docker/main && echo "done" || echo "error";
clean:
@echo -n "> Stop container...............";
@docker stop $(CONTAINER_NAME) >/dev/null 2>&1 && echo "stopped" || echo "already"; true;
@echo -n "> Delete container.............";
@docker rm -f $(CONTAINER_NAME) >/dev/null 2>&1 && echo "deleted" || echo "already"; true;
@echo -n "> Delete image.................";
@docker rmi -f $(IMAGE_NAME) >/dev/null 2>&1 && echo "deleted" || echo "already"; true;
@echo -n "> Delete Dockerfile............";
@rm Dockerfile >/dev/null 2>&1 && echo "done" || echo "already"; true
@echo -n "> Delete log file..............";
@rm $(LOG) >/dev/null 2>&1 && echo "done" || echo "already"; true
@echo -n "> Delete lock file.............";
@rm $(LOCK) >/dev/null 2>&1 && echo "done" || echo "already"; true
run:
@echo ">>> Search running container";
@test ! -f $(LOCK) && echo -e "<<< nothing\n" || (echo -e "<<< found\n\nERR: You must run 'make clean' before running a new container"; exit 1);
@echo ">>> Build image";
@make image;
@echo -e "<<< built\n";
@echo ">>> Container launched";
@touch $(LOCK);
@docker run --name $(CONTAINER_NAME) $(IMAGE_NAME);
@echo -e "<<< stopped\n";
@echo ">>> clean installation" | tee -a $(LOG); \
make clean;
@echo "<<< cleaned";
kill:
@echo -n "Search running container.......";
@test -f $(LOCK) && echo "found" || (echo -e "nothing\n\nERR: You must run a container to kill it"; exit 1);
@echo -n "Kill container.................";
@docker exec -ti inst1 sh -c 'rm boot.lock' && echo "killed" || echo "error";
2018-02-16 00:49:02 +00:00
boot:
@touch $(LOG);
2018-02-16 00:49:02 +00:00
@while true; do \
echo ">>> pull from source" | tee -a $(LOG); \
git pull origin master >> $(LOG) 2>&1 && echo -e "<<< pulled\n" || echo -e "<<< error\n"; \
echo ">>> make image" | tee -a $(LOG); \
make image; \
echo -e ">>> made\n" | tee -a $(LOG); \
echo ">>> launch container" | tee -a $(LOG); \
touch $(LOCK); \
docker run --name $(CONTAINER_NAME) $(IMAGE_NAME) >> $(LOG) 2>&1; \
echo -e "<<< stopped\n" | tee -a $(LOG); \
echo ">>> clean installation" | tee -a $(LOG); \
make clean; \
echo -e "<<< cleaned\n"; \
2018-02-16 00:49:02 +00:00
sleep 2; \
done;
log:
@echo -n "> Checking log file.......";
@test -f $(LOG) && echo "found" || (echo "missing"; exit 1);
@echo -n "> Checking container......";
@test -f $(LOCK) && echo "running" || echo "not running";
@echo "====== LOG ======";
@tail -f $(LOG);
tty:
@echo -n "> Checking lock...........";
@test -f $(LOCK) && echo "found" || (echo "missing"; exit 1);
@echo "> Connecting tty.............";
@docker exec -ti $(CONTAINER_NAME) sh;