Makefile 2.73 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 
7
8
IMAGENAME=$(REPO)/$(NAME)
IMAGEWTAG=$(IMAGENAME):$(VERSION)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
9
action="test-${PYMAIN}"
10
11
12

all: build run

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

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

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
23
init:
24
25
26
	pip install --user pre-commit
	pre-commit install

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

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

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

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

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

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
43
dev-%:
44
	@docker start $(NAME)-dev$* || (\
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
45
		$(MAKE) build-$*; \
46
		docker run -d -w /usr/src/app/ -v $$PWD:/usr/src/app --entrypoint=/bin/bash -ti --name $(NAME)-dev$* '$(IMAGEWTAG)-python$*'; \
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
47
48
	)\

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

dev: dev-$(PYMAIN)

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

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

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

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

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

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

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

70
clean:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
71
72
	@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
73
	@docker rmi $(NAME)-dev 2>/dev/null || true
74

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
75
76

git_commit:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
77
	git commit -a
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
78
79

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
82
git_push:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
83
	git push --tags origin master
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
84

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

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

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

run: run-$(PYMAIN)
94

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
95
push-latest: build-$(PYMAIN)
96
97
98
99
	docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGEWTAG)'
	docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGENAME)'
	docker push '$(IMAGENAME)'
	docker push '$(IMAGEWTAG)'
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
100

101
102
103
push-%: build-%
	docker push $(IMAGENAME):$(VERSION)-python$*

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
104
105
106
ci:
	gitlab-runner exec docker --docker-volumes /var/run/docker.sock:/var/run/docker.sock --env CI_PROJECT_NAME=$(NAME) ${action}

J. Fernando Sánchez's avatar
Fix 5    
J. Fernando Sánchez committed
107
.PHONY: test test-% test-all build-% build test pip_test run yapf push-main push-% dev ci version .FORCE