Skip to content

Commit bf8ddf7

Browse files
committed
Several dockerfile cleanups (user and cache)
Just trying to make consistent our use of the user name we create. This makes the user name the same across all images and makes sure it is being used in the right places. Some tinkering with the caches we use for the RUN statements. Dropped the UID (there is very little documentation about how this actually affects the cache and whose UID it is) so we'll use the default. Added cache statements for apt statements as well. Note that for good connections, the caching does not make a measurable difference in the time to build. It could be that we are still not using the cache appropriately. Signed-off-by: Mic Bowman <[email protected]>
1 parent 22b9557 commit bf8ddf7

6 files changed

+78
-53
lines changed

Diff for: docker/pdo_base.dockerfile

+22-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ ENV TERM=screen-256color
2525
# -----------------------------------------------------------------
2626
ARG ADD_APT_PKGS=
2727

28-
ENV DEBIAN_FRONTEND "noninteractive"
29-
RUN apt-get update \
28+
ENV DEBIAN_FRONTEND="noninteractive"
29+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
30+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
31+
apt-get update \
3032
&& apt-get install -y -q --no-install-recommends \
3133
autoconf \
3234
automake \
@@ -77,5 +79,23 @@ RUN wget -q https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$
7779
&& dpkg --install ${WASI_PACKAGE} \
7880
&& rm ${WASI_PACKAGE}
7981

82+
# -----------------------------------------------------------------
83+
# Create the pdo_user account and group that will be used for
84+
# future installations into the pdo install directory
85+
# -----------------------------------------------------------------
86+
ARG UNAME=pdo_user
87+
ENV UNAME=${UNAME}
88+
89+
ARG UID=1000
90+
ARG GID=$UID
91+
92+
RUN groupadd -f -g $GID -o $UNAME
93+
RUN useradd -m -u $UID -g $GID -d /project/pdo -o -s /bin/bash $UNAME
94+
95+
# -----------------------------------------------------------------
96+
# Prep for the installation
97+
# -----------------------------------------------------------------
98+
USER $UNAME
99+
80100
WORKDIR /project/pdo/tools
81101
COPY tools/environment.sh ./

Diff for: docker/pdo_ccf.dockerfile

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# to cache pip downloads between builds, cutting down noticeably build time.
2020
# Note that cache is cleaned with the "uusal" docker prune commans, e.g., docker builder prune.
2121

22-
ARG PDO_VERSION
22+
ARG PDO_VERSION=latest
2323
FROM pdo_ccf_base:${PDO_VERSION}
2424

2525
# -----------------------------------------------------------------
@@ -38,6 +38,13 @@ ENV PDO_DEBUG_BUILD=${PDO_DEBUG_BUILD}
3838
ARG XFER_DIR=/project/pdo/xfer
3939
ENV XFER_DIR=${XFER_DIR}
4040

41+
# copy the source files into the image using the user
42+
# identity that was created in the base container
43+
ARG UNAME=pdo_user
44+
ENV UNAME=${UNAME}
45+
46+
USER $UNAME
47+
4148
# copy the source files into the image
4249
WORKDIR /project/pdo
4350
COPY --chown=${UNAME}:${UNAME} repository /project/pdo/src
@@ -49,9 +56,7 @@ WORKDIR /project/pdo/tools
4956
COPY --chown=${UNAME}:${UNAME} tools/*.sh ./
5057

5158
# build it!!!
52-
ARG UID=1000
53-
ARG GID=${UID}
54-
RUN --mount=type=cache,uid=${UID},gid=${GID},target=/project/pdo/.cache/pip \
59+
RUN --mount=type=cache,target=/project/pdo/.cache/pip \
5560
/project/pdo/tools/build_ccf.sh
5661

5762
# Network ports for running services

Diff for: docker/pdo_ccf_base.dockerfile

+15-9
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ ARG UBUNTU_NAME=focal
2424

2525
ENV TERM=screen-256color
2626

27+
USER root
28+
2729
# -----------------------------------------------------------------
2830
# Install base packages
2931
# -----------------------------------------------------------------
3032
ARG ADD_APT_PKGS=
3133

32-
ENV DEBIAN_FRONTEND "noninteractive"
33-
RUN apt-get update \
34+
ENV DEBIAN_FRONTEND="noninteractive"
35+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
36+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
37+
apt-get update \
3438
&& apt-get install -y -q --no-install-recommends \
3539
libsecp256k1-dev \
3640
lsof \
@@ -46,8 +50,9 @@ RUN apt-get update \
4650
RUN echo "deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu ${UBUNTU_NAME} main" >> /etc/apt/sources.list
4751
RUN curl https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add -
4852

49-
50-
RUN apt-get update \
53+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
54+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
55+
apt-get update \
5156
&& apt-get install -y --no-install-recommends \
5257
sgx-aesm-service \
5358
libsgx-dcap-ql \
@@ -59,19 +64,20 @@ RUN apt-get clean \
5964
&& rm -rf /var/lib/apt/lists/*
6065

6166
# -----------------------------------------------------------------
67+
# Create the pdo_user account and group that will be used for
68+
# future installations into the pdo install directory
6269
# -----------------------------------------------------------------
63-
WORKDIR /project/pdo
64-
65-
ARG UNAME=pdo_ccf
70+
ARG UNAME=pdo_user
6671
ENV UNAME=${UNAME}
6772

6873
ARG UID=1000
6974
ARG GID=$UID
7075

71-
RUN echo $UID $GID
7276
RUN groupadd -f -g $GID -o $UNAME
7377
RUN useradd -m -u $UID -g $GID -d /project/pdo -o -s /bin/bash $UNAME
74-
RUN chown --recursive $UNAME:$UNAME /project/pdo
78+
79+
# -----------------------------------------------------------------
7580
USER $UNAME
7681

82+
WORKDIR /project/pdo
7783
ENTRYPOINT ["/bin/bash"]

Diff for: docker/pdo_client.dockerfile

+14-18
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,9 @@
1919
# to cache pip downloads between builds, cutting down noticeably build time.
2020
# Note that cache is cleaned with the "uusal" docker prune commans, e.g., docker builder prune.
2121

22-
ARG PDO_VERSION
22+
ARG PDO_VERSION=latest
2323
FROM pdo_base:${PDO_VERSION}
2424

25-
# -----------------------------------------------------------------
26-
# -----------------------------------------------------------------
27-
WORKDIR /project/pdo
28-
29-
ARG UNAME=pdo_client
30-
ENV UNAME=${UNAME}
31-
32-
ARG UID=1000
33-
ARG GID=${UID}
34-
35-
RUN groupadd -f -g $GID -o $UNAME
36-
RUN useradd -m -u $UID -g $GID -d /project/pdo -o -s /bin/bash $UNAME
37-
RUN chown --recursive $UNAME:$UNAME /project/pdo
38-
USER $UNAME
39-
4025
# -----------------------------------------------------------------
4126
# set up the PDO sources
4227
# -----------------------------------------------------------------
@@ -54,6 +39,16 @@ ENV PDO_INTERPRETER=${PDO_INTERPRETER}
5439
ARG PDO_LOG_LEVEL=info
5540
ENV PDO_LOG_LEVEL=${PDO_LOG_LEVEL}
5641

42+
# -----------------------------------------------------------------
43+
# use the identity created in the base container
44+
# -----------------------------------------------------------------
45+
ARG UNAME=pdo_user
46+
ENV UNAME=${UNAME}
47+
48+
USER $UNAME
49+
50+
# -----------------------------------------------------------------
51+
# -----------------------------------------------------------------
5752
# copy the source files into the image
5853
WORKDIR /project/pdo
5954
COPY --chown=${UNAME}:${UNAME} repository /project/pdo/src
@@ -65,8 +60,9 @@ WORKDIR /project/pdo/tools
6560
COPY --chown=${UNAME}:${UNAME} tools/*.sh ./
6661

6762
# build it!!!
68-
RUN --mount=type=cache,uid=${UID},gid=${GID},target=/project/pdo/.cache/pip \
63+
RUN --mount=type=cache,target=/project/pdo/.cache/pip \
6964
/project/pdo/tools/build_client.sh
7065

71-
RUN ln -s /project/pdo/tools/bashrc_client.sh /project/pdo/.bashrc
66+
RUN rm -f /project/pdo/.bashrc; ln -s /project/pdo/tools/bashrc_client.sh /project/pdo/.bashrc
67+
7268
ENTRYPOINT [ "/bin/bash" ]

Diff for: docker/pdo_services.dockerfile

+10-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# to cache pip downloads between builds, cutting down noticeably build time.
2020
# Note that cache is cleaned with the "uusal" docker prune commans, e.g., docker builder prune.
2121

22-
ARG PDO_VERSION
22+
ARG PDO_VERSION=latest
2323
FROM pdo_services_base:${PDO_VERSION}
2424

2525
# -----------------------------------------------------------------
@@ -28,7 +28,7 @@ FROM pdo_services_base:${PDO_VERSION}
2828
ARG REBUILD=0
2929

3030
ARG SGX_MODE=SIM
31-
ENV SGX_MODE $SGX_MODE
31+
ENV SGX_MODE=$SGX_MODE
3232

3333
ARG PDO_DEBUG_BUILD=1
3434
ENV PDO_DEBUG_BUILD=${PDO_DEBUG_BUILD}
@@ -45,7 +45,12 @@ ENV PDO_MEMORY_CONFIG=${PDO_MEMORY_CONFIG}
4545
ARG PDO_LOG_LEVEL=info
4646
ENV PDO_LOG_LEVEL=${PDO_LOG_LEVEL}
4747

48-
# copy the source files into the image
48+
# copy the source files into the image using the user
49+
# identity that was created in the base container
50+
ARG UNAME=pdo_user
51+
ENV UNAME=${UNAME}
52+
53+
USER $UNAME
4954
WORKDIR /project/pdo
5055
COPY --chown=${UNAME}:${UNAME} repository /project/pdo/src
5156

@@ -55,18 +60,15 @@ COPY --chown=${UNAME}:${UNAME} repository /project/pdo/src
5560
WORKDIR /project/pdo/tools
5661
COPY --chown=${UNAME}:${UNAME} tools/*.sh ./
5762

58-
# built it!
59-
ARG UID=1000
60-
ARG GID=${UID}
61-
RUN --mount=type=cache,uid=${UID},gid=${GID},target=/project/pdo/.cache/pip \
63+
# build it!
64+
RUN --mount=type=cache,target=/project/pdo/.cache/pip \
6265
/project/pdo/tools/build_services.sh
6366

6467
# Network ports for running services
6568
EXPOSE 7001 7002 7003 7004 7005
6669
EXPOSE 7101 7102 7103 7104 7105
6770
EXPOSE 7201 7202 7203 7204 7205
6871

69-
7072
# Note that the entry point when specified with exec syntax
7173
# can be extended through the docker run interface far more
7274
# easily than if you use the other specification format of

Diff for: docker/pdo_services_base.dockerfile

+8-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
# ------------------------------------------------------------------------------
1616

17-
ARG PDO_VERSION
17+
ARG PDO_VERSION=latest
1818
FROM pdo_base:${PDO_VERSION}
1919

2020
ARG UBUNTU_VERSION=22.04
@@ -24,7 +24,11 @@ ARG SGX=2.25
2424
ARG OPENSSL=3.0.14
2525
ARG SGXSSL=3.0_Rev4
2626

27-
RUN echo "deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu ${UBUNTU_NAME} main" >> /etc/apt/sources.list \
27+
USER root
28+
29+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
30+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
31+
echo "deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu ${UBUNTU_NAME} main" >> /etc/apt/sources.list \
2832
&& wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add - \
2933
&& apt-get update \
3034
&& apt-get install -y \
@@ -86,17 +90,9 @@ ENV SGX_SSL="/opt/intel/sgxssl"
8690

8791
# -----------------------------------------------------------------
8892
# -----------------------------------------------------------------
89-
WORKDIR /project/pdo
90-
91-
ARG UNAME=pdo_services
93+
ARG UNAME=pdo_user
9294
ENV UNAME=${UNAME}
9395

94-
ARG UID=1000
95-
ARG GID=$UID
96-
97-
RUN groupadd -f -g $GID -o $UNAME
98-
RUN useradd -m -u $UID -g $GID -d /project/pdo -o -s /bin/bash $UNAME
99-
RUN chown --recursive $UNAME:$UNAME /project/pdo
10096
USER $UNAME
101-
97+
WORKDIR /project/pdo
10298
ENTRYPOINT ["/bin/bash"]

0 commit comments

Comments
 (0)