dockerize

This commit is contained in:
dave 2019-04-07 14:46:47 -07:00
parent ed645ac002
commit 1c56f09ddb
17 changed files with 98 additions and 33 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
/iso_raws/*
/isos/ubuntu-*
*.iso
/testenv

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.DS_Store
*.iso
/isos/ubuntu-*
/isoserver.egg-info/
/testenv/
__pycache__

12
Dockerfile Normal file
View File

@ -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"]

View File

@ -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`

1
iso_raws/.gitignore vendored
View File

@ -1 +0,0 @@
*

View File

@ -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

View File

@ -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()

View File

@ -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

20
setup.py Normal file
View File

@ -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)