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

Node path not found error when building image with Alpine #78

Closed
euxx opened this issue Jan 7, 2024 · 0 comments · Fixed by #79
Closed

Node path not found error when building image with Alpine #78

euxx opened this issue Jan 7, 2024 · 0 comments · Fixed by #79

Comments

@euxx
Copy link

euxx commented Jan 7, 2024

Hi, I'm trying to generate Dockerfile with Alpine:

$ bin/rails generate dockerfile --alpine --jemalloc --yjit --cache --parallel

Node part of the generated Dockfile:

# Install JavaScript dependencies
ARG NODE_VERSION=20.10.0
ARG YARN_VERSION=1.22.21
RUN curl -sL https://unofficial-builds.nodejs.org/download/release/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64-musl.tar.gz | tar xz -C /tmp/ && \
    cp -rp /tmp/node-v${NODE_VERSION}-linux-x64-musl/* /usr/local && \
    npm install -g yarn@$YARN_VERSION && \
    rm -rf /tmp/node-v${NODE_VERSION}-linux-x64-musl

# Copy node modules
COPY --from=node /rails/node_modules /rails/node_modules
COPY --from=node /usr/local/node /usr/local/node
ENV PATH=/usr/local/node/bin:$PATH

When building the image, it raises an error:
Error: failed to fetch an image or build from source: error building: failed to solve: failed to compute cache key: "/usr/local/node" not found: not found

Found the reason is the Node paths are inconsistent:

  • cp -rp /tmp/node-v${NODE_VERSION}-linux-x64-musl/* /usr/local && \ use /usr/local
  • COPY --from=node /usr/local/node /usr/local/node use /usr/local/node

I tried to fix it by modifying the Dockerfile:

# Install JavaScript dependencies
ARG NODE_VERSION=20.10.0
ARG YARN_VERSION=1.22.21
+ ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://unofficial-builds.nodejs.org/download/release/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64-musl.tar.gz | tar xz -C /tmp/ && \
+    mkdir /usr/local/node && \
-    cp -rp /tmp/node-v${NODE_VERSION}-linux-x64-musl/* /usr/local && \
+    cp -rp /tmp/node-v${NODE_VERSION}-linux-x64-musl/* /usr/local/node && \
    npm install -g yarn@$YARN_VERSION && \
    rm -rf /tmp/node-v${NODE_VERSION}-linux-x64-musl

It works, but I'm not sure it's the best way.

So please fix it in the generator, thanks.

@rubys rubys linked a pull request Jan 7, 2024 that will close this issue
@rubys rubys closed this as completed in #79 Jan 7, 2024
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

Successfully merging a pull request may close this issue.

1 participant