-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.docker
More file actions
56 lines (45 loc) · 1.92 KB
/
Makefile.docker
File metadata and controls
56 lines (45 loc) · 1.92 KB
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
SHELL := /bin/bash
NVIDIA_UBUNTU_VER?=20.04
INTEL_UBUNTU_VER?=22.04
GPU?=NVIDIA
override GPU := $(shell printf '%s' "$(GPU)" | tr '[:lower:]' '[:upper:]')
ifeq ($(GPU),NVIDIA)
TOOL := xpu-nvidia
DOCKER_FILE := Dockerfile-ubuntu-$(NVIDIA_UBUNTU_VER)-cuda
DOCKER_IMAGE := ubuntu:$(NVIDIA_UBUNTU_VER)-$(TOOL)
DOCKER_RUN_GPU_OPT := --gpus all
else ifeq ($(GPU),INTEL)
TOOL := xpu-intel
DOCKER_FILE := Dockerfile-ubuntu-$(INTEL_UBUNTU_VER)-oneapi
DOCKER_IMAGE := ubuntu:$(INTEL_UBUNTU_VER)-$(TOOL)
DOCKER_RUN_GPU_OPT := --device=/dev/dri
else
$(error GPU must be 'Intel' or 'NVIDIA')
endif
DOCKER_FILES=$(wildcard Dockerfile*)
# For use with --no-cache, --pull, etc.
DOCKER_BUILD_OPT?=
# Reconstruct the timezone for tzdata
TZFULL=$(subst /, ,$(shell readlink /etc/localtime))
TZ=$(word $(shell expr $(words $(TZFULL)) - 1 ),$(TZFULL))/$(word $(words $(TZFULL)),$(TZFULL))
.PHONY: run run-root-cwd run-root build build-all
run:
docker run $(DOCKER_RUN_GPU_OPT) --rm -it -v "${PWD}:${PWD}" --user $(shell id -u):$(shell id -g) -w "${PWD}" $(DOCKER_IMAGE)
# Uses --privileged for advanced root operations within the container.
run-root:
docker run $(DOCKER_RUN_GPU_OPT) --privileged --rm -it -v "${PWD}:${PWD}" --user root -w "${PWD}" $(DOCKER_IMAGE)
build: $(DOCKER_FILE).build
# Use a .PHONY target to build all of the docker images if requested
Dockerfile%.build: Dockerfile%
docker build --build-arg TZ_ARG=$(TZ) $(DOCKER_BUILD_OPT) -f $(<) -t $(DOCKER_IMAGE) .
BUILD_ALL_TARGETS=$(foreach f,$(DOCKER_FILES),$(f).build)
build-all: $(BUILD_ALL_TARGETS)
help:
@echo "Docker Management"
@echo "================="
@echo ""
@echo " build - Build the default Docker image ($(DOCKER_IMAGE))"
@echo " build-all - Build all Docker images found in Dockerfile-*"
@echo " run - Run the default Docker image as current user with PWD mounted"
@echo " run-root - Run the default Docker image as root with PWD mounted"
@echo ""