Switch from ENTRYPOINT to CMD Dockerfile and clean up#8
Open
tom93 wants to merge 3 commits into
Open
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 shcan now be used to start an interactive shell for debugging.Also remove
set -xfrom Dockerfile (unnecessary because we use&&), and switch from$(pwd)to$PWDin the build commands because$PWDis cleaner (especially in the Makefile).