hplush / slowreader

Web app to combine feeds from social networks and RSS and to help read more meaningful and deep content
https://dev.slowreader.app
GNU Affero General Public License v3.0
161 stars 37 forks source link

DevContainer doesn't work on Apple Sillicon Mac #231

Closed 3timeslazy closed 3 months ago

3timeslazy commented 4 months ago

Hi everyone,

First of all, thank you for the awesome project!

Description

I recently ran into a problem running devcontainer on a new MacBook with an M chip. I ran devcontainer using OrbStack and VS Code DevContainer extension and got this error:

 > [dev_container_auto_added_stage_label 8/9] RUN pnpm config set store-dir /home/developer/.local/share/pnpm/store   && pnpm config set ignore-scripts false:
0.089 OrbStack ERROR: Dynamic loader not found: /lib64/ld-linux-x86-64.so.2
0.089 
0.089 This usually means that you're running an x86 program on an arm64 OS without multi-arch libraries.
0.089 To fix this, you can:
0.089   1. Use an Intel (amd64) machine to run this program; or
0.089   2. Install multi-arch libraries in this machine.
0.089 
0.089 This can also be caused by running a glibc executable in a musl distro (e.g. Alpine), or vice versa.
0.089 
0.089 For more details and instructions, see https://go.orbstack.dev/multiarch

I think the problem is on this line:

ADD --checksum=$PNPM_CHECKSUM https://github.com/pnpm/pnpm/releases/download/v$PNPM_VERSION/pnpm-linux-x64 /usr/local/bin/pnpm

That command downloads the same binary regardless of the CPU architecture. When I locally changed that to pnpm-linux-arm64 it worked.

Possible solution

I believe the problem can be solved with the official pnpm install script: https://get.pnpm.io/install.sh. If you look at it, you'll see that it checks the CPU architecture and downloads the corresponding binary.

I tried it locally and replaced the line above with these three lines and it worked:

ENV PNPM_HOME="/usr/local/bin/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN curl -fsSL https://get.pnpm.io/install.sh | PNPM_VERSION="$PNPM_VERSION" ENV="$HOME/.zshrc" SHELL="$(which zsh)" zsh -
ai commented 4 months ago

curl -fsSL https://get.pnpm.io/install.sh

Running unknown script is very unsafe. Also, it will break checksum check.

Seems like we need to add ARM CPU check to Dockerfile.

3timeslazy commented 3 months ago

What do you think about this approach?

# Creates development machine inside docker
# so every developer will have the same environment

FROM docker.io/ubuntu:24.04

ARG TARGETARCH

ENV NODE_VERSION 22.6.0
ENV PNPM_VERSION 9.6.0

ENV NODE_CHECKSUM_arm64 1816e42d4848aa1484910373a1f2f68f43fd6f96a4ef478a9553d05ffa3f8fb2
ENV PNPM_CHECKSUM_arm64 7e5da837e616a613cf257da034d611553c9fdcae54ffa9e1328be0fbcabeb63e
ENV NODE_CHECKSUM_x64   f2f4ccbcbc0a443e5fadebd1149a22f96087ec09cef52ff343a15ee835206d96
ENV PNPM_CHECKSUM_x64   efdfcefb089b01dafa98c4c3fa47f544046d0e4de67055a69b0563875de83175

RUN apt-get update \
  && apt-get install -y eza zsh git tig ripgrep bat curl tar micro psmisc \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

RUN <<EOF

  if [ "$TARGETARCH" = "amd64" ]; then
    export NODE_CHECKSUM=${NODE_CHECKSUM_x64};
    export PNPM_CHECKSUM=${PNPM_CHECKSUM_x64};
    export ARCH="x64"

  elif [ "$TARGETARCH" = "arm64" ]; then
    export NODE_CHECKSUM=$NODE_CHECKSUM_arm64;
    export PNPM_CHECKSUM=$PNPM_CHECKSUM_arm64;
    export ARCH="arm64"

  else
    echo "Unsupported architecture: $TARGETARCH";
    exit 1;
  fi

  curl "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.gz" \
    --fail --show-error --location --silent --output /node.tar.gz;
  echo "$NODE_CHECKSUM /node.tar.gz" | sha256sum -c;

  curl "https://github.com/pnpm/pnpm/releases/download/v${PNPM_VERSION}/pnpm-linux-${ARCH}" \
    --fail --show-error --location --silent --output /usr/local/bin/pnpm;
  echo "$PNPM_CHECKSUM /usr/local/bin/pnpm" | sha256sum -c;

EOF

RUN tar -xz -f /node.tar.gz -C /usr/local --remove-files --strip-components=1 \
  --exclude='*.md' --exclude='LICENSE' \
  --exclude='share' --exclude='lib/node_modules/' \
  --exclude='bin/npm' --exclude='bin/npx' --exclude='bin/corepack'

RUN chmod a+rx /usr/local/bin/pnpm

RUN userdel -r ubuntu && useradd -m -s /bin/zsh developer
USER developer

RUN pnpm config set store-dir /home/developer/.local/share/pnpm/store \
  && pnpm config set ignore-scripts false
RUN echo 'PS1="%d$ "' > ~/.zshrc
ai commented 3 months ago

Looks good, send PR. But can you also update https://github.com/hplush/slowreader/blob/main/scripts/update-env.ts