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

Switch from ENTRYPOINT to CMD Dockerfile and clean up #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tom93
Copy link

@tom93 tom93 commented Mar 22, 2023

Merge after #7.

ENTRYPOINT and CMD are similar but CMD is more appropriate because it allows overriding on the command line, e.g. docker run ... kill-sticky sh can now be used to start an interactive shell for debugging.

Also remove set -x from Dockerfile (unnecessary because we use &&), and switch from $(pwd) to $PWD in the build commands because $PWD is cleaner (especially in the Makefile).

tom93 added 3 commits March 22, 2023 16:57
The package 'get-stdin' switched to an ES module in version 9.0.0 [1],
which broke the build (full error message below).

The error could be fixed by switching to a dynamic import(), namely
`import('get-stdin').then(...)`, but that's awkward; so instead this
commit converts bookmarkletify.js to an ES module (by changing the
file extension to .mjs), which allows using the nicer import statement
syntax: `import getStdin from 'get-stdin';`.

There is an additional problem: import specifiers don't support the
NODE_PATH environment variable[2] and only search local 'node_modules'
directories, so the 'get-stdin' module is not found.

This commit fixes the module search problem by installing the
'get-stdin' package locally instead of globally. (The other packages
are still installed globally, so that their executables will be
available in the default $PATH.)

The final complication is the location of the 'node_modules'
directory. The build command bind-mounts the repository into the
container on /kill-sticky. Creating a 'node_modules' directory inside
/kill-sticky at build time wouldn't work, because the bind mount would
hide it. And creating it at runtime is ugly, because it pollutes the
directory outside the container.

Instead, this commit moves /kill-sticky to /build/kill-sticky, and
then creates the 'node_modules' directory in /build (outside the
'kill-sticky' directory so it won't pollute the repository, but still
in the module search path).

---

Here is the error message with get-stdin 9.0.0 prior to this commit:

```
/kill-sticky/src/bookmarkletify.js:1
const getStdin = require('get-stdin');
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/get-stdin/index.js from /kill-sticky/src/bookmarkletify.js not supported.
Instead change the require of index.js in /kill-sticky/src/bookmarkletify.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/kill-sticky/src/bookmarkletify.js:1:18) {
  code: 'ERR_REQUIRE_ESM'
}
```

[1]: sindresorhus/get-stdin@8f70f58

[2]: https://nodejs.org/docs/latest-v19.x/api/esm.html#no-node_path
They are similar but CMD is more appropriate because it allows
overriding on the command line, e.g. `docker run ... kill-sticky sh`
can now be used to start an interactive shell for debugging.

Also remove `set -x` from Dockerfile (unnecessary because we use
`&&`), and switch from `$(pwd)` to `$PWD` in the build commands
because `$PWD` is cleaner (especially in the Makefile).
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 this pull request may close these issues.

1 participant