From 1c56f09ddb6a025d03c7e06ebe686118400c0a57 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 7 Apr 2019 14:46:47 -0700 Subject: [PATCH] dockerize --- .dockerignore | 4 ++ .gitignore | 6 ++ Dockerfile | 12 ++++ README.md | 8 +++ iso_raws/.gitignore | 1 - {samples => isos/samples}/default/info.txt | 0 {samples => isos/samples}/default/ks.default | 0 .../samples}/default/menu.default | 0 .../samples}/default/seed.default | 0 {samples => isos/samples}/lvm/info.txt | 0 {samples => isos/samples}/lvm/ks.default | 2 +- {samples => isos/samples}/lvm/menu.default | 0 {samples => isos/samples}/lvm/seed.default | 0 main.py => isoserver/__init__.py | 64 +++++++++++-------- main.html => isoserver/main.html | 0 requirements.txt | 14 ++-- setup.py | 20 ++++++ 17 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile delete mode 100644 iso_raws/.gitignore rename {samples => isos/samples}/default/info.txt (100%) rename {samples => isos/samples}/default/ks.default (100%) rename {samples => isos/samples}/default/menu.default (100%) rename {samples => isos/samples}/default/seed.default (100%) rename {samples => isos/samples}/lvm/info.txt (100%) rename {samples => isos/samples}/lvm/ks.default (98%) rename {samples => isos/samples}/lvm/menu.default (100%) rename {samples => isos/samples}/lvm/seed.default (100%) rename main.py => isoserver/__init__.py (75%) rename main.html => isoserver/main.html (100%) create mode 100644 setup.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..03f99a3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +/iso_raws/* +/isos/ubuntu-* +*.iso +/testenv diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..733e426 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +*.iso +/isos/ubuntu-* +/isoserver.egg-info/ +/testenv/ +__pycache__ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e6cd3f5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:bionic + +RUN apt-get update && apt-get install -y python3-pip bsdtar genisoimage + +ADD . /tmp/code + +RUN cd /tmp/code && \ + pip3 install -r requirements.txt && \ + python3 setup.py install && \ + mkdir /data + +ENTRYPOINT ["isoserverd"] diff --git a/README.md b/README.md index c4c77c4..b1853d2 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,11 @@ Installing the `system-config-kickstart` provides a tool for generating Kickstar apt-get install system-config-kickstart system-config-kickstart ``` + + +Docker +------ + +Run the image like: + +* `docker run -it --rm -e PORT=8080 -v /host/iso_raws:/data kickstart` diff --git a/iso_raws/.gitignore b/iso_raws/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/iso_raws/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/samples/default/info.txt b/isos/samples/default/info.txt similarity index 100% rename from samples/default/info.txt rename to isos/samples/default/info.txt diff --git a/samples/default/ks.default b/isos/samples/default/ks.default similarity index 100% rename from samples/default/ks.default rename to isos/samples/default/ks.default diff --git a/samples/default/menu.default b/isos/samples/default/menu.default similarity index 100% rename from samples/default/menu.default rename to isos/samples/default/menu.default diff --git a/samples/default/seed.default b/isos/samples/default/seed.default similarity index 100% rename from samples/default/seed.default rename to isos/samples/default/seed.default diff --git a/samples/lvm/info.txt b/isos/samples/lvm/info.txt similarity index 100% rename from samples/lvm/info.txt rename to isos/samples/lvm/info.txt diff --git a/samples/lvm/ks.default b/isos/samples/lvm/ks.default similarity index 98% rename from samples/lvm/ks.default rename to isos/samples/lvm/ks.default index dca9737..2578671 100644 --- a/samples/lvm/ks.default +++ b/isos/samples/lvm/ks.default @@ -79,7 +79,7 @@ set +x sed -i -E "s/^#?PermitRootLogin .+/PermitRootLogin yes/" /etc/ssh/sshd_config apt-get update apt-get dist-upgrade -y -apt-get install -y open-vm-tools +apt-get install -y open-vm-tools dirmngr rm /etc/firstboot reboot EOF diff --git a/samples/lvm/menu.default b/isos/samples/lvm/menu.default similarity index 100% rename from samples/lvm/menu.default rename to isos/samples/lvm/menu.default diff --git a/samples/lvm/seed.default b/isos/samples/lvm/seed.default similarity index 100% rename from samples/lvm/seed.default rename to isos/samples/lvm/seed.default diff --git a/main.py b/isoserver/__init__.py similarity index 75% rename from main.py rename to isoserver/__init__.py index 095143d..e8944ab 100755 --- a/main.py +++ b/isoserver/__init__.py @@ -7,31 +7,41 @@ from threading import Semaphore import os +APPROOT = os.path.abspath(os.path.join(os.path.dirname(__file__))) + + class ISOserver(object): - def __init__(self): - self.data_dir = "./iso_raws" - self.iso_selection = [i for i in os.listdir(self.data_dir) if not i.startswith(".")] + def __init__(self, isodir): + self.data_dir = isodir + self.iso_selection = [i for i in os.listdir(self.data_dir) if not any([i.startswith("."), i == "samples"])] + if not self.iso_selection: + raise Exception("No base isos found in path {}".format(self.data_dir)) + self.builder_semaphores = {i: Semaphore() for i in self.iso_selection} self._load_templates() def _load_templates(self): - with open("./main.html") as template_f: + with open(os.path.join(APPROOT, "main.html")) as template_f: self.template = Environment(autoescape=True).from_string(template_f.read()) - samples = os.listdir("samples") + basedir = os.path.join(self.data_dir, "samples") + os.makedirs(basedir, exist_ok=True) + samples = os.listdir(basedir) + if not samples: + raise Exception("No templates found in path {}".format(basedir)) self.samples = {} for item in samples: self.samples[item] = {} - with open(os.path.join("samples", item, "menu.default")) as f: + with open(os.path.join(basedir, item, "menu.default")) as f: self.samples[item]["MENU_ENTRIES"] = f.read() - with open(os.path.join("samples", item, "seed.default")) as f: + with open(os.path.join(basedir, item, "seed.default")) as f: self.samples[item]["SEED_CONTENT"] = f.read() - with open(os.path.join("samples", item, "ks.default")) as f: + with open(os.path.join(basedir, item, "ks.default")) as f: self.samples[item]["KS_CONTENT"] = f.read() - info_path = os.path.join("samples", item, "info.txt") + info_path = os.path.join(basedir, item, "info.txt") if os.path.exists(info_path): - with open(os.path.join("samples", item, "info.txt")) as f: + with open(os.path.join(basedir, item, "info.txt")) as f: self.samples[item]["SAMPLE_INFO"] = f.read() @cherrypy.expose @@ -115,26 +125,28 @@ class ISOserver(object): return output -if __name__ == '__main__': +def main(): + from argparse import ArgumentParser + import logging + logging.basicConfig(level=logging.DEBUG) + parser = ArgumentParser() + parser.add_argument("-p", "--port", help="listen port", default=int(os.environ.get("PORT", 8087))) + parser.add_argument("-d", "--data", help="iso data folder", default=os.environ.get("DATADIR", "/data")) + args = parser.parse_args() + + cherrypy.tree.mount(ISOserver(args.data), '/', config={}) cherrypy.config.update({ - 'engine.autoreload_on': False, - 'tools.sessions.on': False, - 'tools.sessions.storage_type': 'ram', # 'file', - 'tools.sessions.timeout': 525600, - 'server.show.tracebacks': True, - 'server.socket_port': 8087, - 'server.thread_pool': 10, + 'environment': 'production', 'server.socket_host': '0.0.0.0', - # 'tools.sessions.storage_path': './sessions/', - 'tools.sessions.locking': 'explicit' # cherrypy.session.acquire_lock() cherrypy.session.release_lock() + 'server.socket_port': args.port, + 'tools.sessions.on': False, + 'server.thread_pool': 10, }) - cherrypy.tree.mount(ISOserver(), '/', config={ - '/': {}, - '/static': { # 'tools.staticdir.on': True, - # 'tools.staticdir.dir': ./static/" - } - }) cherrypy.engine.start() cherrypy.engine.block() + + +if __name__ == '__main__': + main() diff --git a/main.html b/isoserver/main.html similarity index 100% rename from main.html rename to isoserver/main.html diff --git a/requirements.txt b/requirements.txt index e2adc50..6a17061 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,15 @@ appdirs==1.4.3 -cheroot==5.5.0 -CherryPy==10.2.2 +backports.functools-lru-cache==1.5 +cheroot==6.5.4 +CherryPy==18.1.1 +jaraco.functools==2.0 Jinja2==2.9.6 MarkupSafe==1.0 +more-itertools==7.0.0 packaging==16.8 -portend==1.8 +portend==2.4 pyparsing==2.2.0 pytz==2017.2 -six==1.10.0 -tempora==1.7 +six==1.12.0 +tempora==1.14 +zc.lockfile==1.4 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f653389 --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +from setuptools import setup + +__version__ = "0.0.1" + +setup(name='isoserver', + version=__version__, + description='', + url='http://git.davepedu.com/dave/kickstart-builder', + author='dpedu', + author_email='dave@davepedu.com', + packages=['isoserver'], + entry_points={ + "console_scripts": [ + "isoserverd = isoserver:main" + ] + }, + include_package_data=True, + package_data={'isoserver': ['main.html']}, + zip_safe=False)