-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
111 lines (90 loc) · 2.73 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
NAMESPACE = moroshka
PACKAGE = site
SOURCE_VERSION ?= $(shell cat VERSION)
SOURCE_COMMIT ?= $(shell git rev-parse --short=8 HEAD)
TAG = $(shell cat VERSION)
IMAGE_REGISTRY = registry.halfakop.ru:5000
IMAGE_PREFIX = $(NAMESPACE)/$(PACKAGE)
IMAGE_NAME_TAGGED = $(IMAGE_PREFIX):$(TAG)
IMAGE_NAME_LATEST = $(IMAGE_PREFIX):latest
CURDIR = $(shell pwd)
CACHEDIR ?= /tmp/$(PACKAGE)-cache
PORT ?= 8000
.EXPORT_ALL_VARIABLES:
# this exports the following variables
# see https://www.gnu.org/software/make/manual/make.html#index-_002eEXPORT_005fALL_005fVARIABLES
default: help
title:
@echo "\Moroshka - The Company's Site\n"
help: title
@echo "Usage: make {command}"
@echo " clean clean the source code;"
@echo " run run the application locally;"
@echo " rung run the application as in production;"
@echo " bump bump the version;"
@echo
@echo " release make the release;"
@echo " build build the image;"
@echo " tags tag the image;"
@echo " publish publish the image;"
@echo
@echo " test run tests;"
@echo
@echo "Environment variables:"
@echo " SECRET_KEY if undefined then restart of app drops session"
@echo
clean:
@find . -type d -name '__pycache__' -delete
bump:
bumpversion --commit --tag patch
postgres_start:
docker run --rm -d \
-l database \
--name postgres \
-p 5432:5432 \
postgres
# -v postgres_data:/var/lib/postgresql/data/ \
postgres_stop:
docker kill postgres
postgres_shell:
psql -h $(DB_HOST) -p $(DB_PORT) -d $(DB_NAME) -U $(DB_USER)
postgres_dump:
pg_dump -h $(DB_HOST) -p $(DB_PORT) \
-U $(DB_USER) -C -Fc $(DB_NAME) -f backup_pgsql.gz
define run_variables
SECRET_KEY=top_secret \
PYTHONPATH=$(CURDIR)
endef
run:
$(call run_variables) \
python3 manage.py runserver
rung:
$(call run_variables) \
gunicorn -c gunicorn.py src.wsgi
shell:
$(call run_variables) \
python3 manage.py shell
dbshell:
$(call run_variables) \
python3 manage.py dbshell
release: clean build tags registry publish
build:
$(eval SOURCE_VERSION := $(shell cat VERSION))
$(eval SOURCE_COMMIT := $(shell git rev-parse HEAD))
docker build \
-t $(IMAGE_NAME_TAGGED) \
-t $(IMAGE_NAME_LATEST) \
--build-arg SOURCE_VERSION=$(SOURCE_VERSION) \
--build-arg SOURCE_COMMIT=$(SOURCE_COMMIT) \
-f Dockerfile .
tags:
docker tag $(IMAGE_NAME_LATEST) $(IMAGE_REGISTRY)/$(IMAGE_NAME_LATEST)
docker tag $(IMAGE_NAME_TAGGED) $(IMAGE_REGISTRY)/$(IMAGE_NAME_TAGGED)
registry:
@echo ${DOCKER_PASSWORD} | \
docker login -u ${DOCKER_USERNAME} --password-stdin $(IMAGE_REGISTRY)
publish:
docker push $(IMAGE_REGISTRY)/$(IMAGE_NAME_LATEST)
docker push $(IMAGE_REGISTRY)/$(IMAGE_NAME_TAGGED)
test:
PYTHONPATH=. pytest