Makefile 2.61 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
NAME=senpy
REPO=gsiupm
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
5
6
VERSION=$(shell ./version.sh)
TARNAME=$(NAME)-$(VERSION).tar.gz 
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
7
IMAGENAME=$(REPO)/$(NAME):$(VERSION)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
8
TEST_COMMAND=gitlab-runner exec docker --cache-dir=/tmp/gitlabrunner --docker-volumes /tmp/gitlabrunner:/tmp/gitlabrunner --env CI_PROJECT_NAME=$(NAME)
9
10
11

all: build run

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
12
13
14
15
16
17
FORCE:

version: FORCE
	@echo $(VERSION) > $(NAME)/VERSION
	@echo $(NAME) $(VERSION)

J. Fernando Sánchez's avatar
YAPFed    
J. Fernando Sánchez committed
18
19
20
21
yapf:
	yapf -i -r senpy
	yapf -i -r tests

22
23
24
25
dev:
	pip install --user pre-commit
	pre-commit install

26
dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS))
27
	@unlink Dockerfile >/dev/null
28
	ln -s Dockerfile-$(PYMAIN) Dockerfile
29
30
31
32

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

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

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

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

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

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

44
debug-%:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
45
46
47
48
49
50
51
	@docker start $(NAME)-debug || (\
		$(MAKE) build-$*; \
		docker run -d -w /usr/src/app/ -v $$PWD:/usr/src/app --entrypoint=/bin/bash -p 5000:5000 -ti --name $(NAME)-debug '$(IMAGENAME)-python$*'; \
		docker exec -ti $(NAME)-debug pip install -r test-requirements.txt; \
	)\

	docker attach $(NAME)-debug
52
53

debug: debug-$(PYMAIN)
54

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
55
56
test-%:
	$(TEST_COMMAND) test-$*
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
57

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

61
sdist: dist/$(TARNAME)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
62
63

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

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

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
71
72
73
74
75
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)'
76
77

clean:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
78
79
	@docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1;}}' | xargs docker rm -v 2>/dev/null|| true
	@docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
80
	@docker rmi $(NAME)-debug 2>/dev/null || true
81

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
82
83
84
85
upload_git:
	git commit -a
	git tag ${VERSION}
	git push --tags origin master
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
86

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
87
88
pip_upload:
	python setup.py sdist upload ;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
89

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
92
93
94
95
run-%: build-%
	docker run --rm -p 5000:5000 -ti '$(IMAGENAME)-python$(PYMAIN)' --default-plugins

run: run-$(PYMAIN)
96

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