Skip to content

Cobalt Web image Dockerfile #1366

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jo-chemla
Copy link

Build and run image with

docker build -f web/Dockerfile -t cobalt-web .
docker run -e WEB_DEFAULT_API="https://real.api.endpoint" -e WEB_HOST="http://abc"  -e WEB_PLAUSIBLE_HOST="def" -p 800:80 cobalt-web

Currently, vite build still uses process.env env-vars at build time, so the docker container is not using those defined via placeholders in runtime-config.js

Build and run image with

```
docker build -f web/Dockerfile -t cobalt-web .
docker run -e WEB_DEFAULT_API="https://real.api.endpoint" -e WEB_HOST="http://abc"  -e WEB_PLAUSIBLE_HOST="def" -p 800:80 cobalt-web
```

Currently, vite build still uses process.env env-vars at build time, so the docker container is not using those defined via placeholders in `runtime-config.js`
@hyperdefined
Copy link
Contributor

Should use Caddy instead of NGINX.

This is my Dockerfile for hosting web: https://github.com/caninetools/cobalt/blob/main/docker-build/Dockerfile-web

Thanks for getting back @hyperdefined with the direction about using Caddy.
I cannot comment on the issue thread or PR anymore.
This is a fake commit to comment: do you want to edit the PR with your Dockerfile and make the vars editable via docker container env_vars?
@jo-chemla
Copy link
Author

Thanks for getting back @hyperdefined with the direction about using Caddy.
Do you want to edit the PR with your Dockerfile and make the vars editable via docker container env_vars?
Or should I give it a go on my side? Note it seems like it's currently working great with nginx.

@hyperdefined
Copy link
Contributor

hyperdefined commented Jul 2, 2025

I swapped to Caddy since I like it better personally, and I like how it's more lightweight.

As for the environment variables, they are in the build file itself. You can edit them yourself or manually copy in a .env file into the root of the web folder before the site is built.

The site is built in the container before it's published, so passing in environment variables during runtime won't do anything. It has to be done before it's built.

@jo-chemla
Copy link
Author

Thanks again for getting back! What's the point-of-view of the team regarding nginx vs Caddy for this cobalt-web docker image?

Also, this PR uses a docker-entrypoint.sh which replaces runtime docker env variables WEB_HOST, WEB_PLAUSIBLE_HOST, WEB_DEFAULT_API into placeholders in a runtime-config.js file. Only at the moment this config-file.js is not read by the built site.

@verncat
Copy link

verncat commented Jul 21, 2025

bump

@verncat
Copy link

verncat commented Jul 21, 2025

I tried to build image by following your instruction, but it didn't worked
It fails in syscall-napi install

docker build output
~/cobald/$ podman build -f web/Dockerfile -t cobalt-web . --no-cache
[1/2] STEP 1/7: FROM node:20-alpine AS builder
[1/2] STEP 2/7: WORKDIR /repo
--> 54d8f8ca80ed
[1/2] STEP 3/7: RUN npm install -g pnpm 

added 1 package in 2s

1 package is looking for funding
  run `npm fund` for details
npm notice
npm notice New major version of npm available! 10.8.2 -> 11.4.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.4.2
npm notice To update run: npm install -g [email protected]
npm notice
--> 7855d94a9fed
[1/2] STEP 4/7: COPY . .
--> 3ad3da131971
[1/2] STEP 5/7: RUN pnpm install --frozen-lockfile
Scope: all 5 workspace projects
Lockfile is up to date, resolution step is skipped
Progress: resolved 1, reused 0, downloaded 0, added 0
Packages: +395
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 395, reused 0, downloaded 80, added 79
Progress: resolved 395, reused 0, downloaded 235, added 232
Progress: resolved 395, reused 0, downloaded 354, added 352
Progress: resolved 395, reused 0, downloaded 393, added 392
Progress: resolved 395, reused 0, downloaded 394, added 392
Progress: resolved 395, reused 0, downloaded 395, added 394
Progress: resolved 395, reused 0, downloaded 395, added 395
Progress: resolved 395, reused 0, downloaded 395, added 395, done
.../node_modules/ffmpeg-static install$ node install.js
.../node_modules/syscall-napi install$ node-gyp rebuild
.../node_modules/svelte-preprocess postinstall$ echo "[svelte-preprocess] Don't forget to install the preprocessors packages that will be used: sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc..."
.../[email protected]/node_modules/esbuild postinstall$ node install.js
.../[email protected]/node_modules/esbuild postinstall$ node install.js
.../node_modules/svelte-preprocess postinstall: [svelte-preprocess] Don't forget to install the preprocessors packages that will be used: sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc...
.../node_modules/svelte-preprocess postinstall: Done
.../node_modules/syscall-napi install: gyp info it worked if it ends with ok
.../node_modules/syscall-napi install: gyp info using [email protected]
.../node_modules/syscall-napi install: gyp info using [email protected] | linux | x64
.../[email protected]/node_modules/esbuild postinstall: Done
.../node_modules/syscall-napi install: gyp ERR! find Python 
.../node_modules/syscall-napi install: gyp ERR! find Python Python is not set from command line or npm configuration
.../node_modules/syscall-napi install: gyp ERR! find Python Python is not set from environment variable PYTHON
.../node_modules/syscall-napi install: gyp ERR! find Python checking if "python3" can be used
.../node_modules/syscall-napi install: gyp ERR! find Python - executable path is ""
.../node_modules/syscall-napi install: gyp ERR! find Python - "" could not be run
.../node_modules/syscall-napi install: gyp ERR! find Python checking if "python" can be used
.../node_modules/syscall-napi install: gyp ERR! find Python - executable path is ""
.../node_modules/syscall-napi install: gyp ERR! find Python - "" could not be run
.../node_modules/syscall-napi install: gyp ERR! find Python 
.../node_modules/syscall-napi install: gyp ERR! find Python **********************************************************
.../node_modules/syscall-napi install: gyp ERR! find Python You need to install the latest version of Python.
.../node_modules/syscall-napi install: gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
.../node_modules/syscall-napi install: gyp ERR! find Python you can try one of the following options:
.../node_modules/syscall-napi install: gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
.../node_modules/syscall-napi install: gyp ERR! find Python (accepted by both node-gyp and npm)
.../node_modules/syscall-napi install: gyp ERR! find Python - Set the environment variable PYTHON
.../node_modules/syscall-napi install: gyp ERR! find Python - Set the npm configuration variable python:
.../node_modules/syscall-napi install: gyp ERR! find Python npm config set python "/path/to/pythonexecutable"
.../node_modules/syscall-napi install: gyp ERR! find Python For more information consult the documentation at:
.../node_modules/syscall-napi install: gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
.../node_modules/syscall-napi install: gyp ERR! find Python **********************************************************
.../node_modules/syscall-napi install: gyp ERR! find Python 
.../node_modules/syscall-napi install: gyp ERR! configure error 
.../node_modules/syscall-napi install: gyp ERR! stack Error: Could not find any Python installation to use
.../node_modules/syscall-napi install: gyp ERR! stack at PythonFinder.fail (/root/.local/share/pnpm/.tools/pnpm/9.6.0/node_modules/pnpm/dist/node_modules/node-gyp/lib/find-python.js:306:11)
.../node_modules/syscall-napi install: gyp ERR! stack at PythonFinder.findPython (/root/.local/share/pnpm/.tools/pnpm/9.6.0/node_modules/pnpm/dist/node_modules/node-gyp/lib/find-python.js:164:17)
.../node_modules/syscall-napi install: gyp ERR! stack at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
.../node_modules/syscall-napi install: gyp ERR! stack at async configure (/root/.local/share/pnpm/.tools/pnpm/9.6.0/node_modules/pnpm/dist/node_modules/node-gyp/lib/configure.js:27:18)
.../node_modules/syscall-napi install: gyp ERR! stack at async run (/root/.local/share/pnpm/.tools/pnpm/9.6.0/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js:81:18)
.../node_modules/syscall-napi install: gyp ERR! System Linux 6.15.6-100.fc41.x86_64
.../node_modules/syscall-napi install: gyp ERR! command "/usr/local/bin/node" "/root/.local/share/pnpm/.tools/pnpm/9.6.0/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
.../node_modules/syscall-napi install: gyp ERR! cwd /repo/node_modules/.pnpm/[email protected]/node_modules/syscall-napi
.../node_modules/syscall-napi install: gyp ERR! node -v v20.19.4
.../node_modules/syscall-napi install: gyp ERR! node-gyp -v v10.1.0
.../node_modules/syscall-napi install: gyp ERR! not ok 
.../node_modules/syscall-napi install: Failed
.../[email protected]/node_modules/esbuild postinstall: Done
.../node_modules/ffmpeg-static install: Done

Done in 12.7s
x	--> ed0ee5878e85
[1/2] STEP 6/7: WORKDIR /repo/web
--> 182249447377
[1/2] STEP 7/7: RUN pnpm --filter ./web run build
No projects matched the filters in "/repo/web"
--> 67865894c0df
[2/2] STEP 1/8: FROM nginx:alpine
[2/2] STEP 2/8: WORKDIR /usr/share/nginx/html
--> 853747f64228
[2/2] STEP 3/8: COPY --from=builder /repo/web/build .
Error: building at STEP "COPY --from=builder /repo/web/build .": checking on sources under "/var/lib/containers/storage/overlay/de3259beb716e10913908719b723ce7667ad8d6a8c96861aa4e6f45282d464ff/merged": copier: stat: "/repo/web/build": no such file or directory

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.

3 participants