Use RUN --mount=type=cache,... in example backend dockerfile

Signed-off-by: Boris Bera <bbera@coveo.com>
This commit is contained in:
Boris Bera
2022-10-07 12:19:55 -04:00
parent b1c10102a3
commit 632420a0a5
+5 -3
View File
@@ -13,9 +13,10 @@ FROM node:16-bullseye-slim
# Install sqlite3 dependencies. You can skip this if you don't use sqlite3 in the image,
# in which case you should also move better-sqlite3 to "devDependencies" in package.json.
RUN apt-get update && \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential && \
rm -rf /var/lib/apt/lists/* && \
yarn config set python /usr/bin/python3
# From here on we use the least-privileged `node` user to run the backend.
@@ -38,7 +39,8 @@ COPY --chown=node:node yarn.lock package.json packages/backend/dist/skeleton.tar
RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
# Note that this install is not immutable, which is one of the reasons we don't recommend Yarn 3 yet
RUN yarn workspaces focus --all --production && rm -rf "$(yarn cache clean)"
RUN --mount=type=cache,uid=1000,gid=1000,target=/home/node/.yarn/berry/cache,sharing=locked \
yarn workspaces focus --all --production
# Then copy the rest of the backend bundle, along with any other files we might want.
COPY --chown=node:node packages/backend/dist/bundle.tar.gz app-config*.yaml ./