-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile
146 lines (129 loc) · 3.79 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
.PHONY: deps start open stop kill logs restart shell test
UNAME_S := $(shell uname -s)
USERNAME := $(shell whoami)
IS_DOCKER_MEMBER := $(shell groups|grep docker)
ROOT_NAME := $(shell basename $(shell pwd))
BOOT2DOCKER_IP := $(shell boot2docker ip 2> /dev/null)
DOCKER_VERSION := $(shell docker version 2> /dev/null)
DOCKER_COMPOSE_VERSION := $(shell docker-compose version 2> /dev/null)
DOCKER_DOES_NOT_WORK := $(shell (docker info 1> /dev/null) 2>&1|grep -v WARNING)
DOCKER_COMPOSE_DOES_NOT_WORK := $(shell docker-compose ps 2>&1|grep "client and server don't have same version")
PORT_80_USED := $(shell netstat -lnt|awk '$$4 ~ ".80"')
PORT_8080_USED := $(shell netstat -lnt|awk '$$4 ~ ".8080"')
ifndef BOOT2DOCKER_IP
DOCKER_IP := 127.0.0.1
else
DOCKER_IP := $(BOOT2DOCKER_IP)
endif
ifeq ($(UNAME_S),Darwin)
OPEN := open
else
ifeq ($(UNAME_S),Linux)
OPEN := xdg-open
endif
endif
ifndef COMPOSE_FILE
COMPOSE_FILE := development.yml
export COMPOSE_FILE
endif
IS_FRONT_UP := $(shell docker-compose -f $(COMPOSE_FILE) ps front|grep Up)
IS_REALTIME_UP := $(shell docker-compose -f $(COMPOSE_FILE) ps realtime|grep Up)
deps:
ifeq ($(UNAME_S),Linux)
ifneq ($(USERNAME),root)
ifndef IS_DOCKER_MEMBER
@echo "ERROR: Are you in the docker group?"
@echo "You can try:"
@echo " sudo usermod -aG docker $(USERNAME)"
exit 1
endif
endif
ifndef IS_FRONT_UP
ifdef PORT_80_USED
@echo "ERROR: We need to bind to port 80, but something is using it. Please free it up and rerun this."
exit 1
endif
endif
ifndef IS_REALTIME_UP
ifdef PORT_8080_USED
@echo "ERROR: We need to bind to port 8080, but something is using it. Please free it up and rerun this."
exit 1
endif
endif
endif
ifndef DOCKER_VERSION
@echo "ERROR: You need to install Docker first. Exiting."
exit 1
endif
ifndef DOCKER_COMPOSE_VERSION
@echo "ERROR: You need to install docker-compose first. Exiting."
exit 1
endif
ifdef DOCKER_DOES_NOT_WORK
@echo "ERROR: Docker is not installed correctly."
@echo "You may need boot2docker on OSX, or to start the docker service on Linux."
exit 1
endif
ifdef DOCKER_COMPOSE_DOES_NOT_WORK
@echo "ERROR: Your docker version is incompatible with your docker-compose version."
ifdef BOOT2DOCKER_IP
@echo "You can try:"
@echo " brew update && brew upgrade docker docker-compose boot2docker"
@echo " boot2docker upgrade && boot2docker up"
else
@echo "It's recommended that you install both on the latest version."
@echo "Remove all docker packages and docker-compose executables and consult these links:"
@echo " https://docs.docker.com/installation/ubuntulinux/#installation"
@echo " https://docs.docker.com/compose/install/"
endif
exit 1
endif
build: deps $(COMPOSE_FILE)
docker-compose build
start: deps $(COMPOSE_FILE)
docker-compose up -d
open: deps start
$(OPEN) "http://$(DOCKER_IP):80"
stop: deps
docker-compose stop
kill: deps
docker-compose kill
logs: deps
ifdef TARGET
docker-compose logs $(TARGET)
else
docker-compose logs
endif
restart: deps
ifdef TARGET
docker-compose restart -t 0 $(TARGET)
else
docker-compose restart -t 0
endif
shell: deps start
ifndef TARGET
@echo "ERROR: 'make shell' should be used with a target."
@echo "Example: make shell TARGET=api"
exit 1
endif
docker exec -it $(shell docker-compose -f $(COMPOSE_FILE) ps -q $(TARGET)) /bin/bash
test: deps start
ifndef TARGET
@echo "ERROR: 'make test' should be used with a target."
@echo "Example: make test TARGET=api"
exit 1
endif
ifeq ($(TARGET),api)
docker exec -it $(shell docker-compose -f $(COMPOSE_FILE) ps -q $(TARGET)) python manage.py test chat
else
ifeq ($(TARGET),front)
docker exec -it $(shell docker-compose -f $(COMPOSE_FILE) ps -q $(TARGET)) npm test
else
ifeq ($(TARGET),realtime)
docker exec -it $(shell docker-compose -f $(COMPOSE_FILE) ps -q $(TARGET)) npm test
else
@echo "ERROR: Don't know how to test $(TARGET)."
exit 1
endif
endif
endif