-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (120 loc) · 3.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
MAKEFLAGS += --no-print-directory
## ==== Core Arguments and Parameters ====
MAJOR ?= 0
MINOR ?= 1
VERSION = $(MAJOR).$(MINOR)
APP_NAME ?= rail-core
NUM_BUILD_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
# Handle Optional GPU
USE_GPU ?= true
ifeq ($(USE_GPU),true)
DOCKER_GPU_ARG = --gpus all
endif
# Paths and Key File Names
EXPERIMENT_NAME ?= dbg
# Docker args
DISPLAY ?= :0.0
DATA_BASE_DIR ?= $(shell pwd)/data
RESOURCES_BASE_DIR ?= $(shell pwd)/resources
XPASSTHROUGH ?= false
DOCKER_FILE_DIR = "."
DOCKERFILE = ${DOCKER_FILE_DIR}/Dockerfile
IMAGE_NAME = ${APP_NAME}
DOCKER_CORE_VOLUMES = \
--env XPASSTHROUGH=$(XPASSTHROUGH) \
--env DISPLAY=$(DISPLAY) \
$(DOCKER_GPU_ARG) \
--volume="$(DATA_BASE_DIR):/data/:rw" \
--volume="$(RESOURCES_BASE_DIR):/resources/:ro" \
--volume="$(RESOURCES_BASE_DIR)/notebooks:/notebooks/:rw" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw"
DOCKER_BASE = docker run --init --ipc=host --rm \
$(DOCKER_ARGS) $(DOCKER_CORE_VOLUMES) \
${IMAGE_NAME}:${VERSION}
DOCKER_PYTHON = $(DOCKER_BASE) python3
.PHONY: help
help::
@echo ''
@echo 'Usage: make [TARGET] [EXTRA_ARGUMENTS]'
@echo 'Targets:'
@echo ' help display this help message'
@echo ' build build docker image (incremental)'
@echo ' rebuild build docker image from scratch'
@echo ' kill close all project-related docker containers'
@echo ' test run pytest in docker container'
@echo 'Extra Arguments:'
@echo ' DATA_BASE_DIR [./data] local path to directory for storing data'
@echo ' USE_GPU [true] enable or disable using the GPU'
@echo ' XPASSTHROUGH [false] use the local X server for visualization'
@echo ' PYTEST_FILTER [.py] filter unit tests'
@echo ' DOCKER_ARGS [] extra arguments passed to Docker; -it will enable "interactive mode"'
@echo ''
## ==== Helpers for setting up the environment ====
define xhost_activate
@echo "Enabling local xhost sharing:"
@echo " Display: $(DISPLAY)"
@-DISPLAY=$(DISPLAY) xhost +
@-xhost +
endef
arg-check-data:
@[ "${DATA_BASE_DIR}" ] && true || \
( echo "ERROR: Environment variable 'DATA_BASE_DIR' must be set." 1>&2; exit 1 )
xhost-activate:
$(call xhost_activate)
## ==== Build targets ====
.PHONY: build
build:
@echo "Building the Docker container"
@docker build -t ${IMAGE_NAME}:${VERSION} \
--build-arg NUM_BUILD_CORES=$(NUM_BUILD_CORES) \
-f ./${DOCKERFILE} .
.PHONY: rebuild
rebuild:
@docker build -t ${IMAGE_NAME}:${VERSION} --no-cache \
--build-arg NUM_BUILD_CORES=$(NUM_BUILD_CORES) \
-f ./${DOCKERFILE} .
.PHONY: kill
kill:
@echo "Closing all running docker containers:"
@docker kill $(shell docker ps -q --filter ancestor=${IMAGE_NAME}:${VERSION})
.PHONY: shell
shell: DOCKER_ARGS ?= -it
shell:
@$(DOCKER_BASE) bash
## ==== Running tests & cleanup ====
.PHONY: test
test: DOCKER_ARGS ?= -it
test: PYTEST_FILTER ?= "py"
test: build
@$(call xhost_activate)
@mkdir -p $(DATA_BASE_DIR)/test_logs
@$(DOCKER_PYTHON) \
-m pytest -vk $(PYTEST_FILTER) \
-rsx \
--full-trace \
--ignore-glob=**/pybind11/* \
--html=/data/test_logs/report.html \
--xpassthrough=$(XPASSTHROUGH) \
$(TEST_ADDITIONAL_ARGS) \
/modules/
flake8: DOCKER_ARGS = -it --workdir /modules
flake8: build
@echo "Running flake8 format checker..."
@$(DOCKER_BASE) flake8
@echo "... no formatting issues discovered."
## ==== Other Targets ====
tensorboard:
@docker run -it \
-p 0.0.0.0:6006:6006 \
$(DOCKER_CORE_VOLUMES) \
$(IMAGE_NAME):$(VERSION) tensorboard \
--logdir /data --host 0.0.0.0
notebook: DOCKER_ARGS=-it -p 8888:8888
notebook: build
@$(DOCKER_BASE) jupyter notebook \
--notebook-dir=/notebooks \
--no-browser --allow-root \
--ip 0.0.0.0 \
--NotebookApp.token='' --NotebookApp.password=''
# ==== Includes ====
include modules/taskplan/Makefile.mk