Makefile 3.07 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
DEVPORT=5000
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
10
action="test-${PYMAIN}"
11
12
13

all: build run

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

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

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

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

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

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

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

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

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

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
44
dev-%:
45
	@docker start $(NAME)-dev$* || (\
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
46
		$(MAKE) build-$*; \
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
47
		docker run -d -w /usr/src/app/ -p $(DEVPORT):5000 -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
48
49
	)\

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

dev: dev-$(PYMAIN)

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

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

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

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
65

66
sdist: dist/$(TARNAME)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
67
68

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

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

73
clean:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
74
75
	@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
76
77
	@docker stop $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
	@docker rm $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
78
79

git_commit:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
80
	git commit -a
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
81
82

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

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
85
git_push:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
86
	git push --tags origin master
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
87

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

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

run: run-$(PYMAIN)
95

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

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

105
106
107
108
push: $(addprefix push-,$(PYVERSIONS))
	docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGEWTAG)'
	docker push  $(IMAGENAME):$(VERSION)

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
109
110
111
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
112
.PHONY: test test-% test-all build-% build test pip_test run yapf push-main push-% dev ci version .FORCE