dockerfile and env var

Add Dockerfile, requirement.txt, and new BUMPER_CERTS env var.
This commit is contained in:
Brian Martin 2019-06-09 20:09:35 -04:00
parent 3f44b33a0a
commit d5db3b696c
3 changed files with 86 additions and 31 deletions

19
Dockerfile Normal file
View 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"]

View file

@ -15,7 +15,6 @@ import socket
import sys import sys
def strtobool(strbool): def strtobool(strbool):
if str(strbool).lower() in ["true", "1", "t", "y", "on", "yes"]: if str(strbool).lower() in ["true", "1", "t", "y", "on", "yes"]:
return True return True
@ -24,23 +23,29 @@ def strtobool(strbool):
# os.environ['PYTHONASYNCIODEBUG'] = '1' # Uncomment to enable ASYNCIODEBUG # os.environ['PYTHONASYNCIODEBUG'] = '1' # Uncomment to enable ASYNCIODEBUG
bumper_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) 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 # Folders
logs_dir = os.environ.get("BUMPER_LOGS") or os.path.join(bumper_dir, "logs") 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 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") 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 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 # Listeners
bumper_listen = os.environ.get("BUMPER_LISTEN") or socket.gethostbyname( 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_address = bumper_listen
xmpp_listen_port = 5223 xmpp_listen_port = 5223
async def start(): async def start():
try: try:
@ -166,7 +172,9 @@ async def start():
) )
global conf_server_2 global conf_server_2
conf_server_2 = ConfServer( 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 global xmpp_server
xmpp_server = XMPPServer((xmpp_listen_address, xmpp_listen_port)) xmpp_server = XMPPServer((xmpp_listen_address, xmpp_listen_port))
@ -438,6 +446,7 @@ class VacBotDevice(object):
"xmpp_connection": self.xmpp_connection, "xmpp_connection": self.xmpp_connection,
} }
class GlobalVacBotDevice(VacBotDevice): # EcoVacs Home class GlobalVacBotDevice(VacBotDevice): # EcoVacs Home
UILogicId = "" UILogicId = ""
ota = True ota = True
@ -944,11 +953,13 @@ API_ERRORS = {
ERR_WRONG_PWD_FROMATE: "1009", ERR_WRONG_PWD_FROMATE: "1009",
} }
def create_certs(): def create_certs():
import platform import platform
import os import os
import subprocess import subprocess
import sys import sys
path = os.path.dirname(sys.modules[__name__].__file__) path = os.path.dirname(sys.modules[__name__].__file__)
path = os.path.join(path, "..") path = os.path.join(path, "..")
sys.path.insert(0, path) sys.path.insert(0, path)
@ -958,9 +969,7 @@ def create_certs():
os.chdir("certs") os.chdir("certs")
if str(platform.system()).lower() == "windows": if str(platform.system()).lower() == "windows":
# run for win # run for win
subprocess.run( subprocess.run([os.path.join("..", "create_certs", "create_certs_windows.exe")])
[os.path.join("..", "create_certs", "create_certs_windows.exe")]
)
elif str(platform.system()).lower() == "darwin": elif str(platform.system()).lower() == "darwin":
# run on mac # run on mac
subprocess.run([os.path.join("..", "create_certs", "create_certs_osx")]) 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")]) subprocess.run([os.path.join("..", "create_certs", "create_certs_rpi")])
else: else:
# run for linux # run for linux
subprocess.run( subprocess.run([os.path.join("..", "create_certs", "create_certs_linux")])
[os.path.join("..", "create_certs", "create_certs_linux")]
)
else: 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 return
print("Certificates created") print("Certificates created")
@ -989,11 +999,13 @@ def create_certs():
else: else:
os.execv(sys.executable, ["python"] + sys.argv) # Start again os.execv(sys.executable, ["python"] + sys.argv) # Start again
def firstrun_input(): def firstrun_input():
return input( return input(
"No certificates found, would you like to create them automatically? (y/n): " "No certificates found, would you like to create them automatically? (y/n): "
).lower() ).lower()
def first_run(): def first_run():
yes = {"yes", "y", "ye", ""} yes = {"yes", "y", "ye", ""}
print("") print("")
@ -1001,10 +1013,15 @@ def first_run():
create_certs() create_certs()
else: 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): def main(argv=None):
import argparse import argparse
global bumper_debug global bumper_debug
global bumper_listen global bumper_listen
global bumper_announce_ip global bumper_announce_ip
@ -1024,7 +1041,10 @@ def main(argv=None):
"--listen", type=str, default=None, help="start serving on address" "--listen", type=str, default=None, help="start serving on address"
) )
parser.add_argument( 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") parser.add_argument("--debug", action="store_true", help="enable debug logs")
args = parser.parse_args(args=argv) args = parser.parse_args(args=argv)

16
requirements.txt Normal file
View 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