Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running from node-alpine #299

Closed
Apidcloud opened this issue Jan 13, 2023 · 1 comment
Closed

Running from node-alpine #299

Apidcloud opened this issue Jan 13, 2023 · 1 comment

Comments

@Apidcloud
Copy link

Apidcloud commented Jan 13, 2023

I'm trying to execute the linux bin file from a node-alpine docker image, but still couldn't get it to work because of glibc and libstdc.

By default node-alpine doesn't have glibc (it uses musl instead), causing the following error:
Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

What I'm trying now is to install glibc directly into the alpine image, but it's still throwing:
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

Here's what I'm trying to install:

FROM node:16.17.1-alpine as production

RUN apk --no-cache add  \
  wget            \
  ca-certificates \
  # also tried ++6
  libstdc++

# Get and install glibc for alpine
ARG APK_GLIBC_VERSION=2.33-r0
ARG APK_GLIBC_FILE="glibc-${APK_GLIBC_VERSION}.apk"
ARG APK_GLIBC_BIN_FILE="glibc-bin-${APK_GLIBC_VERSION}.apk"
ARG APK_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${APK_GLIBC_VERSION}"
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
  && wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_FILE}"       \
  && apk --no-cache add "${APK_GLIBC_FILE}"               \
  && wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_BIN_FILE}"   \
  && apk --no-cache add "${APK_GLIBC_BIN_FILE}"           \
  && rm glibc-*

The only way I got it to work thus far was using the non-alpine version, with --platform=linux/amd64, and without the apk add and glibc install . But it's way heavier than the alpine image.

If i use the above docker config with --platform=linux/amd64 I get the following error instead:
/usr/lib/libstdc++.so.6: no version information available qemu: uncaught target signal 11 (Segmentation fault) - core dumped

Although it seems the qemu part is because of amd64 running on mac m1 chip (docker/for-mac#5123), although everything works when using the non-alpine based image.

Maybe I should use another glibc version?

@Apidcloud
Copy link
Author

Apidcloud commented Jan 19, 2023

For those interested to run this through a node alpine, I ended up manually building it within a node alpine docker container. I was using a Ubuntu 22.04 at the time, so the platform was amd64. I then copied the build out of it and started using that linux binary instead.

Used the more up-to-date repo mentioned in #290 .

Instructions:
Let's say you have a Dockerfile as follows:

FROM --platform=linux/amd64 node:16.17.1-alpine as production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /app

COPY package*.json ./

COPY ./.npmrc ./.npmrc

RUN npm ci --production

COPY ./dist ./dist

CMD ["npm", "run", "start:prod"]

The steps roughly follow the github actions of the godotengine fbx2gltf repo.

We start by changing the Dockerfile above to include the following:

ENV GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
ENV GLIBC_VERSION=2.33-r0

RUN set -ex && \
    apk --update add curl ca-certificates && \
    for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; \
        do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
    apk add --allow-untrusted /tmp/*.apk && \
    rm -v /tmp/*.apk && \
    /usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib

RUN apk add alpine-sdk linux-lts-dev p7zip cmake
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setupyools

We then run the docker container and access it through its shell:

$ docker ps -a
$ docker exec -it <container-id> /bin/sh

After, we clone the gotdotengine fbx2gltf repo, and follow along the build.yaml from that repo (combined with the original instructions in facebookincubator to install conan, etc.):

$ git clone https://github.com/godotengine/FBX2glTF.git
$ cd FBX2glTF

To install conan (based on facebookincubator original instructions but changed according to this issue):

$ pip3 install conan
$ conan remote update bincrafters https://bincrafters.jfrog.io/artifactory/api/conan/public-conan

Here's a summary of what's needed (based on godotengine/fbx2gltf github actions build.yaml):

$ curl -O -L "https://github.com/V-Sekai/FBXSDK-Linux/archive/refs/tags/2020.2.zip"
$ 7z x 2020.2.zip
$ mkdir -p sdk
$ mv ./FBXSDK-Linux-2020.2/sdk .
$ zstd -d -r --rm ./sdk || true
$ conan install . -i build -s build_type=Release --build fmt -s compiler.libcxx=libstdc++11 --build missing
$ conan build -bf build .

This should create a folder /build with the binary FBX2glTF inside. You can then copy it that build folder out of the container as so:

docker cp <container-id>:/app/FBX2glTF/build .

Now you can replace the FBX2glTF binary with this one.

As a side note, it only seems to work (through docker) on M1 macs when using --platform=linux/amd64. Otherwise it will raise a qemu error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant