|
| 1 | +CMD ?= bash |
| 2 | +CONTAINER_NAME ?= mapadroid-dev |
| 3 | +include docker/.dev.env |
| 4 | +export |
| 5 | + |
| 6 | +define PIP_MISSING |
| 7 | +Pip is missing or not available in PATH. If pip is not installed |
| 8 | +instructions can be found at https://pip.pypa.io/en/stable/installing/ |
| 9 | +endef |
| 10 | + |
| 11 | +define PRE_COMMIT_MISSING |
| 12 | +Install pre-commit @ https://pre-commit.com/#install then run |
| 13 | +source ~/.profile |
| 14 | +endef |
| 15 | + |
| 16 | +define DOCKER_MISSING |
| 17 | +Docker installation is missing or not available. This could be caused by |
| 18 | +not having docker installed or the user does not have access to docker. |
| 19 | +Installation instructions can be found at |
| 20 | +https://docs.docker.com/get-docker/ |
| 21 | +endef |
| 22 | + |
| 23 | +define DOCKER_NOT_RUNNING |
| 24 | +Docker is not running or the user does not have access to the Docker |
| 25 | +Engine. Please verify that its running and you have access. On *nix |
| 26 | +systems you can run the following commands to grant access: |
| 27 | +sudo groupadd docker |
| 28 | +sudo usermod -aG docker $USER |
| 29 | +newgrp docker |
| 30 | +endef |
| 31 | + |
| 32 | +define DOCKER_COMPOSE_MISSING |
| 33 | +docker-compose -f ${COMPOSE_FILE_DEV} is not installed or not available in PATH. Installation |
| 34 | +instructions can be found at https://docs.docker.com/compose/install/ |
| 35 | +If docker-compose -f ${COMPOSE_FILE_DEV} is installed PATH needs to be corrected to include |
| 36 | +the binary |
| 37 | +endef |
| 38 | + |
| 39 | +define DOCKER_COMPOSE_OLD |
| 40 | +docker-compose -f ${COMPOSE_FILE_DEV} is too old. Update docker-compose -f ${COMPOSE_FILE_DEV} from the instructions at |
| 41 | +https://docs.docker.com/compose/install/ |
| 42 | +endef |
| 43 | + |
| 44 | +# Windows defines OS but *nix does not |
| 45 | +ifdef OS |
| 46 | + SHELL := powershell.exe |
| 47 | + pip := $(shell Get-Command pip | Select-Object -ExpandProperty Source) |
| 48 | + precommit := $(shell Get-Command pre-commit | Select-Object -ExpandProperty Source) |
| 49 | + docker := $(shell Get-Command docker | Select-Object -ExpandProperty Source) |
| 50 | + docker_compose := $(shell Get-Command docker-compose -f ${COMPOSE_FILE_DEV} | Select-Object -ExpandProperty Source) |
| 51 | + UID ?= 1000 |
| 52 | + GID ?= 1000 |
| 53 | +else |
| 54 | + ifneq ($(shell which pip),) |
| 55 | + pip := $(shell which pip) |
| 56 | + else ifneq ($(shell which pip3),) |
| 57 | + pip := $(shell which pip3) |
| 58 | + else |
| 59 | + $(error $(PIP_MISSING)) |
| 60 | + endif |
| 61 | + precommit := $(shell which pre-commit) |
| 62 | + docker := $(shell which docker) |
| 63 | + docker_compose := $(shell which docker-compose -f ${COMPOSE_FILE_DEV}) |
| 64 | + UID ?= $(shell id -u) |
| 65 | + GID ?= $(shell id -g) |
| 66 | +endif |
| 67 | + |
| 68 | + |
| 69 | +ifeq (, $(pip)) |
| 70 | + $(error $(PIP_MISSING)) |
| 71 | +endif |
| 72 | +ifneq ($(VIRTUAL_ENV), ) |
| 73 | + pip_precommit_installation := $(pip) install pre-commit |
| 74 | +else |
| 75 | + pip_precommit_installation := $(pip) install --user pre-commit |
| 76 | +endif |
| 77 | +ifeq (, $(precommit)) |
| 78 | + $(error $(PRE_COMMIT_MISSING)) |
| 79 | +endif |
| 80 | +ifeq (, $(docker)) |
| 81 | + $(error $(DOCKER_MISSING)) |
| 82 | +endif |
| 83 | +ifeq (, $(shell docker info)) |
| 84 | + $(error $(DOCKER_NOT_RUNNING)) |
| 85 | +endif |
| 86 | +ifeq (, $(docker_compose)) |
| 87 | + $(error $(DOCKER_COMPOSE_MISSING)) |
| 88 | +endif |
| 89 | +compose_ver ?= $(shell docker-compose -f ${COMPOSE_FILE_DEV} --version | cut -d' ' -f3 | cut -d '.' -f2) |
| 90 | +ifeq (, compose_ver < 27) |
| 91 | + $(error $(DOCKER_COMPOSE_OLD)) |
| 92 | +endif |
| 93 | + |
| 94 | +clean: clean-tox down |
| 95 | + |
| 96 | +clean-tox: |
| 97 | + rm -rf .tox |
| 98 | + |
| 99 | +build: |
| 100 | + docker build --file docker/Dockerfile --tag ${LOCAL_MAD_IMAGE} . |
| 101 | + docker-compose -f ${COMPOSE_FILE_DEV} build --no-cache |
| 102 | + |
| 103 | +rebuild: |
| 104 | + docker build --file docker/Dockerfile --tag ${LOCAL_MAD_IMAGE} . |
| 105 | + docker-compose -f ${COMPOSE_FILE_DEV} build |
| 106 | + |
| 107 | +setup-precommit: |
| 108 | + $(pip_precommit_installation) |
| 109 | + pre-commit install |
| 110 | + pre-commit install --hook-type commit-msg |
| 111 | + |
| 112 | +setup: setup-precommit |
| 113 | + git config commit.template .gitmessage |
| 114 | + |
| 115 | +up: |
| 116 | + docker-compose -f ${COMPOSE_FILE_DEV} up --detach |
| 117 | + |
| 118 | +shell: up |
| 119 | + docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) $(CONTAINER_NAME) $(CMD) |
| 120 | + |
| 121 | +root-shell: up |
| 122 | + docker-compose -f ${COMPOSE_FILE_DEV} exec -u root $(CONTAINER_NAME) $(CMD) |
| 123 | + |
| 124 | +down: |
| 125 | + docker-compose -f ${COMPOSE_FILE_DEV} down |
| 126 | + |
| 127 | +tests: up |
| 128 | + docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox |
| 129 | + |
| 130 | +unittests: up |
| 131 | + docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox -e py37 |
| 132 | + |
| 133 | +# Run bash within a defined tox environment |
| 134 | +# Specify a valid tox environment as such: |
| 135 | +# make shell-py37 |
| 136 | +# To force a recreation of the environment, specify the RECREATE environment variable with any value |
| 137 | +# make shell-py37 RECREATE=1 |
| 138 | +shell-%: up |
| 139 | +ifdef RECREATE |
| 140 | + docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox -e $* --recreate -- bash |
| 141 | +else |
| 142 | + docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox -e $* -- bash |
| 143 | +endif |
| 144 | + |
| 145 | +versions: |
| 146 | + $(pip) --version |
| 147 | + $(precommit) --version |
| 148 | + $(docker) --version |
| 149 | + $(docker_compose) --version |
0 commit comments