Skip to content

Commit

Permalink
fibers fix attempt \#1
Browse files Browse the repository at this point in the history
  • Loading branch information
debdutdeb authored Nov 17, 2023
1 parent 4f9f336 commit f6010aa
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 8 deletions.
11 changes: 10 additions & 1 deletion apps/meteor/.docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ RUN apk add --no-cache ttf-dejavu

COPY dist /app

COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

LABEL maintainer="buildmaster@rocket.chat"

# TODO: use non-root user

RUN set -x \
&& apk add --no-cache --virtual .fetch-deps python3 make g++ libc6-compat \
&& cd /app/bundle/programs/server \
&& npm install --production --unsafe-perm \
&& npm install --production --unsafe-perm; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd npm/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -; \
npm install --production --unsafe-perm || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
&& npm cache clear --force \
&& apk del .fetch-deps

Expand Down
51 changes: 51 additions & 0 deletions apps/meteor/.scripts/fix-arm64-alpine-fibers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/ash
set -xe

cat <<EOF > /dev/null
Why this ugliness?
There are two reasons.
1. For some reason yarn is adding a "node-gyp" script in PATH when running yarn workspaces focus. This shadows any actual installation of node-gyp, and looks for a script at the top level workspace. Adding node-gyp at the root workspace doesn't work either.
2. On arm64, fibers uses ucontexts instead of pthreads. But sadly, my naive attempts at linking with ucontext all failed on arm64 alpine. Why? Very likely I am just that stupid. At this point I am attempting to return to pthreads for arm64 ..hoping this will work and last known issues have been fixed since then.
EOF

apply_patch() {
# https://github.com/debdutdeb/node-fibers/blob/rocketchat-arm64-build-patch/binding.gyp.patch
cat <<EOF > binding.gyp.patch
From d0f0f79ce4a938c5b5a2b577e11f05204e193521 Mon Sep 17 00:00:00 2001
From: Debdut Chakraborty <debdutdeb@outlook.com>
Date: Fri, 17 Nov 2023 10:31:16 +0530
Subject: [PATCH] fix arm64 build
---
binding.gyp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/binding.gyp b/binding.gyp
index 2289325..cc5c62f 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -65,8 +65,8 @@
['target_arch == "arm64"',
{
# There's been problems getting real fibers working on arm
- 'defines': ['CORO_UCONTEXT', '_XOPEN_SOURCE'],
- 'defines!': ['CORO_PTHREAD', 'CORO_SJLJ', 'CORO_ASM'],
+ 'defines': ['CORO_PTHREAD', '_XOPEN_SOURCE'],
+ 'defines!': ['CORO_UCONTEXT', 'CORO_SJLJ', 'CORO_ASM'],
},
],
],
--
2.39.3 (Apple Git-145)
EOF
patch < binding.gyp.patch
}
npm install node-gyp@9.4.1 -g
apply_patch
dest="bin/linux-$(node -p process.arch)-$(node -p process.versions.modules)-musl"
mkdir -p $dest
mv build/Release/fibers.node $dest
rm -rf build
npm uninstall node-gyp -g

rm -f $0
11 changes: 10 additions & 1 deletion ee/apps/account-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,23 @@ COPY ./.yarn/releases .yarn/releases
COPY ./.yarn/patches .yarn/patches
COPY ./ee/apps/${SERVICE}/package.json ee/apps/${SERVICE}/package.json

COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

ENV NODE_ENV=production \
PORT=3000

WORKDIR /app/ee/apps/${SERVICE}

RUN apk update && \
apk --no-cache --virtual build-dependencies add g++ python3 make && \
yarn workspaces focus --production && \
yarn workspaces focus --production; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd /app/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -;\
yarn workspaces focus --production || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
rm -rf /var/cache/apk/* && \
apk del build-dependencies

Expand Down
13 changes: 12 additions & 1 deletion ee/apps/authorization-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,28 @@ COPY ./.yarn/releases .yarn/releases
COPY ./.yarn/patches .yarn/patches
COPY ./ee/apps/${SERVICE}/package.json ee/apps/${SERVICE}/package.json


COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

ENV NODE_ENV=production \
PORT=3000

WORKDIR /app/ee/apps/${SERVICE}

RUN apk update && \
apk --no-cache --virtual build-dependencies add g++ python3 make && \
yarn workspaces focus --production && \
yarn workspaces focus --production; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd /app/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -;\
yarn workspaces focus --production || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
rm -rf /var/cache/apk/* && \
apk del build-dependencies


EXPOSE 3000 9458

CMD ["node", "src/service.js"]
11 changes: 10 additions & 1 deletion ee/apps/ddp-streamer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ COPY ./.yarn/releases .yarn/releases
COPY ./.yarn/patches .yarn/patches
COPY ./ee/apps/${SERVICE}/package.json ee/apps/${SERVICE}/package.json

COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

ENV NODE_ENV=production \
PORT=3000

WORKDIR /app/ee/apps/${SERVICE}

RUN apk update && \
apk --no-cache --virtual build-dependencies add g++ python3 make && \
yarn workspaces focus --production && \
yarn workspaces focus --production; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd /app/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -;\
yarn workspaces focus --production || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
rm -rf /var/cache/apk/* && \
apk del build-dependencies

Expand Down
11 changes: 10 additions & 1 deletion ee/apps/omnichannel-transcript/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ COPY ./.yarn/releases .yarn/releases
COPY ./.yarn/patches .yarn/patches
COPY ./ee/apps/${SERVICE}/package.json ee/apps/${SERVICE}/package.json

COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

ENV NODE_ENV=production \
PORT=3000

WORKDIR /app/ee/apps/${SERVICE}

RUN apk update && \
apk --no-cache --virtual build-dependencies add g++ python3 make && \
yarn workspaces focus --production && \
yarn workspaces focus --production; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd /app/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -;\
yarn workspaces focus --production || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
rm -rf /var/cache/apk/* && \
apk del build-dependencies

Expand Down
11 changes: 10 additions & 1 deletion ee/apps/presence-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ COPY ./.yarn/releases .yarn/releases
COPY ./.yarn/patches .yarn/patches
COPY ./ee/apps/${SERVICE}/package.json ee/apps/${SERVICE}/package.json

COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

ENV NODE_ENV=production \
PORT=3000

WORKDIR /app/ee/apps/${SERVICE}

RUN apk update && \
apk --no-cache --virtual build-dependencies add g++ python3 make && \
yarn workspaces focus --production && \
yarn workspaces focus --production; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd /app/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -;\
yarn workspaces focus --production || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
rm -rf /var/cache/apk/* && \
apk del build-dependencies

Expand Down
11 changes: 10 additions & 1 deletion ee/apps/queue-worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ COPY ./.yarn/releases .yarn/releases
COPY ./.yarn/patches .yarn/patches
COPY ./ee/apps/${SERVICE}/package.json ee/apps/${SERVICE}/package.json

COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

ENV NODE_ENV=production \
PORT=3000

WORKDIR /app/ee/apps/${SERVICE}

RUN apk update && \
apk --no-cache --virtual build-dependencies add g++ python3 make && \
yarn workspaces focus --production && \
yarn workspaces focus --production; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd /app/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -;\
yarn workspaces focus --production || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
rm -rf /var/cache/apk/* && \
apk del build-dependencies

Expand Down
11 changes: 10 additions & 1 deletion ee/apps/stream-hub-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,23 @@ COPY ./.yarn/releases .yarn/releases
COPY ./.yarn/patches .yarn/patches
COPY ./ee/apps/${SERVICE}/package.json ee/apps/${SERVICE}/package.json

COPY apps/meteor/.scripts/fix-arm64-alpine-fibers.sh /fix-fibers.sh

ENV NODE_ENV=production \
PORT=3000

WORKDIR /app/ee/apps/${SERVICE}

RUN apk update && \
apk --no-cache --virtual build-dependencies add g++ python3 make && \
yarn workspaces focus --production && \
yarn workspaces focus --production; code=$?; \
if [[ $(uname -m) == 'aarch64' ]]; then \
cd /app/node_modules/fibers; \
ash /fix-fibers.sh || exit $?; \
cd -;\
yarn workspaces focus --production || exit $?; \
fi; \
if [ $code -ne 0 ]; then exit $code; fi; \
rm -rf /var/cache/apk/* && \
apk del build-dependencies

Expand Down

0 comments on commit f6010aa

Please sign in to comment.