Skip to content

Commit

Permalink
make docker work
Browse files Browse the repository at this point in the history
previously the dockerfile installed the dependencies and you then would mount
the source folder into the container, shadowing the just created node_modules
folder. So this setup only works if you had a node_modules folder on the host
machine already which was kind of the reason to use docker in first place.

To make this work, install the app into a subfolder and create the node_modules
on folder up.

Adopted some example files from here:

- https://github.com/BretFisher/node-docker-good-defaults

Also added a Makefile :-)

So you can just do a 'make docker-server' or 'make docker-build'.
  • Loading branch information
sni committed Jan 12, 2025
1 parent ded40ca commit 434acea
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# add git-ignore syntax here of things you don't want copied into docker image

.git
*Dockerfile*
*docker-compose*
node_modules
9 changes: 9 additions & 0 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ export default defineConfig({
// Can be removed as soon as the legacy content is removed
srcExclude: ['**/legacy/**'],

vite: {
server: {
fs: {
// Allow serving files from one level up to the project root
allow: ['..', '../..'],
},
}
},

themeConfig: {

logo: '/images/svg/naemonlogo.svg',
Expand Down
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
# bash which makes debugging WAY easier
FROM node:22-bookworm

RUN mkdir -p /site
EXPOSE 5173

WORKDIR /site
RUN npm i npm@latest -g

COPY package.json /site/package.json
WORKDIR /opt/node_app

RUN npm install --verbose
COPY package.json package-lock.json* ./
RUN npm install --verbose --include=dev && npm cache clean --force
ENV PATH /opt/node_app/node_modules/.bin:$PATH

EXPOSE 5173
HEALTHCHECK --interval=30s CMD node healthcheck.js

WORKDIR /opt/node_app/app
COPY . .

CMD ["npm", "run", "docs:dev"]
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/make -f

DOCKERRUN=docker run \
--rm -it \
-p 5173:5173 \
--name=naemon-docs \
-v `pwd`:/opt/node_app/app \
-v /opt/node_app/node_modules/ \
-v /opt/node_app/app/.vitepress/cache \
-v /opt/node_app/app/.vitepress/dist \
-v `pwd`/package.json:/opt/node_app/package.json \
naemon/docs:latest

docker-build:
docker build -t naemon/docs .
$(DOCKERRUN) npm run docs:build

docker-server:
docker build -t naemon/docs .
$(DOCKERRUN)
3 changes: 0 additions & 3 deletions legacy/Gemfile

This file was deleted.

33 changes: 0 additions & 33 deletions legacy/Makefile

This file was deleted.

Binary file removed legacy/favicon.ico
Binary file not shown.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "naemon-docs",
"private": true,
"version": "0.0.0",
"devDependencies": {
"vitepress": "^1.5.0"
},
"scripts": {
"docs:dev": "vitepress dev --host",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
"docs:dev": "npx vitepress dev --host",
"docs:build": "npx vitepress build",
"docs:preview": "npx vitepress preview"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.7.0"
}
}
}

0 comments on commit 434acea

Please sign in to comment.