Skip to content

Commit f3c831e

Browse files
authored
Merge pull request #16 from EntropyOrg/docker-gpu
GPU version of Docker images
2 parents 27fc867 + e428f21 commit f3c831e

File tree

4 files changed

+169
-24
lines changed

4 files changed

+169
-24
lines changed

.github/workflows/build-container.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
uses: docker/[email protected]
3030
with:
3131
files: docker/docker-bake.hcl
32+
targets: |
33+
default
34+
gpu
3235
push: ${{ github.event_name != 'pull_request' }}
3336
set: |
3437
*.cache-from=type=gha

docker/Dockerfile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#syntax=docker/dockerfile-upstream:1.4.0-rc1
22

3-
ARG TF_VERSION="2.11.0"
3+
ARG TF_VERSION
44

55
# Packages from Ubuntu focal base
66
ARG APT_PKGS_PERL="perl cpanminus"
@@ -11,8 +11,6 @@ ARG APT_PKGS_DEV="libffi-dev libssl-dev pkg-config"
1111

1212
FROM perldocker/perl-tester:5.36 AS builder
1313

14-
ARG TF_VERSION
15-
1614
ENV ALIEN_LIBTENSORFLOW_FROM_BINARY_VERSION=${TF_VERSION}
1715

1816
#COPY . /build
@@ -28,8 +26,6 @@ RUN dzil build --in dist
2826

2927
FROM tensorflow/tensorflow:${TF_VERSION}-jupyter AS base-builder
3028

31-
ARG TF_VERSION
32-
3329
ARG APT_PKGS_PERL
3430
ARG APT_PKGS_RUN
3531
ARG APT_PKGS_DEV
@@ -38,6 +34,9 @@ COPY --from=builder /build/dist /build/dist
3834

3935
ENV ALIEN_LIBTENSORFLOW_FROM_BINARY_VERSION=${TF_VERSION}
4036

37+
# Build the base with CPU
38+
ENV ALIEN_LIBTENSORFLOW_DEVICE_TYPE="cpu"
39+
4140
RUN rm -Rfv /tf
4241
RUN mkdir -p /tf
4342

@@ -48,20 +47,26 @@ RUN cpanm -nq App::plx App::cpm
4847
# Init plx in /tf.
4948
RUN bash -c 'cd /tf \
5049
&& plx --init \
51-
&& plx --config libspec add 10perl5-nb.ll /perl5-nb && perl -Mlocal::lib=/perl5-nb \
50+
&& plx --config libspec add 20perl5-nb.ll /perl5-nb && perl -Mlocal::lib=/perl5-nb \
51+
&& plx --config libspec add 10perl5-libtf.ll /perl5-libtf && perl -Mlocal::lib=/perl5-libtf \
5252
&& plx --config libspec add 00perl5-global.ll /perl5 \
5353
&& plx --cpanm -l /perl5 -nq App::cpm \
5454
'
5555

5656
# Install Jupyter kernel
57-
RUN cpm install -L /perl5 Devel::IPerl
57+
RUN plx cpm install -L /perl5 Devel::IPerl IO::Async::Loop::Epoll
58+
59+
# Install libtensorflow (with Alien deps to /perl5 and actual Alien dist to
60+
# /perl5-libtf)
61+
RUN plx --cpanm -l /perl5 --installdeps --no-man-pages -nq Alien::Libtensorflow \
62+
&& plx --cpanm -l /perl5-libtf --no-man-pages -nq Alien::Libtensorflow
5863

5964
# Install the actual dist.
60-
RUN cpm install -L /perl5 /build/dist \
65+
RUN plx --cpanm -l /perl5 -nq --no-man-pages /build/dist \
6166
&& rm -Rf /build/dist
6267

6368
# Clean up
64-
RUN apt-get remove -y $NB_APT_PKGS_DEV && apt-get autoremove
69+
RUN apt-get remove -y $APT_PKGS_DEV && apt-get autoremove -y
6570

6671
RUN apt-get -qq purge \
6772
&& apt-get -qq clean \
@@ -96,8 +101,9 @@ RUN groupadd \
96101
--uid ${NB_UID} \
97102
${NB_USER}
98103

99-
COPY --from=base-builder /perl5 /perl5
100-
COPY --from=base-builder /tf /tf
104+
COPY --from=base-builder /perl5 /perl5
105+
COPY --from=base-builder /perl5-libtf /perl5-libtf
106+
COPY --from=base-builder /tf /tf
101107

102108
# Get rid of upstream tutorials.
103109
RUN rm -Rf /tf/tensorflow-tutorials

docker/Dockerfile.with-gpu-libtf

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#syntax=docker/dockerfile-upstream:1.4.0-rc1
2+
3+
ARG TF_VERSION
4+
ARG TF_DEVICE_TAG
5+
6+
FROM nb-base AS nb-builder
7+
8+
ARG TF_VERSION
9+
ARG TF_DEVICE_TYPE
10+
11+
ENV ALIEN_LIBTENSORFLOW_FROM_BINARY_VERSION=${TF_VERSION}
12+
ENV ALIEN_LIBTENSORFLOW_DEVICE_TYPE=${TF_DEVICE_TYPE}
13+
14+
USER root
15+
16+
RUN rm -Rf /perl5-libtf \
17+
&& plx --cpanm -l /perl5-libtf --no-man-pages -nq Alien::Libtensorflow
18+
19+
FROM tensorflow/tensorflow:${TF_VERSION}${TF_DEVICE_TAG}-jupyter AS nb
20+
21+
# Packages from Ubuntu focal base
22+
ARG APT_PKGS_PERL="perl cpanminus"
23+
ARG APT_PKGS_RUN="libffi7 libssl1.1 libzmq5"
24+
25+
ARG NB_APT_PKGS_RUN
26+
27+
ARG NB_USER
28+
ARG NB_UID
29+
30+
# Use bash as default shell, rather than sh
31+
ENV SHELL /bin/bash
32+
33+
# Set up user
34+
ENV USER ${NB_USER}
35+
ENV HOME /home/${NB_USER}
36+
37+
USER root
38+
39+
RUN groupadd \
40+
--gid ${NB_UID} \
41+
${NB_USER} && \
42+
useradd \
43+
--comment "Default user" \
44+
--create-home \
45+
--gid ${NB_UID} \
46+
--no-log-init \
47+
--shell /bin/bash \
48+
--uid ${NB_UID} \
49+
${NB_USER}
50+
51+
COPY --from=nb-builder /perl5 /perl5
52+
COPY --from=nb-builder /perl5-nb /perl5-nb
53+
COPY --from=nb-builder /perl5-libtf /perl5-libtf
54+
COPY --from=nb-builder /tf /tf
55+
56+
RUN apt-get update && apt-get install -y --no-install-recommends $APT_PKGS_PERL $APT_PKGS_RUN $NB_APT_PKGS_RUN
57+
58+
RUN cpanm -nq App::plx App::cpm
59+
60+
RUN apt-get -qq purge \
61+
&& apt-get -qq clean \
62+
&& rm -rf /var/lib/apt/lists/*
63+
64+
RUN rm -Rf $HOME/.perl-cpm/ $HOME/.cpanm
65+
66+
USER ${NB_USER}
67+
68+
RUN plx iperl --version # install kernel and exit
69+
70+
EXPOSE 8888
71+
72+
ENTRYPOINT [ "plx", "--base", "/tf", "--exec" ]
73+
CMD [ "jupyter", "notebook", "--notebook-dir=/tf", "--ip", "0.0.0.0", "--no-browser" ]
74+
75+
# vim:ft=dockerfile

docker/docker-bake.hcl

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
group "default" {
22
targets = [
3+
# CPU
34
"base",
45
"nb-omnibus",
56
"nb-image-class",
67
"nb-gene-expr-pred",
78
]
89
}
910

11+
group "gpu" {
12+
targets = [
13+
# GPU
14+
"gpu-nb-omnibus",
15+
]
16+
}
17+
18+
variable "TF_VERSION" {
19+
default = "2.12.0"
20+
}
21+
22+
function "TF_LATEST_VERSION" {
23+
params = []
24+
result = "2.12.0" # current upstream version
25+
}
26+
1027
variable "REGISTRY" {
1128
default = "quay.io/entropyorg/"
1229
}
@@ -15,10 +32,6 @@ variable "IMAGE" {
1532
default = "perl-ai-tensorflow-libtensorflow"
1633
}
1734

18-
variable "TAG" {
19-
default = "latest"
20-
}
21-
2235
variable "NB_USER" {
2336
default = "jovyan"
2437
}
@@ -27,47 +40,95 @@ variable "NB_UID" {
2740
default = 1000
2841
}
2942

30-
target "nb" {
43+
function "device2tag" {
44+
params = [device]
45+
result = equal(device,"cpu") ? "" : equal(device,"gpu") ? "-gpu" : ""
46+
}
47+
48+
function "tag" {
49+
params = [device, suffix]
50+
result = [
51+
"${REGISTRY}${IMAGE}:${TF_VERSION}${device2tag(device)}${suffix}",
52+
equal(TF_VERSION, TF_LATEST_VERSION())
53+
? "${REGISTRY}${IMAGE}:latest${device2tag(device)}${suffix}"
54+
: "",
55+
]
56+
}
57+
58+
target "nb-all" {
3159
args = {
3260
NB_USER = NB_USER
3361
NB_UID = NB_UID
62+
TF_VERSION = TF_VERSION
63+
}
64+
}
65+
66+
target "nb-cpu" {
67+
inherits = [ "nb-all" ]
68+
args = {
69+
TF_DEVICE_TYPE = "cpu"
70+
TF_DEVICE_TAG = "${device2tag("cpu")}"
71+
}
72+
}
73+
74+
target "nb-gpu" {
75+
inherits = [ "nb-all" ]
76+
args = {
77+
TF_DEVICE_TYPE = "gpu"
78+
TF_DEVICE_TAG = "${device2tag("gpu")}"
3479
}
3580
}
3681

3782
target "base" {
38-
inherits = [ "nb" ]
83+
inherits = [ "nb-cpu" ]
3984
dockerfile = "docker/Dockerfile"
4085
target = "base"
41-
tags = ["${REGISTRY}${IMAGE}:${TAG}"]
86+
tags = tag("cpu", "")
4287
}
4388

4489
target "nb-image-class" {
45-
inherits = [ "nb" ]
90+
inherits = [ "nb-cpu" ]
4691
dockerfile = "docker/Dockerfile.nb-image-class"
4792
target = "image-classification"
4893
contexts = {
4994
base = "target:base"
5095
}
51-
tags = ["${REGISTRY}${IMAGE}:${TAG}-nb-image-class"]
96+
tags = tag("cpu", "-nb-image-class")
5297
}
5398

5499
target "nb-gene-expr-pred" {
55-
inherits = [ "nb" ]
100+
inherits = [ "nb-cpu" ]
56101
dockerfile = "docker/Dockerfile.nb-gene-expr-pred"
57102
target = "gene-expression-prediction"
58103
contexts = {
59104
base = "target:base"
60105
}
61-
tags = ["${REGISTRY}${IMAGE}:${TAG}-nb-gene-expr-pred"]
106+
tags = tag("cpu", "-nb-gene-expr-pred")
62107
}
63108

64109
target "nb-omnibus" {
65-
inherits = [ "nb" ]
110+
inherits = [ "nb-cpu" ]
66111
dockerfile = "docker/Dockerfile.nb-omnibus"
67112
contexts = {
68113
base = "target:base"
69114
nb-image-class = "target:nb-image-class"
70115
nb-gene-expr-pred = "target:nb-gene-expr-pred"
71116
}
72-
tags = ["${REGISTRY}${IMAGE}:${TAG}-nb-omnibus"]
117+
tags = tag("cpu", "-nb-omnibus")
118+
}
119+
120+
target "gpu-nb-omnibus" {
121+
inherits = [ "nb-gpu" ]
122+
args = {
123+
NB_APT_PKGS_RUN = <<EOF
124+
libjpeg-turbo8 libpng16-16 libgsl23
125+
samtools libhts3 tabix libxml2 libexpat1 libdb5.3 netpbm gnuplot-nox
126+
EOF
127+
}
128+
dockerfile = "docker/Dockerfile.with-gpu-libtf"
129+
target = "nb"
130+
contexts = {
131+
nb-base = "target:nb-omnibus"
132+
}
133+
tags = tag("gpu", "-nb-omnibus")
73134
}

0 commit comments

Comments
 (0)