dockerfile and env var
Add Dockerfile, requirement.txt, and new BUMPER_CERTS env var.
This commit is contained in:
parent
3f44b33a0a
commit
d5db3b696c
3 changed files with 86 additions and 31 deletions
19
Dockerfile
Normal file
19
Dockerfile
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
FROM python:3.7-alpine as base
|
||||
|
||||
FROM base as builder
|
||||
|
||||
RUN mkdir /install
|
||||
WORKDIR /install
|
||||
|
||||
COPY requirements.txt /requirements.txt
|
||||
|
||||
RUN pip install --install-option="--prefix=/install" -r /requirements.txt
|
||||
|
||||
FROM base
|
||||
|
||||
COPY --from=builder /install /usr/local
|
||||
COPY . /bumper
|
||||
|
||||
WORKDIR /bumper
|
||||
|
||||
ENTRYPOINT ["python3", "-m", "bumper"]
|
||||
|
|
@ -15,7 +15,6 @@ import socket
|
|||
import sys
|
||||
|
||||
|
||||
|
||||
def strtobool(strbool):
|
||||
if str(strbool).lower() in ["true", "1", "t", "y", "on", "yes"]:
|
||||
return True
|
||||
|
|
@ -24,23 +23,29 @@ def strtobool(strbool):
|
|||
|
||||
|
||||
# os.environ['PYTHONASYNCIODEBUG'] = '1' # Uncomment to enable ASYNCIODEBUG
|
||||
|
||||
bumper_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
|
||||
# Set defaults from environment variables first
|
||||
# Certs
|
||||
ca_cert = os.environ.get("BUMPER_CA") or os.path.join(bumper_dir, "certs", "ca.crt")
|
||||
server_cert = os.environ.get("BUMPER_CERT") or os.path.join(
|
||||
bumper_dir, "certs", "bumper.crt"
|
||||
)
|
||||
server_key = os.environ.get("BUMPER_KEY") or os.path.join(
|
||||
bumper_dir, "certs", "bumper.key"
|
||||
)
|
||||
|
||||
# Set defaults from environment variables first
|
||||
print(bumper_dir)
|
||||
# Folders
|
||||
logs_dir = os.environ.get("BUMPER_LOGS") or os.path.join(bumper_dir, "logs")
|
||||
os.makedirs(logs_dir, exist_ok=True) # Ensure logs directory exists or create
|
||||
print(logs_dir)
|
||||
data_dir = os.environ.get("BUMPER_DATA") or os.path.join(bumper_dir, "data")
|
||||
os.makedirs(data_dir, exist_ok=True) # Ensure data directory exists or create
|
||||
print(data_dir)
|
||||
certs_dir = os.environ.get("BUMPER_CERTS") or os.path.join(bumper_dir, "certs")
|
||||
os.makedirs(certs_dir, exist_ok=True) # Ensure data directory exists or create
|
||||
print(certs_dir)
|
||||
|
||||
|
||||
# Certs
|
||||
ca_cert = os.environ.get("BUMPER_CA") or os.path.join(certs_dir, "ca.crt")
|
||||
print(ca_cert)
|
||||
server_cert = os.environ.get("BUMPER_CERT") or os.path.join(certs_dir, "bumper.crt")
|
||||
print(server_cert)
|
||||
server_key = os.environ.get("BUMPER_KEY") or os.path.join(certs_dir, "bumper.key")
|
||||
print(server_key)
|
||||
|
||||
# Listeners
|
||||
bumper_listen = os.environ.get("BUMPER_LISTEN") or socket.gethostbyname(
|
||||
|
|
@ -123,6 +128,7 @@ conf2_listen_port = 8007
|
|||
xmpp_listen_address = bumper_listen
|
||||
xmpp_listen_port = 5223
|
||||
|
||||
|
||||
async def start():
|
||||
|
||||
try:
|
||||
|
|
@ -166,7 +172,9 @@ async def start():
|
|||
)
|
||||
global conf_server_2
|
||||
conf_server_2 = ConfServer(
|
||||
(conf2_listen_address, conf2_listen_port), usessl=False, helperbot=mqtt_helperbot
|
||||
(conf2_listen_address, conf2_listen_port),
|
||||
usessl=False,
|
||||
helperbot=mqtt_helperbot,
|
||||
)
|
||||
global xmpp_server
|
||||
xmpp_server = XMPPServer((xmpp_listen_address, xmpp_listen_port))
|
||||
|
|
@ -438,6 +446,7 @@ class VacBotDevice(object):
|
|||
"xmpp_connection": self.xmpp_connection,
|
||||
}
|
||||
|
||||
|
||||
class GlobalVacBotDevice(VacBotDevice): # EcoVacs Home
|
||||
UILogicId = ""
|
||||
ota = True
|
||||
|
|
@ -944,11 +953,13 @@ API_ERRORS = {
|
|||
ERR_WRONG_PWD_FROMATE: "1009",
|
||||
}
|
||||
|
||||
|
||||
def create_certs():
|
||||
import platform
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
path = os.path.dirname(sys.modules[__name__].__file__)
|
||||
path = os.path.join(path, "..")
|
||||
sys.path.insert(0, path)
|
||||
|
|
@ -958,9 +969,7 @@ def create_certs():
|
|||
os.chdir("certs")
|
||||
if str(platform.system()).lower() == "windows":
|
||||
# run for win
|
||||
subprocess.run(
|
||||
[os.path.join("..", "create_certs", "create_certs_windows.exe")]
|
||||
)
|
||||
subprocess.run([os.path.join("..", "create_certs", "create_certs_windows.exe")])
|
||||
elif str(platform.system()).lower() == "darwin":
|
||||
# run on mac
|
||||
subprocess.run([os.path.join("..", "create_certs", "create_certs_osx")])
|
||||
|
|
@ -970,12 +979,13 @@ def create_certs():
|
|||
subprocess.run([os.path.join("..", "create_certs", "create_certs_rpi")])
|
||||
else:
|
||||
# run for linux
|
||||
subprocess.run(
|
||||
[os.path.join("..", "create_certs", "create_certs_linux")]
|
||||
)
|
||||
subprocess.run([os.path.join("..", "create_certs", "create_certs_linux")])
|
||||
|
||||
else:
|
||||
logging.log(logging.FATAL, "Can't determine platform. Create certs manually and try again.")
|
||||
logging.log(
|
||||
logging.FATAL,
|
||||
"Can't determine platform. Create certs manually and try again.",
|
||||
)
|
||||
return
|
||||
|
||||
print("Certificates created")
|
||||
|
|
@ -989,11 +999,13 @@ def create_certs():
|
|||
else:
|
||||
os.execv(sys.executable, ["python"] + sys.argv) # Start again
|
||||
|
||||
|
||||
def firstrun_input():
|
||||
return input(
|
||||
"No certificates found, would you like to create them automatically? (y/n): "
|
||||
).lower()
|
||||
|
||||
|
||||
def first_run():
|
||||
yes = {"yes", "y", "ye", ""}
|
||||
print("")
|
||||
|
|
@ -1001,10 +1013,15 @@ def first_run():
|
|||
create_certs()
|
||||
|
||||
else:
|
||||
logging.log(logging.FATAL, "Can't continue without certificates, please create some then try again.")
|
||||
logging.log(
|
||||
logging.FATAL,
|
||||
"Can't continue without certificates, please create some then try again.",
|
||||
)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
import argparse
|
||||
|
||||
global bumper_debug
|
||||
global bumper_listen
|
||||
global bumper_announce_ip
|
||||
|
|
@ -1024,7 +1041,10 @@ def main(argv=None):
|
|||
"--listen", type=str, default=None, help="start serving on address"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--announce", type=str, default=None, help="announce address to bots on checkin"
|
||||
"--announce",
|
||||
type=str,
|
||||
default=None,
|
||||
help="announce address to bots on checkin",
|
||||
)
|
||||
parser.add_argument("--debug", action="store_true", help="enable debug logs")
|
||||
args = parser.parse_args(args=argv)
|
||||
|
|
|
|||
16
requirements.txt
Normal file
16
requirements.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-i https://pypi.python.org/simple
|
||||
aiohttp==4.0.0a0
|
||||
async-timeout==3.0.1
|
||||
attrs==19.1.0
|
||||
chardet==3.0.4
|
||||
docopt==0.6.2
|
||||
hbmqtt==0.9.5
|
||||
idna==2.8
|
||||
multidict==4.5.2
|
||||
passlib==1.7.1
|
||||
pyyaml==5.1.1
|
||||
six==1.12.0
|
||||
tinydb==3.13.0
|
||||
transitions==0.6.9
|
||||
websockets==7.0
|
||||
yarl==1.3.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue