forked from globocom/GloboNetworkAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
180 lines (125 loc) · 4.71 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#
# Makefile for Network API project
#
# Docker image version
NETAPI_IMAGE_VERSION := 2.1.0
# Gets git current branch
curr_branch := $(shell git symbolic-ref --short -q HEAD)
# Gets git current branch
curr_version := $(shell cat version.txt);
# Sed binary depends on Operating system
ifeq ($(shell uname -s),Darwin)
SED_TYPE := gsed
else
SED_TYPE := sed
endif
help:
@echo
@echo "Network API"
@echo
@echo "Available target rules"
@echo
@echo "Local:"
@echo " api To get a shell of network_app container"
@echo " db To get a shell of network_db container"
@echo " start to run project through docker compose"
@echo " stop to stop all containers from docker composition"
@echo " logs to follow logs on application container"
@echo " test to execute tests using containers. Use app variable"
@echo " status to show containers status"
@echo " clean to clean garbage left by builds and installation"
@echo " fixture to generate fixtures from a given model"
@echo " tag to create a new tag based on the current versioni"
@echo
@echo "Build:"
@echo " build_img to build docker images"
@echo " docs to create documentation files"
@echo " compile to compile .py files (just to check for syntax errors)"
@echo " build to build without installing"
@echo " install to install"
@echo " dist to create egg for distribution"
@echo
@echo "Remote:"
@echo " publish to publish the package to PyPI"
@echo " push_img to push image to docker hub"
@echo " test_ci Used by Travis CI to run tests on django applications"
@echo
pip: # install pip libraries
@pip install -r requirements.txt
@pip install -r requirements_test.txt
db_reset: # drop and create database
@[ -z $NETWORKAPI_DATABASE_PASSWORD ] && [ -z $NETWORKAPI_DATABASE_USER ] && [ -z $NETWORKAPI_DATABASE_HOST ] && mysqladmin -hlocalhost -uroot -f drop networkapi; true
@[ -z $NETWORKAPI_DATABASE_PASSWORD ] && [ -z $NETWORKAPI_DATABASE_USER ] && [ -z $NETWORKAPI_DATABASE_HOST ] && mysqladmin -hlocalhost -uroot -f create networkapi; true
@[ -n $NETWORKAPI_DATABASE_PASSWORD ] && [ -n $NETWORKAPI_DATABASE_USER ] && [ -n $NETWORKAPI_DATABASE_HOST ] && mysqladmin -hNETWORKAPI_DATABASE_HOST -uNETWORKAPI_DATABASE_USER -pNETWORKAPI_DATABASE_PASSWORD -f drop networkapi; true
@[ -n $NETWORKAPI_DATABASE_PASSWORD ] && [ -n $NETWORKAPI_DATABASE_USER ] && [ -n $NETWORKAPI_DATABASE_HOST ] && mysqladmin -hNETWORKAPI_DATABASE_HOST -uNETWORKAPI_DATABASE_USER -pNETWORKAPI_DATABASE_PASSWORD -f create networkapi; true
run: # run local server
@python manage.py runserver 0.0.0.0:8000 $(filter-out $@,$(MAKECMDGOALS))
shell: # run django shell
@python manage.py shell_plus
clean:
@echo "Cleaning..."
@rm -rf build dist *.egg-info
@rm -rf docs/_build
@find . \( -name '*.pyc' -o -name '**/*.pyc' -o -name '*~' \) -delete
docs: clean
@(cd docs && make html)
compile: clean
@echo "Compiling source code..."
@python -tt -m compileall .
#@pep8 --format=pylint --statistics networkapiclient setup.py
install:
@python setup.py install
api:
@docker exec -it netapi_app sh
db:
@docker exec -it netapi_db bash
build:
@docker-compose up --build -d
dist: clean
@python setup.py sdist
publish: clean
@python setup.py sdist upload
#
# Containers based target rules
#
start: docker-compose.yml
@docker-compose up -d
stop: docker-compose.yml
@docker-compose down --remove-orphans
logs:
@docker logs --tail 100 --follow netapi_app
status:
docker ps --all --format "{{.ID}}\t{{.Names}}\t{{.Status}}"
test:
@clear
@echo "Running NetAPI tests for app '${app}'"
time docker exec -it netapi_app ./fast_start_test_reusedb.sh ${app}
test_ci:
@echo "Running NetAPI tests for app '${app}'"
time docker exec -it netapi_app ./fast_start_test.sh ${app}
fixture:
ifeq (${model},)
$(error Missing model. Usage: make fixture model=interface.PortChannel)
endif
docker exec -it netapi_app django-admin.py dumpdata ${model}
build_img: scripts/docker/Dockerfile
docker build -t networkapi:latest --file scripts/docker/Dockerfile .
docker build -t networkapi:$(NETAPI_IMAGE_VERSION) --file scripts/docker/Dockerfile .
push_img: scripts/docker/push_image.sh
./$^
tag:
ifneq ($(curr_branch),master)
$(error Branch must be master to generate a new tag)
endif
ifeq ($(shell which $(SED_TYPE)),)
$(error Missing GNU sed. Install it with 'brew install gnu-sed')
endif
@echo "Current version is: $(curr_version)"
@read -p "Enter new tag/version: " tag; \
echo "Bumping to tag: $$tag"; \
echo $$tag > version.txt; \
git diff; \
git add version.txt ; \
git commit --message "Update version to $$tag"; \
git tag --annotate $$tag --message "Bump version to $$tag"; \
git push origin master --tags;