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

Dockerfile: remove node runtime #283

Open
wants to merge 8 commits into
base: dev3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ GivTCP/startup.sh
*.pkl
.forceFullRefresh
test.txt
.git
.vscode
Dockerfile
WebDashboard/graphics

# WebDashboard is a static site - node is not required
# except as a helper to serve the site for development
WebDashboard/package*
26 changes: 17 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# givtcp-vuejs builder
FROM node:21-alpine AS givtcp_vuejs_tmp

# set the working directory in the container
WORKDIR /app

# Copy file dependencies in a single layer
COPY givtcp-vuejs .

RUN npm install && \
npm run build && \
mv dist/index.html dist/config.html

# set base image (host OS)
#FROM python:3.11-rc-alpine
FROM python:alpine3.19

RUN apk add mosquitto
RUN apk add npm
RUN apk add git
RUN apk add tzdata
RUN apk add musl
Expand All @@ -12,7 +24,6 @@ RUN apk add redis
RUN apk add nginx

RUN mkdir -p /run/nginx
RUN npm install -g serve

# set the working directory in the container
WORKDIR /app
Expand All @@ -21,12 +32,6 @@ WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY givtcp-vuejs/package.json /app/ingress/package.json

RUN cd /app/ingress && npm install
COPY givtcp-vuejs ./ingress
RUN cd /app/ingress && npm run build && mv dist/index.html dist/config.html && cp -a dist/. /app/ingress/

COPY ingress.conf /etc/nginx/http.d/
COPY ingress_no_ssl.conf /app/ingress_no_ssl.conf
RUN rm /etc/nginx/http.d/default.conf
Expand All @@ -43,6 +48,9 @@ COPY redis.conf redis.conf
COPY settings.json ./settings.json
COPY ingress/ ./ingress

EXPOSE 1883 6379 8099
# Copy static site files
COPY --from=givtcp_vuejs_tmp /app/dist /app/ingress/

EXPOSE 1883 3000 6379 8099

CMD ["python3", "/app/startup.py"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ GivTCP can auto-discover devices on the network for a (near) zero config setup

Typically run through the Home Assistant Addon, it is also possible to run as a standalone docker container.

<a href="https://www.buymeacoffee.com/givtcp" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

## Quick Set-up

### Install GivTCP
Expand Down
2 changes: 1 addition & 1 deletion WebDashboard
47 changes: 24 additions & 23 deletions startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def createsettingsjson(inv):
outp.write(" first_run_evc= True\n")
outp.write(" self_run_timer="+str(setts["self_run_timer"])+"\n")
outp.write(" self_run_timer_full="+str(setts["self_run_timer_full"])+"\n")
outp.write(" queue_retries="+str(setts["queue_retries"])+"\n")
outp.write(" queue_retries="+str(setts["queue_retries"])+"\n")
outp.write(" givtcp_instance="+str(inv)+"\n")
outp.write(" default_path=\""+str(PATH)+"\"\n")
outp.write(" dynamic_tariff="+str(setts["dynamic_tariff"]).capitalize()+"\n")
Expand Down Expand Up @@ -286,24 +286,24 @@ def findinv(networks):
hasMQTT=False
logger.info("No HA MQTT service has been found. Install and run the Mosquitto addon, or manually configure your own MQTT broker.")

#Get Timezone
#Get Timezone
url="http://supervisor/info"
result = requests.get(url,
headers={'Content-Type':'application/json',
'Authorization': 'Bearer {}'.format(access_token)})
info=result.json()
SuperTimezone=info['data']['timezone']
logger.debug("Supervisor Timezone: "+str(SuperTimezone))
#Get addonslug/ingress url

#Get addonslug/ingress url
url="http://supervisor/addons/self/info"
result = requests.get(url,
headers={'Content-Type':'application/json',
'Authorization': 'Bearer {}'.format(access_token)})
baseurl=result.json()['data']['ingress_url']
logger.debug("Ingress URL is: "+str(baseurl))

#Get Host Details
#Get Host Details
url="http://supervisor/network/info"
result = requests.get(url,
headers={'Content-Type':'application/json',
Expand Down Expand Up @@ -352,8 +352,8 @@ def findinv(networks):
logger.info("Searching for Inverters")
finv=findinv(networks)
i=i+1
if i==3:
break
if i==3:
break
inverterStats=finv[0]
invList=finv[1]
evcList=finv[2]
Expand Down Expand Up @@ -436,7 +436,7 @@ def findinv(networks):
setts["invertorIP_"+str(num)]=inverterStats[inv]['IP_Address']
break
setts['Model_'+str(inv)]=inverterStats[inv]['Model'].name.capitalize()


if len(evcList)>0:
logger.debug("evcList: "+str(evcList))
Expand Down Expand Up @@ -540,7 +540,7 @@ def findinv(networks):
os.remove(firstrun)

createsettingsjson(inv)

######
# Always delete lockfiles and FCRunning etc... but only delete pkl if too old?
for file in os.listdir(setts["cache_location"]):
Expand Down Expand Up @@ -585,7 +585,7 @@ def findinv(networks):
logger.info ("Running Invertor "+str(inv)+" ("+str(setts["serial_number_"+str(inv)])+") read loop every "+str(setts['self_run_timer'])+"/"+str(setts['self_run_timer_full'])+"s")
selfRun[inv]=subprocess.Popen(["/usr/local/bin/python3",PATH+"/read.py", "start"])


GUPORT=6344+inv
logger.debug ("Starting Gunicorn on port "+str(GUPORT))
command=shlex.split("/usr/local/bin/gunicorn -w 3 -b :"+str(GUPORT)+" REST:giv_api")
Expand Down Expand Up @@ -623,10 +623,21 @@ def findinv(networks):
outp.write(" \"solarRate\": "+str(setts['day_rate'])+",\n")
outp.write(" \"exportRate\": "+str(setts['export_rate'])+"\n")
outp.write("}")

WDPORT=int(setts['Web_Dash_Port'])
logger.info ("Serving Web Dashboard from port "+str(WDPORT))
command=shlex.split("/usr/bin/node /usr/local/bin/serve -p "+ str(WDPORT))
webDash=subprocess.Popen(command)
logger.info (f"Serving Web Dashboard from port {WDPORT}")
with open("/etc/nginx/http.d/webdashboard.conf", 'w') as wd:
wd.write("server {\n")
wd.write(f"\tlisten {WDPORT};\n")
wd.write("\tlocation / {\n")
wd.write("\t\troot /app/WebDashboard;\n")
wd.write("\t\tindex index.html;\n\n")
wd.write("\t\ttry_files $uri $uri/ =404;\n")
wd.write("\t}\n")
wd.write("}\n")

# reload nginx to pick up the new conf
subprocess.Popen(["nginx","-s","reload", "-c", "/etc/nginx/nginx.conf"])


if setts['Smart_Target']==True:
Expand Down Expand Up @@ -670,16 +681,6 @@ def findinv(networks):
logger.info ("Starting Gunicorn on port "+str(GUPORT))
command=shlex.split("/usr/local/bin/gunicorn -w 3 -b :"+str(GUPORT)+" REST:giv_api")
gunicorn[inv]=subprocess.Popen(command)

if setts['Web_Dash'] == True:
if not webDash.poll() == None:
webDash.kill()
logger.error("Web Dashboard process died. Restarting...")
os.chdir("/app/WebDashboard")
WDPORT = int(setts['Web_Dash_Port'])
logger.info("Serving Web Dashboard from port " + str(WDPORT))
command = shlex.split("/usr/bin/node /usr/local/bin/serve -p " + str(WDPORT))
webDash = subprocess.Popen(command)

if setts['MQTT_Address']=="127.0.0.1":
if not mqttBroker.poll()==None:
Expand Down