-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·63 lines (45 loc) · 1.67 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
IMAGE_NAME := prowl/django
IMAGE_TAG := 1.10.4
CONTAINER_NAME := django_app
ENV_FILE_NAME := django_app_env
HOST_PORT := 8000
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
MAKE_DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
ifndef ${ENV_FILE_NAME}
ifeq ($(shell test -s ./env && echo -n yes),yes)
ENV_FILE := $(abspath ./env)
else
ENV_FILE := /dev/null
endif
else
ENV_FILE := ${${ENV_FILE_NAME}}
endif
.PHONY: all depend build clean create kill start stop restart shell migrate static docker_ip gen_secret
all: create depend migrate static restart
depend:
docker exec -it $(CONTAINER_NAME) pip install -r requirements.txt
build:
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
clean:
docker images $(IMAGE_NAME) | grep -q $(IMAGE_TAG) && docker rmi $(IMAGE_NAME):$(IMAGE_TAG) || true
create:
docker run --name $(CONTAINER_NAME) --restart=always --env-file $(ENV_FILE) -d -p $(HOST_PORT):80 -v $(MAKE_DIR):/opt/app $(IMAGE_NAME):$(IMAGE_TAG)
kill:
docker stop $(CONTAINER_NAME) && docker rm $(CONTAINER_NAME)
start:
docker start $(CONTAINER_NAME)
stop:
docker stop $(CONTAINER_NAME)
restart:
docker restart $(CONTAINER_NAME)
shell:
docker exec -it $(CONTAINER_NAME) bash
migrate:
docker exec -it $(CONTAINER_NAME) python ./src/manage.py migrate
static:
docker exec -it $(CONTAINER_NAME) python ./src/manage.py collectstatic --noinput
docker_ip:
@ip addr show docker0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
gen_secret:
@python -c 'import random; print "".join([random.SystemRandom().choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'