Skip to content

Commit

Permalink
Fix Docker builds hanging/OOMing (#535)
Browse files Browse the repository at this point in the history
* 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:
- matrix-org/synapse#14173
- matrix-org/synapse@424d1d2

* Update changelog

Co-authored-by: Half-Shot <will@half-shot.uk>
  • Loading branch information
AndrewFerr and Half-Shot authored Oct 17, 2022
1 parent fdcb5a2 commit c0efb91
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/docker-hub-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ jobs:
platforms: ${{ env.PLATFORMS }}
push: ${{ env.PUSH }}
tags: |
${{ env.DOCKER_NAMESPACE }}/matrix-hookshot:latest
${{ 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
5 changes: 5 additions & 0 deletions .github/workflows/docker-hub-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelog.d/535.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increase network timeout for Docker builds, and fix Docker build OOMing in CI for arm64 builds.

0 comments on commit c0efb91

Please sign in to comment.