Makefile 2.87 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
PYVERSIONS=3.5 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
VERSION=$(shell git describe --tags --dirty 2>/dev/null)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
6
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
action="test-${PYMAIN}"
9
10
11

all: build run

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
12
.FORCE:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
13

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
14
version: .FORCE
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
15
	@echo $(VERSION) > $(NAME)/VERSION
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
16
	@echo $(VERSION)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
17

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
22
init:
23
24
25
	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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
37
build-%: version 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
43
dev-%:
	@docker start $(NAME)-dev || (\
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
44
		$(MAKE) build-$*; \
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
45
		docker run -d -w /usr/src/app/ -v $$PWD:/usr/src/app --entrypoint=/bin/bash -p 5000:5000 -ti --name $(NAME)-dev '$(IMAGENAME)-python$*'; \
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
46
47
	)\

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
48
49
50
51
52
	docker exec -ti $(NAME)-dev bash

dev: dev-$(PYMAIN)

test-all: $(addprefix test-,$(PYVERSIONS))
53

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
54
55
test-%: build-%
	docker run --rm --entrypoint /usr/local/bin/python -w /usr/src/app $(IMAGENAME)-python$*  setup.py test
56

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
57
test: test-$(PYMAIN)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
58

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

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

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

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

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

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

clean:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
79
80
	@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
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
81
	@docker rmi $(NAME)-dev 2>/dev/null || true
82

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
83
84

git_commit:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
85
	git commit -a
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
86
87

git_tag:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
88
	git tag ${VERSION}
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
89

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
90
git_push:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
91
	git push --tags origin master
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
92

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
93
94
pip_upload:
	python setup.py sdist upload ;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
95

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
98
99
100
101
run-%: build-%
	docker run --rm -p 5000:5000 -ti '$(IMAGENAME)-python$(PYMAIN)' --default-plugins

run: run-$(PYMAIN)
102

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
103
104
105
106
107
108
109
110
111
112
113
push-latest: build-$(PYMAIN)
	docker tag $(IMAGENAME)-python$(PYMAIN) $(IMAGENAME)
	docker push $(IMAGENAME)

push-%: build-%
	docker push $(IMAGENAME)-python$*

ci:
	gitlab-runner exec docker --docker-volumes /var/run/docker.sock:/var/run/docker.sock --env CI_PROJECT_NAME=$(NAME) ${action}

.PHONY: test test-% test-all build-% build test pip_test run yapf dev ci version .FORCE