character-sheet-app icon indicating copy to clipboard operation
character-sheet-app copied to clipboard

Add support for docker

Open LeoColman opened this issue 3 years ago • 12 comments

Quick docker command

As an user, it would be interesting to have a quick docker command to setup an instance of character-sheet-app, something like

docker run derikb/character-sheet-app -p MyPort:8080

Docker compose file

In the long term, it would also be interesting to setup a local database, using another docker to set that up and add to the documentation. We can create this in a new ticket if it's interesting

LeoColman avatar May 11 '22 14:05 LeoColman

@LeoColman My knowledge of docker extends no further than knowing what it is. I'm not against the idea, but I also don't now how to do it. I'd be happy to take a PR (and instructions for testing).

Supporting a local database is probably more complicated... would have to update the code to allow for setting different db targets and then handling different types of db interfaces/apis.

derikb avatar May 11 '22 14:05 derikb

Here's a barebones dockerfile that runs the webserver with no database or anything. I don't think the node version is right because it complains about the package-lock.json version but it does run the server locally.

To build: docker build -t character-sheet-app . To run: sudo docker run -it character-sheet-app

FROM node:18-alpine
WORKDIR /app
COPY . .

RUN npm install

CMD ["npm", "run", "start"]
EXPOSE 8080

kyledhardison avatar May 13 '22 19:05 kyledhardison

Will try to find some time to look into this further. I've been told I should learn docker for my job, so I guess this will be a good learning experience.

The node/npm thing is because my local is still on... 14 because of work, so the npm lock file is the old version. Working on getting that updated soon, so that issue should go away maybe next time I rerun and npm update/install.

derikb avatar Jun 12 '22 15:06 derikb

Starting working on this. Did work out a non-database docker that basically just uses nginx to serve the files in ./dist.

Working on a dev one next that will live update from the local files when you change them.

Then maybe I'll look into an sqlite option in lieu of the firebase db, so that one could run the container with a database backend.

derikb avatar Jul 11 '22 12:07 derikb

Also I updated my local node/npm so the latest release has a package-lock that's compatible with node 16/18 now.

derikb avatar Jul 11 '22 13:07 derikb

Just stumbled onto this. Love the project! I just used this container https://hub.docker.com/r/danjellz/http-server and pointed ./dist at the /public folder in the container. worked like a charm. I'm also interested in the local database option. sqlite would be ideal for the backend. Unfortunately i'm not good with node, or i would contribute a pr...

lambchop01 avatar Feb 08 '23 21:02 lambchop01

Just an idea.. Rather than re coding to use a local database, how hard would it be to use the backup/restore feature to save to the ./dist/ folder? Then have it restore from the latest backup upon loading the page.

lambchop01 avatar Feb 10 '23 16:02 lambchop01

@lambchop01 Yeah making the backup/restore to/from file a little more automated could work in a docker system if you had a node backend to handle the save to the file system. Not sure if that is any more longterm secure than just saving to the localstorage though there would still be opportunities for the data to get deleted unexpectedly, I think (maybe not if you had docker linked up to an external directory on the harddrive (iirc that's possible with Docker). Really nothing I'm doing with the current firebase database is any more complicated that listing/retrieving/saving blobs of JSON, so switching to an file interface wouldn't require a ton of changes other than swapping out the firebase stuff for some other service.

I guess you could get multi-computer usage out of that if you linked the docker to a directory that synced between devices (something in Dropbox or another such service (I use SpiderOak for instance to sync between machines).

Bonus in that making all this easy to setup would be less maintenance for me as far as having the firebase to worry about as far as usage and security.

derikb avatar Feb 20 '23 14:02 derikb

on writing data from docker container to host directory: https://www.digitalocean.com/community/tutorials/how-to-share-data-between-the-docker-container-and-the-host

Think that could be used to write JSON "backup" type data to the local machine. Could do each character as a separate file based on the key.

derikb avatar Feb 27 '23 23:02 derikb

@derikb sorry, I thought I'd replied to your lasst comment! Yes, that would work! That was exactly what I was thinking.

To expand on @kyledhardison 's barebones dockerfile, I would add a Volume and then add the volume to the run command (It has been a while since i've made a dockerfile, might have to double check it is right)

FROM node:18-alpine
WORKDIR /app
COPY . .

RUN npm install

VOLUME /app

CMD ["npm", "run", "start"]
EXPOSE 8080

To build: docker build -t character-sheet-app . To run: sudo docker run -it -v ./data:/app character-sheet-app This creates a directory ./data if not already created and binds it to directory /app in the container.

lambchop01 avatar Feb 27 '23 23:02 lambchop01

https://github.com/typicode/lowdb might be a simple way to do storage in node for a docker run package. would need to generate a pretty simple server side... but if its local use only one can ignore a lot of the more complicated aspects (security, auth, perms, etc.).

derikb avatar Jun 29 '24 20:06 derikb

maybe https://fastify.dev/docs/latest/Guides/Getting-Started/ to work up a quick simple server in node

derikb avatar Jul 02 '24 12:07 derikb