Reorder dockerfile to optimize rebuilds (#438)

* Reorder dockerfile to optimize rebuilds

* Add changelog
This commit is contained in:
Justin Carlson 2022-08-11 13:11:55 -04:00 committed by GitHub
parent a79309071d
commit b0eaa8b3b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -3,9 +3,6 @@
# as musl doesn't support cdylib
FROM node:16 AS builder
COPY . /src
WORKDIR /src
# We need rustup so we have a sensible rust version, the version packed with bullsye is too old
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal
ENV PATH="/root/.cargo/bin:${PATH}"
@ -14,8 +11,14 @@ ENV PATH="/root/.cargo/bin:${PATH}"
# See https://github.com/matrix-org/matrix-rust-sdk-bindings/blob/main/crates/matrix-sdk-crypto-nodejs/release/Dockerfile.linux#L5-L6
RUN apt-get update && apt-get install -y build-essential cmake
# Workaround: Need to install esbuild manually https://github.com/evanw/esbuild/issues/462#issuecomment-771328459
WORKDIR /src
COPY package.json yarn.lock ./
RUN yarn --ignore-scripts --pure-lockfile
COPY . ./
# Workaround: Need to install esbuild manually https://github.com/evanw/esbuild/issues/462#issuecomment-771328459
RUN node node_modules/esbuild/install.js
RUN yarn build
@ -23,18 +26,19 @@ RUN yarn build
# Stage 1: The actual container
FROM node:16-slim
COPY --from=builder /src/lib/ /bin/matrix-hookshot/
COPY --from=builder /src/public/ /bin/matrix-hookshot/public/
COPY --from=builder /src/package.json /bin/matrix-hookshot/
COPY --from=builder /src/yarn.lock /bin/matrix-hookshot/
WORKDIR /bin/matrix-hookshot
COPY --from=builder /src/yarn.lock /src/package.json ./
# --ignore-scripts so we don't try to build
RUN yarn --ignore-scripts --production --pure-lockfile && yarn cache clean
# Copy rust bindings for crypto, since we built them in the previous step.
COPY --from=builder /src/node_modules/@turt2live/matrix-sdk-crypto-nodejs /bin/matrix-hookshot/node_modules/@turt2live/matrix-sdk-crypto-nodejs
COPY --from=builder /src/lib ./
COPY --from=builder /src/public ./public
VOLUME /data
EXPOSE 9993
EXPOSE 7775

1
changelog.d/438.misc Normal file
View File

@ -0,0 +1 @@
Optimize docker image rebuilds.