-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
108 lines (91 loc) · 4.13 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
.PHONY: build build-full pull pack-benchmark pack-submission repack-submission repack-example test-submission
# ================================================================================================
# Settings
# ================================================================================================
TAG = latest
LOCAL_TAG = local
TASK = pose-estimation
REPO = spacecraft-pose-${TASK}
REGISTRY_IMAGE = spacecraftpose.azurecr.io/${REPO}:${TAG}
LOCAL_IMAGE = ${REPO}:${LOCAL_TAG}
CONTAINER_NAME = spacecraft-pose-${TASK}
# if not TTY (for example GithubActions CI) no interactive tty commands for docker
ifneq (true, ${GITHUB_ACTIONS_NO_TTY})
TTY_ARGS = -it
endif
# To run a submission, use local version if that exists; otherwise, use official version
# setting SUBMISSION_IMAGE as an environment variable will override the image
SUBMISSION_IMAGE ?= $(shell docker images -q ${LOCAL_IMAGE})
ifeq (,${SUBMISSION_IMAGE})
SUBMISSION_IMAGE := $(shell docker images -q ${REGISTRY_IMAGE})
endif
# Give write access to the submission folder to everyone so Docker user can write when mounted
_submission_write_perms:
mkdir -p submission/
chmod -R 0777 submission/
# ================================================================================================
# Commands for building the container if you are changing the requirements
# ================================================================================================
## Builds the container locally
build:
docker build -t ${LOCAL_IMAGE} runtime
build-full:
docker build --no-cache -t ${LOCAL_IMAGE} runtime
## Ensures that your locally built container can import all the Python packages successfully when it runs
test-container: build _submission_write_perms
docker run \
${TTY_ARGS} \
--mount type=bind,source="$(shell pwd)"/runtime/tests,target=/tests,readonly \
${LOCAL_IMAGE} \
pytest tests/test_packages.py
## Start your locally built container and open a bash shell within the running container; same as submission setup except has network access
interact-container: build _submission_write_perms
docker run \
--mount type=bind,source="$(shell pwd)"/data,target=/code_execution/data,readonly \
--mount type=bind,source="$(shell pwd)"/submission,target=/code_execution/submission \
--shm-size 8g \
-it \
--entrypoint /bin/bash \
${LOCAL_IMAGE}
## Pulls the official container from Azure Container Registry
pull:
docker pull ${REGISTRY_IMAGE}
## Creates a submission/submission.zip file from the source code in examples_src
pack-example:
# Don't overwrite so no work is lost accidentally
ifneq (,$(wildcard ./submission/submission.zip))
$(error You already have a submission/submission.zip file. Rename or remove that file (e.g., rm submission/submission.zip).)
endif
mkdir -p submission/
cd example_src; zip -r ../submission/submission.zip ./*
## Creates a submission/submission.zip file from the source code in submission_src
pack-submission:
# Don't overwrite so no work is lost accidentally
ifneq (,$(wildcard ./submission/submission.zip))
$(error You already have a submission/submission.zip file. Rename or remove that file (e.g., rm submission/submission.zip).)
endif
mkdir -p submission/
cd submission_src; zip -r ../submission/submission.zip ./*
repack-submission: clean pack-submission
repack-example: clean pack-example
## Runs container using code from `submission/submission.zip` and data from `data/`
test-submission: _submission_write_perms
# if submission file does not exist
ifeq (,$(wildcard ./submission/submission.zip))
$(error To test your submission, you must first put a "submission.zip" file in the "submission" folder. \
If you want to use the benchmark, you can run `make pack-benchmark` first)
endif
docker run \
${TTY_ARGS} \
--network none \
--mount type=bind,source="$(shell pwd)"/data,target=/code_execution/data,readonly \
--mount type=bind,source="$(shell pwd)"/submission,target=/code_execution/submission \
--shm-size 8g \
--name ${CONTAINER_NAME} \
--rm \
${SUBMISSION_IMAGE}
## Delete temporary Python cache and bytecode files
clean:
find . -type f -name "*.py[co]" -delete
find . -type d -name "__pycache__" -delete
rm -rf ./submission/*