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

Dependency resolution does not appear to follow symlink context when in a dockerfile #11073

Open
kevin-lindsay-1 opened this issue May 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kevin-lindsay-1
Copy link

kevin-lindsay-1 commented May 14, 2024

What version of Bun is running?

1.1.8+89d25807f

What platform is your computer?

Linux 6.5.0-28-generic x86_64 x86_64

What steps can reproduce the bug?

  1. Create an example project using bunx create-remix <name>
  2. bun install, bun run build, bun start work as normal
  3. Create a fairly basic dockerfile and attempt to build

Your dockerfile may be slightly simpler than this, but here's the important lines from mine:

FROM oven/bun:1.1.8-alpine
WORKDIR "/usr/root/function"
COPY [\
  "./function/bun.lock*", \
  "./function/package.json*", \
  "./"\
  ]
COPY [ "./function/node_modules/", "./node_modules/" ]
RUN bun install --frozen-lockfile
COPY [ "./function/", "./" ]
RUN bun run build

Using this (default) build script:

// package.json
{
  "scripts":  {
    "build": "remix vite:build"
  }
}

References this binary, which is a symlink:

> readlink -f ./node_modules/.bin/remix
/<omitted for privacy>/node_modules/@remix-run/dev/dist/cli.js

Which contains this line:

// .../node_modules/@remix-run/dev/dist/cli.js
var index = require('./index');

Which produces this error:

 > [build 1/2] RUN bun run build:
#10 0.073 $ remix vite:build
#10 0.086 error: Cannot find module "./index" from "/usr/root/function/node_modules/.bin/remix"
#10 0.086 
#10 0.086 Bun v1.1.8 (Linux x64 baseline)
#10 0.087 error: script "build" exited with code 1

Changing the cli.js file to output directory information results in the symlink's directory being output:

const { cwd } = require('process');
console.log(cwd());
console.log(__dirname);
var index = require('./index');
 > [build 1/2] RUN bun run build:
#16 0.099 $ remix vite:build
#16 0.113 /usr/root/function
#16 0.113 /usr/root/function/node_modules/.bin

This can be worked around by supplying a path to the actual folder being executed from:

// package.json
{
  "scripts":  {
    "build": "./node_modules/@remix-run/dev/dist/cli.js vite:build"
  }
}

What is the expected behavior?

The symlink is followed, the context is set to the symlink's destination directory, and the require succeeds.

What do you see instead?

The symlink is followed, the context is not set to the symlink's destination directory, and the require fails.

Additional information

I imagine you'll want to find out why the symlink doesn't appear to be followed when using a package.json script, because it seems to be working locally in Ubuntu, not sure why it works in one and not others.

I tried this using different dockerhub images, all of them had this problem. Seems like there's something I missed, or this is something specific to docker? I ran this using the built-in docker builder, and I also ran using the kubernetes docker builder. Both had this problem.

@kevin-lindsay-1 kevin-lindsay-1 added the bug Something isn't working label May 14, 2024
@kevin-lindsay-1 kevin-lindsay-1 changed the title Dependency resolution does not appear to follow symlinks when in a dockerfile Dependency resolution does not appear to follow symlink context when in a dockerfile May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant