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

feat: initial draft of the Dockerfile alternative #26

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

Daniel-Boll
Copy link
Collaborator

@Daniel-Boll Daniel-Boll commented Oct 6, 2024

Remaining tasks

  • Configure a CI to release this into the GitHub Docker Registry
  • Configure to do a npm release and GitHub NPM Registry
    The goal is the following:
    npx @basementdevs/scylla-studio@latest
  • (optional) Try to make the Dockerfile image alpine to save some space. [@gvieira18]

Running Scylla Studio via Docker

You can run Scylla Studio directly through Docker without setting up the entire environment. To do this, run the following one-liner:

docker run --rm --name scylla-studio --network="host" ghcr.io/basementdevs/scylla-studio:latest

Persistent Volumes

If you'd like to keep the session data and logs between runs, you can use Docker volumes:

docker run --rm --name scylla-studio --network="host" \
  -v scylla-studio-data:/usr/app/data \
  ghcr.io/basementdevs/scylla-studio:latest

This will create a persistent volume named scylla-studio-data for the application's data.

To remove the volume later:

docker volume rm scylla-studio-data

Signed-off-by: Daniel Boll <danielboll.academico@gmail.com>
@Daniel-Boll Daniel-Boll added the hacktoberfest-accepted Hacktoberfest-able PR label Oct 6, 2024
@Daniel-Boll Daniel-Boll self-assigned this Oct 6, 2024
@Daniel-Boll Daniel-Boll linked an issue Oct 6, 2024 that may be closed by this pull request
@Daniel-Boll
Copy link
Collaborator Author

The build command I'm currently using is the following:

docker buildx build -t basementdevs/scylla-studio .

Copy link
Contributor

@danielhe4rt danielhe4rt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Daniel-Boll
Copy link
Collaborator Author

Copilot Summary

This pull request includes significant updates to Docker support, dependency management, and code formatting. The most important changes include the addition of a Dockerfile, updates to the compose.yml for Docker Compose, improvements in the README.md for Docker usage instructions, and various code formatting and dependency adjustments.

Docker Support:

  • Added a new Dockerfile to build and run the application using a Debian-based Node.js image. This includes stages for dependencies, building, and production setup. (Dockerfile)
  • Updated compose.yml to define services for scylladb and scylla-studio, including resource limits, ports, and network settings. (compose.yml)

Documentation:

  • Enhanced README.md with instructions on running Scylla Studio via Docker, including commands for persistent volumes. (README.md)

Code Formatting and Dependency Management:

  • Updated next.config.mjs to set the output to "standalone" for better Docker compatibility. (next.config.mjs)
  • Moved @types/better-sqlite3 from dependencies to devDependencies in package.json and updated pnpm-lock.yaml accordingly. (package.json, pnpm-lock.yaml) [1] [2] [3] [4]
  • Reformatted tracing-dashboard-render.tsx for better readability and consistency, including fixing import statements and improving state management. (src/app/(main)/query-runner/_components/tracing-dashboard-render.tsx) [1] [2] [3] [4] [5]

Component Refactoring:

  • Refactored Label component to use Radix UI and class-variance-authority for styling. (src/components/ui/label.tsx)

Database Path Adjustment:

  • Modified the database path in connections.ts to use a relative path for better compatibility with Docker. (src/lib/internal-db/connections.ts) [1] [2] [3]

@danielhe4rt danielhe4rt self-requested a review October 7, 2024 16:14
@gvieira18
Copy link
Collaborator

I tried building on this branch locally and got this error.

Error: The module '/app/node_modules/.pnpm/better-sqlite3@11.3.0/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 115. This version of Node.js requires
NODE_MODULE_VERSION 127. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Module._extensions..node (node:internal/modules/cjs/loader:1717:18)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at mod.require (/app/node_modules/.pnpm/next@14.2.13_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/require-hook.js:65:28)
    at require (node:internal/modules/helpers:135:16)
    at bindings (/app/node_modules/.pnpm/bindings@1.5.0/node_modules/bindings/bindings.js:112:48)
    at new Database (/app/node_modules/.pnpm/better-sqlite3@11.3.0/node_modules/better-sqlite3/lib/database.js:48:64) {
  code: 'ERR_DLOPEN_FAILED',
  digest: '948557867'
}

image

Also, why create another user with these IDs?

RUN groupadd --system --gid 1001 nodejs
RUN useradd --system --uid 1001 nextjs

image

@Daniel-Boll
Copy link
Collaborator Author

I took this base docker image from elsewhere, but I'm not sure why the new user though.

About the error, that's odd. Can you try to add pnpm rebuild after the installation?

from roughly 1GB to <180MB

Signed-off-by: Daniel Boll <danielboll.academico@gmail.com>
@Daniel-Boll
Copy link
Collaborator Author

Daniel-Boll commented Oct 8, 2024

I managed to get a working image with less than 200 MiB with cgr.dev/chainguard/node:latest and cgr.dev/chainguard/node:latest-dev I think that's already pretty good.

@YvanDaSilva
Copy link

YvanDaSilva commented Oct 8, 2024

I manage to get a working image with less than 200 MiB with cgr.dev/chainguard/node:latest-dev and cgr.dev/chainguard/node:latest-dev I think that's already pretty good.

Was going to recommend that before leaving stream yesterday in case distroless was not a success.

Glad you got it work :) Congrats.

<200mb is fine for a nodejs image. Try: https://github.com/wagoodman/dive to explore your image, you will see that nodejs alone is 110+MiB

edit: I just tried your image, it still spews the same error.

node:internal/modules/cjs/loader:1251
  throw err;
  ^

Error: Cannot find module '/home/nonroot/node'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:166:5)
    at node:internal/main/run_main_module:30:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v22.9.0

I'll give it another spin later to see if I can figure out what is crashing.

@Daniel-Boll
Copy link
Collaborator Author

I just tried your image, it still spews the same error.

Is there any chance of that being a cache problem? I'll try to prune what I have here and test again to see if I can reproduce it. It would be a good idea if @gvieira18 or @danielhe4rt could test it too.

@diegoreis42
Copy link
Collaborator

I tested on my local machine and it worked fine. I built and ran manually with docker buildx build -t basementdevs/scylla-studio .

@gvieira18
Copy link
Collaborator

Tested locally and worked as expected.

docker build \
  --label "org.opencontainers.image.source=https://github.com/basementdevs/scylla-studio" \
  --label "org.opencontainers.image.created=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
  --tag "basementdevs/scylla-studio:main" \
  --tag "basementdevs/scylla-studio:develop" \
  --progress=plain \
  --file Dockerfile \
  .

image

@YvanDaSilva
Copy link

Very likely something is wrong on my machine (macos aarch64). This means distroless also worked 🙈 lol.
Merge on :D

@Daniel-Boll
Copy link
Collaborator Author

This means distroless also worked 🙈 lol

I couldn't make the distroless one work on my machine, that's why I tried to move to this one. Hopefully it will work on mac eventually, lol. 🙏

@Daniel-Boll Daniel-Boll merged commit d89cf75 into main Oct 8, 2024
@danielhe4rt danielhe4rt deleted the feat/binary-release branch October 8, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Hacktoberfest-able PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: publishing on npx and docker
5 participants