From c0efb91c9ab0dda74e0e7d039467387dc05ac10c Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 17 Oct 2022 13:09:15 -0400 Subject: [PATCH] Fix Docker builds hanging/OOMing (#535) * Add network timeouts to Docker builds * Split cargo build out * Put cargo in the right place * debug usage * install time * Fix docker build OOMing in CI for arm64 builds Yoinked from synapse: - https://github.com/matrix-org/synapse/pull/14173 - https://github.com/matrix-org/synapse/commit/424d1d28cc73df1fcad70e7fff5978864d99b1d0 * Update changelog Co-authored-by: Half-Shot --- .github/workflows/docker-hub-latest.yml | 7 ++++++- .github/workflows/docker-hub-release.yml | 5 +++++ Dockerfile | 12 +++++++++--- changelog.d/535.misc | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 changelog.d/535.misc diff --git a/.github/workflows/docker-hub-latest.yml b/.github/workflows/docker-hub-latest.yml index 95a2499d7..88c8b5180 100644 --- a/.github/workflows/docker-hub-latest.yml +++ b/.github/workflows/docker-hub-latest.yml @@ -34,4 +34,9 @@ jobs: platforms: ${{ env.PLATFORMS }} push: ${{ env.PUSH }} tags: | - ${{ env.DOCKER_NAMESPACE }}/matrix-hookshot:latest \ No newline at end of file + ${{ env.DOCKER_NAMESPACE }}/matrix-hookshot:latest + + # arm64 builds OOM without the git fetch setting. c.f. + # https://github.com/rust-lang/cargo/issues/10583 + build-args: | + CARGO_NET_GIT_FETCH_WITH_CLI=true \ No newline at end of file diff --git a/.github/workflows/docker-hub-release.yml b/.github/workflows/docker-hub-release.yml index 7046ad45c..4f8725f77 100644 --- a/.github/workflows/docker-hub-release.yml +++ b/.github/workflows/docker-hub-release.yml @@ -36,3 +36,8 @@ jobs: push: true tags: | ${{ env.DOCKER_NAMESPACE }}/matrix-hookshot:${{ env.RELEASE_VERSION }} + + # arm64 builds OOM without the git fetch setting. c.f. + # https://github.com/rust-lang/cargo/issues/10583 + build-args: | + CARGO_NET_GIT_FETCH_WITH_CLI=true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1345f78ea..3b1235dba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,17 +7,23 @@ FROM node:16 AS builder RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal ENV PATH="/root/.cargo/bin:${PATH}" +# arm64 builds consume a lot of memory if `CARGO_NET_GIT_FETCH_WITH_CLI` is not +# set to true, so we expose it as a build-arg. +ARG CARGO_NET_GIT_FETCH_WITH_CLI=false +ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_NET_GIT_FETCH_WITH_CLI + # Needed to build rust things for matrix-sdk-crypto-nodejs # 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 +RUN apt-get update && apt-get install -y build-essential cmake time WORKDIR /src COPY package.json yarn.lock ./ -RUN yarn --ignore-scripts --pure-lockfile +RUN yarn --ignore-scripts --pure-lockfile --network-timeout 600000 COPY . ./ +RUN /usr/bin/time -v cargo build --jobs 1 # 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 @@ -31,7 +37,7 @@ WORKDIR /bin/matrix-hookshot COPY --from=builder /src/yarn.lock /src/package.json ./ -RUN yarn --production --pure-lockfile && yarn cache clean +RUN yarn --network-timeout 600000 --production --pure-lockfile && yarn cache clean COPY --from=builder /src/lib ./ COPY --from=builder /src/public ./public diff --git a/changelog.d/535.misc b/changelog.d/535.misc new file mode 100644 index 000000000..c5847bdb8 --- /dev/null +++ b/changelog.d/535.misc @@ -0,0 +1 @@ +Increase network timeout for Docker builds, and fix Docker build OOMing in CI for arm64 builds.