2016-09-20 18:55:59 +00:00
|
|
|
NAME=senpy
|
2017-02-27 11:14:39 +00:00
|
|
|
VERSION=$(shell git describe --tags --dirty 2>/dev/null)
|
2017-06-02 17:21:12 +00:00
|
|
|
GITHUB_REPO=git@github.com:gsi-upm/senpy.git
|
|
|
|
|
|
|
|
IMAGENAME=gsiupm/senpy
|
2017-02-27 19:00:09 +00:00
|
|
|
IMAGEWTAG=$(IMAGENAME):$(VERSION)
|
2017-06-02 17:21:12 +00:00
|
|
|
|
|
|
|
PYVERSIONS=3.5 2.7
|
|
|
|
PYMAIN=$(firstword $(PYVERSIONS))
|
|
|
|
|
2017-03-14 18:54:33 +00:00
|
|
|
DEVPORT=5000
|
2017-06-02 17:21:12 +00:00
|
|
|
|
|
|
|
TARNAME=$(NAME)-$(VERSION).tar.gz
|
2017-02-27 11:14:39 +00:00
|
|
|
action="test-${PYMAIN}"
|
2017-05-19 15:55:52 +00:00
|
|
|
GITHUB_REPO=git@github.com:gsi-upm/senpy.git
|
2016-09-20 18:55:59 +00:00
|
|
|
|
2017-05-19 12:38:29 +00:00
|
|
|
KUBE_CA_PEM_FILE=""
|
|
|
|
KUBE_URL=""
|
|
|
|
KUBE_TOKEN=""
|
2017-05-19 17:59:45 +00:00
|
|
|
KUBE_NAMESPACE=$(NAME)
|
2017-05-19 12:38:29 +00:00
|
|
|
KUBECTL=docker run --rm -v $(KUBE_CA_PEM_FILE):/tmp/ca.pem -v $$PWD:/tmp/cwd/ -i lachlanevenson/k8s-kubectl --server="$(KUBE_URL)" --token="$(KUBE_TOKEN)" --certificate-authority="/tmp/ca.pem" -n $(KUBE_NAMESPACE)
|
2017-05-19 15:55:52 +00:00
|
|
|
CI_COMMIT_REF_NAME=master
|
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
help: ## Show this help.
|
|
|
|
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/\(.*:\)[^#]*##\s*\(.*\)/\1\t\2/' | column -t -s " "
|
2017-05-19 12:38:29 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
config: ## Load config from the environment. You should run it once in every session before other tasks. Run: eval $(make config)
|
|
|
|
@echo ". ../.env || true;"
|
|
|
|
@awk '{ print "export " $$0}' .env
|
|
|
|
@echo "# Please, run: "
|
|
|
|
@echo "# eval \$$(make config)"
|
|
|
|
# If you need to run a command on the key/value pairs, use this:
|
|
|
|
# @awk '{ split($$0, a, "="); "echo " a[2] " | base64 -w 0" |& getline b64; print "export " a[1] "=" a[2]; print "export " a[1] "_BASE64=" b64}' .env
|
2016-09-20 18:55:59 +00:00
|
|
|
|
2017-02-08 20:55:17 +00:00
|
|
|
quick_build: $(addprefix build-, $(PYMAIN))
|
2016-09-21 16:59:28 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
build: $(addprefix build-, $(PYVERSIONS)) ## Build all images / python versions
|
2016-09-20 18:55:59 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
build-%: version Dockerfile-% ## Build a specific version (e.g. build-2.7)
|
2017-05-19 12:38:29 +00:00
|
|
|
docker build -t '$(IMAGEWTAG)-python$*' --cache-from $(IMAGENAME):python$* -f Dockerfile-$* .;
|
2016-09-20 18:55:59 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
quick_test: test-$(PYMAIN)
|
2017-01-10 09:02:14 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
dev-%: ## Launch a specific development environment using docker (e.g. dev-2.7)
|
2017-02-28 03:28:54 +00:00
|
|
|
@docker start $(NAME)-dev$* || (\
|
2017-02-27 10:37:43 +00:00
|
|
|
$(MAKE) build-$*; \
|
2017-03-14 18:54:33 +00:00
|
|
|
docker run -d -w /usr/src/app/ -p $(DEVPORT):5000 -v $$PWD:/usr/src/app --entrypoint=/bin/bash -ti --name $(NAME)-dev$* '$(IMAGEWTAG)-python$*'; \
|
2017-02-27 10:37:43 +00:00
|
|
|
)\
|
|
|
|
|
2017-02-28 03:28:54 +00:00
|
|
|
docker exec -ti $(NAME)-dev$* bash
|
2017-02-27 11:14:39 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
dev: dev-$(PYMAIN) ## Launch a development environment using docker, using the default python version
|
2017-02-27 11:14:39 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
test-%: ## Run setup.py from in an isolated container, built from the base image. (e.g. test-2.7)
|
2017-07-12 15:50:09 +00:00
|
|
|
# This speeds tests up because the image has most (if not all) of the dependencies already.
|
|
|
|
docker rm $(NAME)-test-$* || true
|
|
|
|
docker create -ti --name $(NAME)-test-$* --entrypoint="" -w /usr/src/app/ $(IMAGENAME):python$* python setup.py test
|
|
|
|
docker cp . $(NAME)-test-$*:/usr/src/app
|
|
|
|
docker start -a $(NAME)-test-$*
|
2016-12-19 17:18:47 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
test: $(addprefix test-,$(PYVERSIONS)) ## Run the tests with the main python version
|
|
|
|
|
|
|
|
run-%: build-%
|
|
|
|
docker run --rm -p $(DEVPORT):5000 -ti '$(IMAGEWTAG)-python$(PYMAIN)' --default-plugins
|
|
|
|
|
|
|
|
run: run-$(PYMAIN)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Deployment and advanced features
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
deploy: ## Deploy to kubernetes using the credentials in KUBE_CA_PEM_FILE (or KUBE_CA_BUNDLE ) and TOKEN
|
|
|
|
@cat k8s/* | envsubst | $(KUBECTL) apply -f -
|
|
|
|
|
|
|
|
deploy-check: ## Get the deployed configuration.
|
|
|
|
@$(KUBECTL) get deploy,pods,svc,ingress
|
|
|
|
|
|
|
|
login: ## Log in to the registry. It will only be used in the server, or when running a CI task locally (if CI_BUILD_TOKEN is set).
|
|
|
|
ifeq ($(CI_BUILD_TOKEN),)
|
|
|
|
@echo "Not logging in to the docker registry" "$(CI_REGISTRY)"
|
|
|
|
else
|
|
|
|
docker login -u gitlab-ci-token -p $(CI_BUILD_TOKEN) $(CI_REGISTRY)
|
|
|
|
endif
|
|
|
|
ifeq ($(HUB_USER),)
|
|
|
|
@echo "Not logging in to global the docker registry"
|
|
|
|
else
|
2017-09-27 14:31:47 +00:00
|
|
|
docker login -u $(HUB_USER) -p $(HUB_PASSWORD)
|
2017-08-27 16:43:40 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
.FORCE:
|
|
|
|
|
|
|
|
version: .FORCE
|
|
|
|
@echo $(VERSION) > $(NAME)/VERSION
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
yapf: ## Format python code
|
|
|
|
yapf -i -r $(NAME)
|
|
|
|
yapf -i -r tests
|
|
|
|
|
|
|
|
init: ## Init pre-commit hooks (i.e. enforcing format checking before allowing a commit)
|
|
|
|
pip install --user pre-commit
|
|
|
|
pre-commit install
|
|
|
|
|
|
|
|
dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS)) ## Generate dockerfiles for each python version
|
|
|
|
@unlink Dockerfile >/dev/null
|
|
|
|
ln -s Dockerfile-$(PYMAIN) Dockerfile
|
|
|
|
|
|
|
|
Dockerfile-%: Dockerfile.template ## Generate a specific dockerfile (e.g. Dockerfile-2.7)
|
|
|
|
sed "s/{{PYVERSION}}/$*/" Dockerfile.template > Dockerfile-$*
|
2016-09-21 16:59:28 +00:00
|
|
|
|
2017-04-04 09:30:56 +00:00
|
|
|
dist/$(TARNAME): version
|
2017-06-12 19:50:51 +00:00
|
|
|
python setup.py sdist;
|
2016-12-14 13:38:58 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
sdist: dist/$(TARNAME) ## Generate the distribution file (wheel)
|
2016-12-14 13:38:58 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
pip_test-%: sdist ## Test the distribution file using pip install and a specific python version (e.g. pip_test-2.7)
|
2017-06-12 19:27:02 +00:00
|
|
|
docker run --rm -v $$PWD/dist:/dist/ python:$* pip install /dist/$(TARNAME);
|
2016-12-14 13:38:58 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
pip_test: $(addprefix pip_test-,$(PYVERSIONS)) ## Test pip installation with the main python version
|
2016-09-21 16:59:28 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
pip_upload: pip_test ## Upload package to pip
|
2017-06-02 17:21:12 +00:00
|
|
|
python setup.py sdist upload ;
|
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
clean: ## Clean older docker images and containers related to this project and dev environments
|
2017-05-19 12:38:29 +00:00
|
|
|
@docker ps -a | grep $(IMAGENAME) | awk '{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1;}}' | xargs docker rm -v 2>/dev/null|| true
|
|
|
|
@docker images | grep $(IMAGENAME) | awk '{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
|
2017-04-10 18:38:12 +00:00
|
|
|
@docker stop $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
|
|
|
|
@docker rm $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
|
2017-02-27 11:14:39 +00:00
|
|
|
|
|
|
|
git_commit:
|
2016-09-21 18:29:16 +00:00
|
|
|
git commit -a
|
2017-02-27 11:14:39 +00:00
|
|
|
|
|
|
|
git_tag:
|
2016-09-21 18:29:16 +00:00
|
|
|
git tag ${VERSION}
|
2017-02-27 11:14:39 +00:00
|
|
|
|
2017-02-27 18:30:02 +00:00
|
|
|
git_push:
|
2016-09-21 18:29:16 +00:00
|
|
|
git push --tags origin master
|
2016-09-21 08:10:49 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
quick_build: $(addprefix build-, $(PYMAIN))
|
|
|
|
|
|
|
|
build: $(addprefix build-, $(PYVERSIONS)) ## Build all images / python versions
|
|
|
|
|
|
|
|
build-%: version Dockerfile-% ## Build a specific version (e.g. build-2.7)
|
|
|
|
docker build -t '$(IMAGEWTAG)-python$*' --cache-from $(IMAGENAME):python$* -f Dockerfile-$* .;
|
|
|
|
|
|
|
|
quick_test: test-$(PYMAIN)
|
|
|
|
|
|
|
|
dev-%: ## Launch a specific development environment using docker (e.g. dev-2.7)
|
|
|
|
@docker start $(NAME)-dev$* || (\
|
|
|
|
$(MAKE) build-$*; \
|
|
|
|
docker run -d -w /usr/src/app/ -p $(DEVPORT):5000 -v $$PWD:/usr/src/app --entrypoint=/bin/bash -ti --name $(NAME)-dev$* '$(IMAGEWTAG)-python$*'; \
|
|
|
|
)\
|
|
|
|
|
|
|
|
docker exec -ti $(NAME)-dev$* bash
|
|
|
|
|
|
|
|
dev: dev-$(PYMAIN) ## Launch a development environment using docker, using the default python version
|
|
|
|
|
|
|
|
test-%: ## Run setup.py from in an isolated container, built from the base image. (e.g. test-2.7)
|
|
|
|
# This speeds tests up because the image has most (if not all) of the dependencies already.
|
|
|
|
docker rm $(NAME)-test-$* || true
|
|
|
|
docker create -ti --name $(NAME)-test-$* --entrypoint="" -w /usr/src/app/ $(IMAGENAME):python$* python setup.py test
|
|
|
|
docker cp . $(NAME)-test-$*:/usr/src/app
|
|
|
|
docker start -a $(NAME)-test-$*
|
|
|
|
|
|
|
|
test: $(addprefix test-,$(PYVERSIONS)) ## Run the tests with the main python version
|
|
|
|
|
2017-02-27 10:37:43 +00:00
|
|
|
run-%: build-%
|
2017-03-14 18:54:33 +00:00
|
|
|
docker run --rm -p $(DEVPORT):5000 -ti '$(IMAGEWTAG)-python$(PYMAIN)' --default-plugins
|
2017-02-27 10:37:43 +00:00
|
|
|
|
|
|
|
run: run-$(PYMAIN)
|
2016-09-20 18:55:59 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
push-latest: $(addprefix push-latest-,$(PYVERSIONS)) ## Push the "latest" tag to dockerhub
|
2017-02-27 19:00:09 +00:00
|
|
|
docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGEWTAG)'
|
|
|
|
docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGENAME)'
|
2017-03-01 16:59:35 +00:00
|
|
|
docker push '$(IMAGENAME):latest'
|
2017-02-27 19:00:09 +00:00
|
|
|
docker push '$(IMAGEWTAG)'
|
2017-02-27 11:14:39 +00:00
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
push-latest-%: build-% ## Push the latest image for a specific python version
|
2017-05-19 12:38:29 +00:00
|
|
|
docker tag $(IMAGENAME):$(VERSION)-python$* $(IMAGENAME):python$*
|
|
|
|
docker push $(IMAGENAME):$(VERSION)-python$*
|
|
|
|
docker push $(IMAGENAME):python$*
|
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
push-%: build-% ## Push the image of the current version (tagged). e.g. push-2.7
|
2017-02-27 19:38:55 +00:00
|
|
|
docker push $(IMAGENAME):$(VERSION)-python$*
|
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
push: $(addprefix push-,$(PYVERSIONS)) ## Push an image with the current version for every python version
|
2017-03-01 17:49:52 +00:00
|
|
|
docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGEWTAG)'
|
|
|
|
docker push $(IMAGENAME):$(VERSION)
|
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
push-github: ## Push the code to github. You need to set up HUB_USER and HUB_PASSWORD
|
2017-05-19 15:55:52 +00:00
|
|
|
$(eval KEY_FILE := $(shell mktemp))
|
|
|
|
@echo "$$GITHUB_DEPLOY_KEY" > $(KEY_FILE)
|
|
|
|
@git remote rm github-deploy || true
|
|
|
|
git remote add github-deploy $(GITHUB_REPO)
|
2017-06-12 18:47:46 +00:00
|
|
|
@GIT_SSH_COMMAND="ssh -i $(KEY_FILE)" git fetch github-deploy $(CI_COMMIT_REF_NAME) || true
|
2017-05-19 15:55:52 +00:00
|
|
|
@GIT_SSH_COMMAND="ssh -i $(KEY_FILE)" git push github-deploy $(CI_COMMIT_REF_NAME)
|
|
|
|
rm $(KEY_FILE)
|
|
|
|
|
2017-08-27 16:43:40 +00:00
|
|
|
ci: ## Run a task using gitlab-runner. Only use to debug problems in the CI pipeline
|
|
|
|
gitlab-runner exec shell --builds-dir '.builds' --env CI_PROJECT_NAME=$(NAME) ${action}
|
2017-05-19 12:38:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
.PHONY: test test-% test-all build-% build test pip_test run yapf push-main push-% dev ci version .FORCE deploy
|