Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit ba78da0

Browse files
Workflow improvements (#1066)
* Added Makefile to easily run tests and improve code quality * Fix build for MAD docker image * Update development build to use the MAD docker image
1 parent 293df9c commit ba78da0

22 files changed

+494
-60
lines changed

.flake8

Lines changed: 0 additions & 4 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ configs/coords/*
2323
status.json
2424
update_log.json
2525
commands.json
26+
.tox/
2627
# Byte-compiled / optimized / DLL files
2728
__pycache__/
2829
*.py[cod]

.gitlint

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[general]
2+
ignore=title-trailing-punctuation, title-must-not-contain-word
3+
4+
[title-max-length]
5+
line-length=120
6+
7+
[body-max-line-length]
8+
line-length=140

.gitmessage

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# (ISSUE IF APPLICABLE) SHORT_DESCRIPTION
2+
3+
# LONG_DESCRIPTION
4+
# * Thing 1
5+
# * Thing 2

.isort.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
known_third_party = PIL,aioconsole,apkutils,bitstring,configargparse,cv2,dataclasses,flask,flask_caching,gevent,google,gpapi,gpxdata,imutils,loguru,mysql,numpy,pkg_resources,psutil,pytesseract,pytest,requests,s2sphere,urllib3,websockets,werkzeug

.pre-commit-config.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
repos:
2+
- repo: https://github.com/Seeefo/manage-commit-msg.git
3+
rev: 1.0.3
4+
hooks:
5+
- id: restore-commit-msg
6+
- repo: https://github.com/jorisroovers/gitlint
7+
rev: v0.13.1
8+
hooks:
9+
- id: gitlint
10+
- repo: https://github.com/Seeefo/manage-commit-msg.git
11+
rev: 1.0.3
12+
hooks:
13+
- id: save-commit-msg
14+
- repo: https://gitlab.com/pycqa/flake8
15+
rev: 3.7.9
16+
hooks:
17+
- id: flake8
18+
language_version: python3
19+
additional_dependencies: [flake8-bugbear, flake8-logging-format, flake8-variables-names, pep8-naming, flake8-eradicate]
20+
- repo: https://github.com/asottile/seed-isort-config
21+
rev: v2.1.0
22+
hooks:
23+
- id: seed-isort-config
24+
language_version: python3
25+
- repo: https://github.com/pre-commit/mirrors-isort
26+
rev: v4.3.21
27+
hooks:
28+
- id: isort
29+
language_version: python3
30+
- repo: https://github.com/pre-commit/pre-commit-hooks
31+
rev: v2.5.0
32+
hooks:
33+
- id: trailing-whitespace
34+
- id: end-of-file-fixer

Makefile

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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

docker/.dev.env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
COMPOSE_CONVERT_WINDOWS_PATHS=1
2+
COMPOSE_FILE_DEV=docker/docker-compose-dev.yaml
3+
DOCKER_USER=dockeruser
4+
5+
LOCAL_MAD_IMAGE=local_mad_production
6+
LOCAL_MAD_DEV_IMAGE=local_mad_development
7+
8+
MYSQL_ROOT_PASSWORD=password
9+
MYSQL_DATABASE=rocketdb
10+
MYSQL_USER=rocketdb
11+
MYSQL_PASSWORD=rocketdb
12+
13+
THERAIDMAPPER_DBIP=mariadb
14+
THERAIDMAPPER_DBUSERNAME=${MYSQL_USER}
15+
THERAIDMAPPER_DBNAME=${MYSQL_DATABASE}
16+
THERAIDMAPPER_DBPASSWORD=${MYSQL_USER}

.dockerignore renamed to docker/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ temp/
66
files/
77
upload/
88
update_log.json
9+
docker/

Dockerfile renamed to docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
############################
22
# MAD
33
############################
4-
FROM python:3.7-slim
4+
FROM python:3.7-slim AS mad-core
55
# Working directory for the application
66
WORKDIR /usr/src/app
77

8+
89
# copy requirements only, to reduce image size and improve cache usage
910
COPY requirements.txt /usr/src/app/
1011

0 commit comments

Comments
 (0)