-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathdocker.mk
More file actions
205 lines (178 loc) · 7 KB
/
docker.mk
File metadata and controls
205 lines (178 loc) · 7 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Version of golang to use in docker specific builds.
GOLANG_VERSION ?= $(shell ./hack/golang-version.sh)
# Global definitions. These are defined here to allow the docker targets to be
# invoked directly without the root makefile.
WITH_NVCGO ?= yes
WITH_LIBELF ?= no
WITH_TIRPC ?= no
WITH_SECCOMP ?= yes
DOCKER ?= docker
LIB_NAME ?= libnvidia-container
PLATFORM ?= $(shell uname -m)
DIST_DIR ?= $(CURDIR)/dist
MAKE_DIR ?= $(CURDIR)/mk
REVISION ?= $(shell git rev-parse HEAD)
include $(CURDIR)/versions.mk
# Supported OSs by architecture
AMD64_TARGETS := ubuntu20.04 ubuntu18.04 ubuntu16.04 debian10 debian9
X86_64_TARGETS := centos7 centos8 rhel7 rhel8 amazonlinux2 opensuse-leap15.1
PPC64LE_TARGETS := ubuntu18.04 ubuntu16.04 centos7 centos8 rhel7 rhel8
ARM64_TARGETS := ubuntu18.04
AARCH64_TARGETS := centos7 rhel7 centos8 rhel8 amazonlinux2
# Define top-level build targets
docker%: SHELL:=/bin/bash
# When using Podman, local images are stored under localhost/ so run uses the same name
IMAGE_PREFIX := $(if $(filter podman,$(DOCKER)),localhost/,)
# When using Podman (often on SELinux hosts), :z allows the container to write to the volume
VOLUME_OPTS := $(if $(filter podman,$(DOCKER)),:z,)
# Podman defaults to OCI image format which ignores SHELL; use docker format so RUN uses bash
DOCKER_BUILD_FMT := $(if $(filter podman,$(DOCKER)),--format docker,)
# Native targets (for tab completion by OS name only on native platform)
ifeq ($(PLATFORM),x86_64)
NATIVE_TARGETS := $(AMD64_TARGETS) $(X86_64_TARGETS)
$(AMD64_TARGETS): %: %-amd64
$(X86_64_TARGETS): %: %-x86_64
else ifeq ($(PLATFORM),ppc64le)
NATIVE_TARGETS := $(PPC64LE_TARGETS)
$(PPC64LE_TARGETS): %: %-ppc64le
else ifeq ($(PLATFORM),aarch64)
NATIVE_TARGETS := $(ARM64_TARGETS) $(AARCH64_TARGETS)
$(ARM64_TARGETS): %: %-arm64
$(AARCH64_TARGETS): %: %-aarch64
endif
docker-native: $(NATIVE_TARGETS)
# amd64 targets
AMD64_TARGETS := $(patsubst %, %-amd64, $(AMD64_TARGETS))
$(AMD64_TARGETS): ARCH := amd64
$(AMD64_TARGETS): %: --%
docker-amd64: $(AMD64_TARGETS)
# x86_64 targets
X86_64_TARGETS := $(patsubst %, %-x86_64, $(X86_64_TARGETS))
$(X86_64_TARGETS): ARCH := x86_64
$(X86_64_TARGETS): %: --%
docker-x86_64: $(X86_64_TARGETS)
# arm64 targets
ARM64_TARGETS := $(patsubst %, %-arm64, $(ARM64_TARGETS))
$(ARM64_TARGETS): ARCH := arm64
$(ARM64_TARGETS): %: --%
docker-arm64: $(ARM64_TARGETS)
# aarch64 targets
AARCH64_TARGETS := $(patsubst %, %-aarch64, $(AARCH64_TARGETS))
$(AARCH64_TARGETS): ARCH := aarch64
$(AARCH64_TARGETS): %: --%
docker-aarch64: $(AARCH64_TARGETS)
# ppc64le targets
PPC64LE_TARGETS := $(patsubst %, %-ppc64le, $(PPC64LE_TARGETS))
$(PPC64LE_TARGETS): ARCH := ppc64le
$(PPC64LE_TARGETS): WITH_LIBELF := yes
$(PPC64LE_TARGETS): %: --%
docker-ppc64le: $(PPC64LE_TARGETS)
# docker target to build for all os/arch combinations
docker-all: $(AMD64_TARGETS) $(X86_64_TARGETS) \
$(ARM64_TARGETS) $(AARCH64_TARGETS) \
$(PPC64LE_TARGETS)
# Default variables for all private '--' targets below.
# One private target is defined for each OS we support.
--%: CFLAGS :=
--%: LDLIBS :=
--%: TARGET_PLATFORM = $(*)
--%: VERSION = $(patsubst $(OS)%-$(ARCH),%,$(TARGET_PLATFORM))
--%: BASEIMAGE = $(OS):$(VERSION)
--%: BUILDIMAGE = $(IMAGE_PREFIX)nvidia/$(LIB_NAME)/$(OS)$(VERSION)-$(ARCH)
--%: DOCKERFILE = $(MAKE_DIR)/Dockerfile.$(OS)
--%: ARTIFACTS_DIR = $(DIST_DIR)/$(OS)$(VERSION)/$(ARCH)
--%: docker-build-%
@
# Define verify targets to run a minimal sanity check that everything has built
# and runs correctly for a given OS on amd64/x86_64. Requires a working NVIDIA
# driver installation on a native amd64/x86_64 machine.
$(patsubst %, %-verify, $(AMD64_TARGETS)): ARCH := amd64
$(patsubst %, %-verify, $(AMD64_TARGETS)): %-verify: --verify-%
$(patsubst %, %-verify, $(X86_64_TARGETS)): ARCH := x86_64
$(patsubst %, %-verify, $(X86_64_TARGETS)): %-verify: --verify-%
docker-amd64-verify: $(patsubst %, %-verify, $(AMD64_TARGETS)) \
$(patsubst %, %-verify, $(X86_64_TARGETS))
--verify-%: docker-verify-%
@
# private OS targets with defaults
--ubuntu%: OS := ubuntu
--debian%: OS := debian
--amazonlinux%: OS := amazonlinux
# private centos target with overrides
--centos%: OS := centos
--centos%: WITH_TIRPC = yes
--centos%: WITH_LIBELF = yes
--centos8%: BASEIMAGE = quay.io/centos/centos:stream8
# private opensuse-leap target with overrides
--opensuse-leap%: OS := opensuse-leap
--opensuse-leap%: BASEIMAGE = opensuse/leap:$(VERSION)
# private rhel target (actually built on centos)
--rhel%: OS := centos
--rhel%: VERSION = $(patsubst rhel%-$(ARCH),%,$(TARGET_PLATFORM))
--rhel%: ARTIFACTS_DIR = $(DIST_DIR)/rhel$(VERSION)/$(ARCH)
--rhel8%: CFLAGS := -I/usr/include/tirpc
--rhel8%: LDLIBS := -ltirpc
--rhel8%: BASEIMAGE = quay.io/centos/centos:stream8
--verify-rhel%: OS := centos
--verify-rhel%: VERSION = $(patsubst rhel%-$(ARCH),%,$(TARGET_PLATFORM))
docker-build-%: $(ARTIFACTS_DIR)
@echo "Building for $(TARGET_PLATFORM)"
$(DOCKER) pull --platform=linux/$(ARCH) $(BASEIMAGE)
DOCKER_BUILDKIT=1 \
$(DOCKER) build \
$(DOCKER_BUILD_FMT) \
--platform=linux/$(ARCH) \
--progress=plain \
--build-arg BASEIMAGE="$(BASEIMAGE)" \
--build-arg OS_VERSION="$(VERSION)" \
--build-arg OS_ARCH="$(ARCH)" \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg WITH_NVCGO="$(WITH_NVCGO)" \
--build-arg WITH_LIBELF="$(WITH_LIBELF)" \
--build-arg WITH_TIRPC="$(WITH_TIRPC)" \
--build-arg WITH_SECCOMP="$(WITH_SECCOMP)" \
--build-arg CFLAGS="$(CFLAGS)" \
--build-arg LDLIBS="$(LDLIBS)" \
--build-arg REVISION="$(REVISION)" \
--build-arg LIB_VERSION="$(LIB_VERSION)" \
--build-arg LIB_TAG="$(LIB_TAG)" \
--build-arg LIB_BUILD="$(LIB_BUILD)" \
$(EXTRA_BUILD_ARGS) \
--tag $(BUILDIMAGE) \
--file $(DOCKERFILE) .
mkdir -p $(ARTIFACTS_DIR)
$(DOCKER) run \
--platform=linux/$(ARCH) \
--rm \
-e TAG \
-v $(ARTIFACTS_DIR):/dist$(VOLUME_OPTS) \
$(BUILDIMAGE)
docker-verify-%: %
@echo "Verifying for $(TARGET_PLATFORM)"
$(DOCKER) run \
--privileged \
--runtime=nvidia \
-e NVIDIA_VISIBLE_DEVICES=all \
--rm $(BUILDIMAGE) \
bash -c "make install; LD_LIBRARY_PATH=/usr/local/lib/ nvidia-container-cli -k -d /dev/tty info"
docker-clean:
IMAGES=$$($(DOCKER) images "$(IMAGE_PREFIX)nvidia/$(LIB_NAME)/*" --format="{{.ID}}"); \
if [ "$${IMAGES}" != "" ]; then \
$(DOCKER) rmi -f $${IMAGES}; \
fi
$(ARTIFACTS_DIR):
mkdir -p $(@)