-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
138 lines (113 loc) · 3.26 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
help:
@cat Makefile
.EXPORT_ALL_VARIABLES:
# create an .env file to override the default settings
-include .env
export $(shell sed 's/=.*//' .env)
.PHONY: build docs
# ----------------
# default settings
# ----------------
# user
LOCAL_USER:=$(shell whoami)
LOCAL_USER_ID:=$(shell id -u)
# project
PROJECT_NAME?=sdata
# python
PYTHON?=python
PYTHON_EXEC?=python -m
PYTHONVERSION?=3.10.10
PYTEST?=pytest
SYSTEM=$(shell python -c "import sys; print(sys.platform)")
# poetry
PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
POETRY=poetry
# docker
DOCKER?=docker
DOCKERFILE?=Dockerfile
REGISTRY=registry.com
MEMORY=8g
SHM=4g
CPUS=1
DOCKER_COMMON_FLAGS=--cpus=$(CPUS) --memory=$(MEMORY) --shm-size=$(SHM) --network=host --volume $(PWD):/workdir -e LOCAL_USER_ID -e LOCAL_USER
IMAGE=$(REGISTRY)/$(PROJECT_NAME)
IMAGE_PYTHON=/$(PROJECT_NAME)/bin/python
CUDA_DEVICE=1
BUILD_CMD=$(DOCKER) build -t $(REGISTRY)/$(PROJECT_NAME) --build-arg project_name=$(PROJECT_NAME) -f $(DOCKERFILE) .
# -----------
# install project's dependencies
# -----------
# dev dependencies
install-init:
$(PYTHON_EXEC) pip install --upgrade pip
$(PYTHON_EXEC) pip install --upgrade setuptools virtualenv poetry setuptools_rust
# install main dependencies with poetry (dynamic installation)
install-w-poetry:
$(PYTHON_EXEC) $(POETRY) install --no-cache
poetry-lock:
nohup poetry lock 2>&1 > logs/poetry-lock.log &
# MAIN: w poetry (dynamic): install dev deps, then main deps, export frozen, then project
poetry-install: install-init
poetry-install: install-w-poetry
# MAIN: default installation method
install: poetry-install
install-nohup:
mkdir -p logs || echo "Folder already exists."
nohup make install 2>&1 > logs/install.log &
# -----------
# testing
# -----------
pytest:
bash scripts/pytest.sh
# ---
# git
# ---
# squash all commits before rebasing, see https://stackoverflow.com/questions/25356810/git-how-to-squash-all-commits-on-branch
git-squash:
git reset $(git merge-base main $(git branch --show-current))
git add -A
git commit -m "squashed commit"
# Locally delete branches that have been merged
git-clean:
bash scripts/git-clean.sh
# -----------
# docker
# -----------
# build project's image
build: DOCKER_HOST=
build:
$(BUILD_CMD)
build-nohup: DOCKER_HOST=
build-nohup:
mkdir -p logs || echo "Folder already exists."
nohup $(BUILD_CMD) 2>&1 > logs/build-$(shell echo "$(DOCKERFILE)" | tr "/" "-").log &
# launch bash session within a container
bash: DOCKER_HOST=
bash:
$(DOCKER) run --rm -it $(DOCKER_COMMON_FLAGS) \
--name $(PROJECT_NAME)-bash \
-t $(REGISTRY)/$(PROJECT_NAME) bash
# run
run: CONFIG=main
run: RANDOM=$(shell bash -c 'echo $$RANDOM')
run: CONTAINER_NAME=run-$(CONFIG)-$(RANDOM)
run: SCRIPT=experiments/main.py
run: DOCKER_FLAGS=
run: GPU_FLAGS=
run: OVERRIDE=
run: NOW=$(shell date '+%Y-%m-%d_%H:%M:%S')
run: CMD=$(IMAGE_PYTHON) -u /workdir/$(SCRIPT) --config-name $(CONFIG) $(OVERRIDE)
run:
$(DOCKER) run --rm -it $(DOCKER_FLAGS) $(DOCKER_COMMON_FLAGS) \
$(GPU_FLAGS) \
--name $(PROJECT_NAME)-$(CONTAINER_NAME) \
-t $(REGISTRY)/$(PROJECT_NAME) \
$(CMD)
# clean dangling images
clean: DOCKER_HOST=
clean:
$(DOCKER) system prune
# WARNING: cleans everything, even images you may want to keep
clean-all: DOCKER_HOST=
clean-all:
$(DOCKER) rmi $(docker images -f dangling=true -q)