-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
127 lines (109 loc) · 5.2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# *DREDGER - THE OUTER/EDGE DOCKER DEV TOOL*
# To see a list of available commands execute "make help"
SHELL = bash
MOUNT = $${DREDGER_MOUNT:-$(CURDIR)}
NAME = $${DREDGER_NAME:-$(shell basename $(MOUNT))}
HOST = $${DREDGER_HOST:-$(NAME).localhost}
HOST_IP = $${DREDGER_HOST_IP:-172.17.0.1}
VOLUME = $${DREDGER_VOLUME:-/var/www}
PORT = $${DREDGER_PORT:-80}
USER = $${DREDGER_USER:-root}
PWD = $${DREDGER_PWD:-$(CURDIR)}
.PHONY: help build run bash status restart destroy logs clean install update self-update info inspect
help::
echo 'Usage: dredger [command]'
echo ''
echo 'Commands:'
echo ''
echo ' build - Build the image and copy the built files if no local changes'
echo ' run - Run the container and proxy'
echo ' bash - Enter running container with bash'
echo ' status - Show the status of running container'
echo ' logs - Show logs'
echo ' copy - Copy files from the container to the local folder'
echo ' restart - Restarts the running container'
echo ' destroy - Stops the running container and deletes it'
echo ' install - Run app install scripts (defaults to `composer install`)'
echo ' update - Run app update scripts (defaults to `composer update`)'
echo ' info - Show Dredger environment info'
echo ' inspect - Show docker inspect info for the running container'
echo ' self-update - Upgrade Dredger to the latest version'
echo ''
# DEFAULT TARGETS
build::
docker build --pull -t $(NAME) $(PWD);
echo "Copying build files to working directory...";
if [ -d .git ] && [ -z "$$(git -C $(PWD) status --porcelain)" ]; then \
docker run --rm --user=$(USER) --entrypoint="" -v $(MOUNT):/copy $(NAME) bash -c "rm -f .gitignore && cp -rup . /copy"; \
else \
read -p "Git working directory not clean, do you want to override local changes with built files? " -n 1 -r && echo && if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker run --rm --user=$(USER) --entrypoint="" -v $(MOUNT):/copy $(NAME) bash -c "rm -f .gitignore && cp -rup . /copy"; \
fi; \
fi
echo "Removing existing containers...";
-docker rm -f -v $(NAME) 2>/dev/null
run::
if ! nc -z 0.0.0.0 $(PORT) && ! grep -q docker /proc/1/cgroup; then \
docker pull containous/traefik:latest && \
docker run --restart=unless-stopped -d -p $(PORT):80 -v /var/run/docker.sock:/var/run/docker.sock containous/traefik:latest --web --docker --docker.endpoint=unix:///var/run/docker.sock; \
fi
if [ -z "$$(docker images -q $(NAME))" ]; then \
docker build --pull -t $(NAME) $(PWD); \
echo "Copying build files to working directory..."; \
if [ -d .git ] && [ -z "$$(git -C $(PWD) status --porcelain)" ]; then \
docker run --rm --user=$(USER) --entrypoint="" -v $(MOUNT):/copy $(NAME) bash -c "rm -f .gitignore && cp -rup . /copy"; \
else \
read -p "Git working directory not clean, do you want to override local changes with built files? " -n 1 -r && echo && if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker run --rm --user=$(USER) --entrypoint="" -v $(MOUNT):/copy $(NAME) bash -c "rm -f .gitignore && cp -rup . /copy"; \
fi; \
fi \
fi
if [ ! "$$(docker ps -aq --filter name=^/$(NAME)$$)" ]; then \
docker run --rm \
$(shell if [ "$$DREDGER_FOREGROUND" != true ]; then echo '-d'; fi) \
-v $(MOUNT):$(VOLUME) \
-e VIRTUAL_HOST=$(HOST) \
-e XDEBUG_HOST=$(HOST_IP) \
-e DOCKER_HOST_IP=$(HOST_IP) \
-l traefik.frontend.rule=HostRegexp:$(HOST) \
-l traefik.port=80 \
-l traefik.enable=true \
$(ENV) \
$(ARGS) \
--name $(NAME) $(NAME); \
else \
docker restart $(NAME); \
fi
copy::
echo "Copying build files to working directory...";
if [ -d .git ] && [ -z "$$(git -C $(PWD) status --porcelain)" ]; then \
docker run --rm --user=$(USER) --entrypoint="" -v $(MOUNT):/copy $(NAME) bash -c "rm -f .gitignore && cp -rup . /copy"; \
else \
read -p "Git working directory not clean, do you want to override local changes with built files? " -n 1 -r && echo && if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker run --rm --user=$(USER) --entrypoint="" -v $(MOUNT):/copy $(NAME) bash -c "rm -f .gitignore && cp -rup . /copy"; \
fi; \
fi
bash::
-docker exec -it --user=$(USER) $(NAME) bash
status::
-docker exec -it --user=root $(NAME) /usr/bin/supervisorctl status
restart::
-docker restart $(NAME)
destroy::
-docker rm -f -v $(NAME) 2>/dev/null || echo "Container does not exist"
logs::
-docker logs -f $(NAME)
install::
docker exec -it --user=$(USER) $(NAME) composer install --no-interaction --prefer-dist
update::
docker exec -it --user=$(USER) $(NAME) composer update --no-interaction --prefer-dist
self-update::
-wget -qO- https://raw.githubusercontent.com/outeredge/dredger/master/install.sh | bash
info::
echo "Mount: $(MOUNT)"
echo "Name: $(NAME)"
echo "Host: $(HOST)"
echo "Volume: $(VOLUME)"
inspect::
-docker inspect $(NAME)
-include Makefile.local