Bugfix: mqtt wont connect #1
Improvement: Add Dockerfile #2, compose, License, github workflow
This commit is contained in:
parent
6d7eada993
commit
a3ce01a90f
45
.github/workflows/docker-publish.yml
vendored
Normal file
45
.github/workflows/docker-publish.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
name: Build image & push
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
# Step 1: Check out the repository
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Step 2: Extract version from __version__.py
|
||||
- name: Extract version
|
||||
run: |
|
||||
VERSION=$(python -c "exec(open('__version__.py').read()); print(__version__)")
|
||||
echo "Version is $VERSION"
|
||||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||||
|
||||
# Step 3: Log in to GitHub Container Registry
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Step 4: Build the Docker image
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build -t ghcr.io/${{ github.repository }}:${{ env.VERSION }} .
|
||||
|
||||
# Step 5: Push the Docker image to GHCR
|
||||
- name: Push Docker image
|
||||
run: |
|
||||
docker push ghcr.io/${{ github.repository }}:${{ env.VERSION }}
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -130,3 +130,5 @@ cython_debug/
|
||||
|
||||
# IDE files
|
||||
.idea/
|
||||
|
||||
config.env
|
||||
|
27
Dockerfile
Normal file
27
Dockerfile
Normal file
@ -0,0 +1,27 @@
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM python:3.11-slim-buster
|
||||
|
||||
# permissions and nonroot user for tightened security
|
||||
RUN adduser --disabled-login nonroot
|
||||
RUN mkdir /home/app/ && chown -R nonroot:nonroot /home/app
|
||||
RUN mkdir -p /var/log/flask-app && touch /var/log/flask-app/flask-app.err.log && touch /var/log/flask-app/flask-app.out.log
|
||||
RUN chown -R nonroot:nonroot /var/log/flask-app
|
||||
WORKDIR /home/app
|
||||
USER nonroot
|
||||
|
||||
# copy all the files to the container
|
||||
COPY --chown=nonroot:nonroot . .
|
||||
|
||||
# venv
|
||||
ENV VIRTUAL_ENV=/home/app/venv
|
||||
|
||||
# python setup
|
||||
RUN python -m venv $VIRTUAL_ENV
|
||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||
RUN export FLASK_APP=src/app.py
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# define the port number the container should expose
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "app:app"]
|
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Filip Bednárik
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -48,6 +48,6 @@ TBD:
|
||||
- Filament spending based on printing
|
||||
- Evidently needed GUI improvements
|
||||
- Code cleanup
|
||||
- Deployment as Docker and Helm chart
|
||||
- Deployment as Helm chart
|
||||
- Video showcase
|
||||
- TODOs
|
||||
|
1
__version__.py
Normal file
1
__version__.py
Normal file
@ -0,0 +1 @@
|
||||
__version__ = '0.0.1'
|
6
compose.yaml
Normal file
6
compose.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
services:
|
||||
openspoolman:
|
||||
build: .
|
||||
env_file: "config.env"
|
||||
ports:
|
||||
- "8000:8000"
|
5
config.env.template
Normal file
5
config.env.template
Normal file
@ -0,0 +1,5 @@
|
||||
OPENSPOOLMAN_BASE_URL=
|
||||
PRINTER_ACCESS_CODE=
|
||||
PRINTER_ID=
|
||||
PRINTER_IP=
|
||||
SPOOLMAN_BASE_URL=
|
@ -9,6 +9,9 @@ from config import PRINTER_ID, PRINTER_CODE, PRINTER_IP
|
||||
from messages import GET_VERSION, PUSH_ALL
|
||||
from spoolman_client import fetchSpoolList, patchExtraTags
|
||||
|
||||
MQTT_CLIENT = {} # Global variable storing MQTT Client
|
||||
LAST_AMS_CONFIG = {} # Global variable storing last AMS configuration
|
||||
|
||||
|
||||
def num2letter(num):
|
||||
return chr(ord("A") + int(num))
|
||||
@ -82,7 +85,8 @@ def setActiveTray(spool_id, spool_extra, ams_id, tray_id):
|
||||
if spool_extra == None:
|
||||
spool_extra = {}
|
||||
|
||||
if not spool_extra.get("active_tray") or spool_extra.get("active_tray") != json.dumps(f"{PRINTER_ID}_{ams_id}_{tray_id}"):
|
||||
if not spool_extra.get("active_tray") or spool_extra.get("active_tray") != json.dumps(
|
||||
f"{PRINTER_ID}_{ams_id}_{tray_id}"):
|
||||
patchExtraTags(spool_id, spool_extra, {
|
||||
"active_tray": json.dumps(f"{PRINTER_ID}_{ams_id}_{tray_id}"),
|
||||
})
|
||||
@ -133,6 +137,4 @@ def getMqttClient():
|
||||
return MQTT_CLIENT
|
||||
|
||||
|
||||
MQTT_CLIENT = {} # Global variable storing MQTT Client
|
||||
LAST_AMS_CONFIG = {} # Global variable storing last AMS configuration
|
||||
SPOOLS = fetchSpools() # Global variable storing latest spool from spoolman
|
||||
|
@ -2,3 +2,4 @@ paho-mqtt==2.1.0
|
||||
requests==2.32.3
|
||||
flask==3.1.0
|
||||
pyopenssl==24.3.0
|
||||
gunicorn==23.0.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user