Browse Source

dockerize

master
dave 3 years ago
parent
commit
1c56f09ddb
  1. 4
      .dockerignore
  2. 6
      .gitignore
  3. 12
      Dockerfile
  4. 8
      README.md
  5. 1
      iso_raws/.gitignore
  6. 0
      isos/samples/default/info.txt
  7. 0
      isos/samples/default/ks.default
  8. 0
      isos/samples/default/menu.default
  9. 0
      isos/samples/default/seed.default
  10. 0
      isos/samples/lvm/info.txt
  11. 2
      isos/samples/lvm/ks.default
  12. 0
      isos/samples/lvm/menu.default
  13. 0
      isos/samples/lvm/seed.default
  14. 62
      isoserver/__init__.py
  15. 0
      isoserver/main.html
  16. 14
      requirements.txt
  17. 20
      setup.py

4
.dockerignore

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

6
.gitignore

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

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

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

1
iso_raws/.gitignore

@ -1 +0,0 @@
*

0
samples/default/info.txt → isos/samples/default/info.txt

0
samples/default/ks.default → isos/samples/default/ks.default

0
samples/default/menu.default → isos/samples/default/menu.default

0
samples/default/seed.default → isos/samples/default/seed.default

0
samples/lvm/info.txt → isos/samples/lvm/info.txt

2
samples/lvm/ks.default → 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

0
samples/lvm/menu.default → isos/samples/lvm/menu.default

0
samples/lvm/seed.default → isos/samples/lvm/seed.default

62
main.py → 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,
'environment': 'production',
'server.socket_host': '0.0.0.0',
'server.socket_port': args.port,
'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,
'server.socket_host': '0.0.0.0',
# 'tools.sessions.storage_path': './sessions/',
'tools.sessions.locking': 'explicit' # cherrypy.session.acquire_lock() cherrypy.session.release_lock()
})
cherrypy.tree.mount(ISOserver(), '/', config={
'/': {},
'/static': { # 'tools.staticdir.on': True,
# 'tools.staticdir.dir': ./static/"
}
})
cherrypy.engine.start()
cherrypy.engine.block()
if __name__ == '__main__':
main()

0
main.html → isoserver/main.html

14
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

20
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)
Loading…
Cancel
Save