Skip to content

Commit e2676ff

Browse files
committed
Squashes docker layers from the build.
1 parent 4128e16 commit e2676ff

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

ML-Frameworks/pytorch-aarch64/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ where `YY` is the year, and `MM` the month of the increment.
1010
### Added
1111

1212
### Changed
13+
- Updated Dockerfile to minimise layers in the final image.
1314

1415
### Removed
1516

ML-Frameworks/pytorch-aarch64/Dockerfile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
# Specify DOCKER_IMAGE_MIRROR if you want to use a mirror of hub.docker.com
2020
ARG DOCKER_IMAGE_MIRROR=""
21-
FROM ${DOCKER_IMAGE_MIRROR}ubuntu:22.04
21+
FROM ${DOCKER_IMAGE_MIRROR}ubuntu:22.04 AS workshop
22+
23+
ARG USERNAME
2224

2325
ARG TORCH_WHEEL
2426
ENV TORCH_WHEEL=$TORCH_WHEEL
@@ -44,7 +46,7 @@ RUN apt-get update && apt-get install -y \
4446
&& rm -rf /var/lib/apt/lists/*
4547

4648
# DOCKER_USER for the Docker user
47-
ENV DOCKER_USER=ubuntu
49+
ENV DOCKER_USER=${USERNAME}
4850

4951
# Setup default user
5052
RUN useradd --create-home -s /bin/bash -m $DOCKER_USER && echo "$DOCKER_USER:Portland" | chpasswd && adduser $DOCKER_USER sudo
@@ -112,4 +114,16 @@ RUN sudo mkdir -p /home/ubuntu/gen_ai_utils/ && \
112114
sudo git config --global --add safe.directory /home/ubuntu/gen_ai_utils/torchchat && \
113115
sudo git checkout 90749d280bbc116fcc121a1eda1b60f1dba5b675
114116

117+
# Move build into final image as a single layer.
118+
FROM ${DOCKER_IMAGE_MIRROR}ubuntu:22.04
119+
120+
ARG USERNAME
121+
122+
ENV DOCKER_USER=${USERNAME}
123+
124+
COPY --from=workshop / /
125+
RUN chown $DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER
126+
127+
USER $DOCKER_USER
128+
WORKDIR /home/$DOCKER_USER
115129
CMD ["bash", "-l"]

ML-Frameworks/pytorch-aarch64/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ torch_wheel_name=$(grep -o "torch-.*.whl" $build_log | head -n -1 | tail -n 1)
5050
# Use the second to last match, otherwise grep finds itself
5151
torch_ao_wheel_name=$(grep -o "torchao-.*.whl" $build_log | head -n -1 | tail -n 1)
5252

53-
docker build -t toolsolutions-pytorch:latest \
53+
DOCKER_BUILDKIT=1 docker build -t toolsolutions-pytorch:latest \
5454
--build-arg TORCH_WHEEL=results/$torch_wheel_name \
5555
--build-arg DOCKER_IMAGE_MIRROR \
5656
--build-arg TORCH_AO_WHEEL=ao/dist/$torch_ao_wheel_name \
57+
--build-arg USERNAME=ubuntu \
5758
.

ML-Frameworks/tensorflow-aarch64/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ where `YY` is the year, and `MM` the month of the increment.
1010
### Added
1111

1212
### Changed
13+
- Updated Dockerfile to minimise layers in the final image.
1314

1415
### Removed
1516

ML-Frameworks/tensorflow-aarch64/Dockerfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
# Specify DOCKER_IMAGE_MIRROR if you want to use a mirror of hub.docker.com
1919
ARG DOCKER_IMAGE_MIRROR=""
20-
FROM ${DOCKER_IMAGE_MIRROR}ubuntu:22.04
20+
FROM ${DOCKER_IMAGE_MIRROR}ubuntu:22.04 AS workshop
21+
22+
ARG USERNAME
2123

2224
ARG TENSORFLOW_WHEEL
2325
ENV TENSORFLOW_WHEEL=$TENSORFLOW_WHEEL
@@ -76,4 +78,16 @@ RUN pip install -r requirements.txt --no-deps
7678
# Setup Examples
7779
COPY --chown=$DOCKER_USER examples/ /home/$DOCKER_USER/
7880

81+
# Move build into final image as a single layer.
82+
FROM ${DOCKER_IMAGE_MIRROR}ubuntu:22.04
83+
84+
ARG USERNAME
85+
86+
ENV DOCKER_USER=${USERNAME}
87+
88+
COPY --from=workshop / /
89+
RUN chown $DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER
90+
91+
USER $DOCKER_USER
92+
WORKDIR /home/$DOCKER_USER
7993
CMD ["bash", "-l"]

0 commit comments

Comments
 (0)