Makefile 2.34 KB
Newer Older
1
PYVERSIONS=3.5 3.4 2.7
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
2
PYMAIN=$(firstword $(PYVERSIONS))
3
4
5
NAME=senpy
REPO=gsiupm
VERSION=$(shell cat $(NAME)/VERSION)
6
TARNAME=$(NAME)-$(subst -,.,$(VERSION)).tar.gz 
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
7
IMAGENAME=$(REPO)/$(NAME):$(VERSION)
8
9
10

all: build run

J. Fernando Sánchez's avatar
YAPFed    
J. Fernando Sánchez committed
11
12
13
14
yapf:
	yapf -i -r senpy
	yapf -i -r tests

15
16
17
18
dev:
	pip install --user pre-commit
	pre-commit install

19
dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS))
20
	@unlink Dockerfile >/dev/null
21
	ln -s Dockerfile-$(PYMAIN) Dockerfile
22
23
24
25

Dockerfile-%: Dockerfile.template
	sed "s/{{PYVERSION}}/$*/" Dockerfile.template > Dockerfile-$*

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
26
quick_build: $(addprefix build-, $(PYMAIN))
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
27

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
28
build: $(addprefix build-, $(PYVERSIONS))
29
30

build-%: Dockerfile-%
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
31
	docker build -t '$(IMAGENAME)-python$*' -f Dockerfile-$* .;
32

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
33
quick_test: $(addprefix test-,$(PYMAIN))
34

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
35
test: $(addprefix test-,$(PYVERSIONS))
36

37
debug-%:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
38
	(docker start $(NAME)-debug && docker attach $(NAME)-debug) || docker run -w /usr/src/app/ -v $$PWD:/usr/src/app --entrypoint=/bin/bash -ti --name $(NAME)-debug '$(IMAGENAME)-python$*'
39
40

debug: debug-$(PYMAIN)
41

42
test-%: build-%
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
43
	docker run --rm -w /usr/src/app/ --entrypoint=/usr/local/bin/python -ti '$(IMAGENAME)-python$*' setup.py test --addopts "-vvv -s" ;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
44

45
dist/$(TARNAME):
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
46
47
	docker run --rm -ti -v $$PWD:/usr/src/app/ -w /usr/src/app/ python:$(PYMAIN) python setup.py sdist;

48
sdist: dist/$(TARNAME)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
49
50

pip_test-%: sdist
51
	docker run --rm -v $$PWD/dist:/dist/ -ti python:$* pip install /dist/$(TARNAME);
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
52
53

pip_test: $(addprefix pip_test-,$(PYVERSIONS))
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
54
55

upload-%: test-%
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
56
	docker push '$(IMAGENAME)-python$*'
57

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
58
59
60
61
62
upload: test $(addprefix upload-,$(PYVERSIONS))
	docker tag '$(IMAGENAME)-python$(PYMAIN)' '$(IMAGENAME)'
	docker tag '$(IMAGENAME)-python$(PYMAIN)' '$(REPO)/$(NAME)'
	docker push '$(IMAGENAME)'
	docker push '$(REPO)/$(NAME)'
63
64
65
66

clean:
	@docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1;}}' | xargs docker rm 2>/dev/null|| true
	@docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
67
	@docker rmi $(NAME)-debug 2>/dev/null || true
68

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
69
70
71
72
upload_git:
	git commit -a
	git tag ${VERSION}
	git push --tags origin master
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
73

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
74
75
pip_upload:
	python setup.py sdist upload ;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
76

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
77
pip_test: $(addprefix pip_test-,$(PYVERSIONS))
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
78

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
79
run: build
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
80
	docker run --rm -p 5000:5000 -ti '$(IMAGENAME)-python$(PYMAIN)'
81

82
.PHONY: test test-% build-% build test pip_test run yapf dev