fredli74 / smartcharge-dev

Smart charging system for EVs
https://smartcharge.dev
MIT License
18 stars 4 forks source link

Docker support? #837

Open tfsjohan opened 2 years ago

tfsjohan commented 2 years ago

Any plans to add a docker-compose file to simplify installation locally, like on a raspberry pi?

fredli74 commented 2 years ago

It's a good idea.

Unfortunately, I have no experience with either creating my own docker containers or Raspberry pi. I'll keep this issue open for now.

tfsjohan commented 2 years ago

What kind of setup are you using today?

Skickat från min iPhone

12 jan. 2022 kl. 03:13 skrev Fredrik Lidström @.***>:

 It's a good idea.

Unfortunately, I have no experience with either creating my own docker containers or Raspberry pi. I'll keep this issue open for now.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

fredli74 commented 2 years ago

The public server is hosted on Heroku. I would guess that creating a Docker container for this project should be pretty straightforward. It's basically three parts, that could possibly all be run in the same container for personal usage.

  1. node.js webserver
  2. node.js worker service
  3. PostgreSQL database

It does already create and populate the database automatically if it connects and the scserver schema does not exist.

galonias commented 2 years ago

This was fairly easy to do a quick and dirty docker image out of.

Once I managed to figure out the database creation and the token extraction (might be easier with the .env-file creation and the additional step by step in the installation instruction).

  1. Run the installations-steps
  2. Create Dockerfile in the foot folder of smartcharge-dev source:
    
    FROM node:latest

Create app directory

WORKDIR /opt/smartcharge-dev

Install app dependencies

A wildcard is used to ensure both package.json AND package-lock.json are copied

where available (npm@5+)

COPY package*.json ./

RUN npm install

If you are building your code for production

RUN npm ci --only=production

Bundle app source

COPY . .

EXPOSE 3000 ADD start.sh / RUN chmod +x /start.sh

CMD ["/start.sh"]


3. Create start.sh in the root folder of smartcharge-dev source (replace internal_token and http://192.168.0.200:3000 with your ip-adress and exposed port):

!/bin/bash

node /opt/smartcharge-dev/dist/server/server.js & node /opt/smartcharge-dev/dist/server/agency.js -d internal_token http://192.168.0.200:3000


4. Create docker image

docker build . -t galonias/smartcharge-dev

5. Create docker container

docker run --name smartcharge-dev --network smartcharge -p 3000:3000 -d galonias/smartcharge-dev:latest

fredli74 commented 2 years ago

Thanks for this @galonias!

What would be the best practice regarding PostgreSQL? How did you set up yours? Typically it's not recommended to use a Dockerized PostgreSQL for production, but I can imagine that it would be very nice and convenient for personal use. Maybe step-by-step instructions on how to set up a PostgreSQL container beside the smartcharge Docker container would be sufficient? What do you think?

fredli74 commented 2 years ago

although maybe a fully ready-made single-user smartcharge setup with server, worker, and PSQL using docker-compose could be nice in the end

galonias commented 2 years ago

I have a PSQL docker container which I’ve reused for this purpose. I didn’t bother setting up a secondary instance.

Having a dedicated single user in one docker container would be optimal for easy setup. You can probably borrow some inspiration from Teslamate and their docker-compose file, https://docs.teslamate.org/docs/installation/docker

tfsjohan commented 1 year ago

PSQL in a container works perfectly for TeslaMate.

With a good docker-componse file setup is very easy despite having multiple containers.

I think you can get good ideas by looking at the docker setup guide for TeslaMate.

6 sep. 2022 kl. 20:48 skrev galonias @.***>:

I have a PSQL docker container which I’ve reused for this purpose. I didn’t bother setting up a secondary instance.

Having a dedicated single user in one docker container would be optimal for easy setup. You can probably borrow some inspiration from Teslamate and their docker-compose file, https://docs.teslamate.org/docs/installation/docker https://docs.teslamate.org/docs/installation/docker — Reply to this email directly, view it on GitHub https://github.com/fredli74/smartcharge-dev/issues/837#issuecomment-1238527671, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGSBXCUN6ISGYSIRR4LNIDV46GZXANCNFSM5LDUNMOQ. You are receiving this because you authored the thread.

enoch85 commented 1 year ago

Very interested in this app. Docker would be a great addition. Is it still maintained?