refs #597 use docker to create the oglive images
parent
d4564f6ad9
commit
f002c5678a
|
@ -0,0 +1,11 @@
|
|||
.git
|
||||
.gitignore
|
||||
.dockerignore
|
||||
__pycache__
|
||||
Dockerfile
|
||||
INSTALL.es.txt
|
||||
Jenkinsfile
|
||||
kernelParameterOG.es.txt
|
||||
ogclientImg2Sqfs
|
||||
ogclientSqfs2Img
|
||||
*.swp
|
|
@ -0,0 +1,38 @@
|
|||
FROM ubuntu:noble
|
||||
|
||||
ARG OPENGNSYS_BRANCH=main
|
||||
|
||||
RUN apt-get update && apt-get -y install \
|
||||
debootstrap \
|
||||
fdisk \
|
||||
file \
|
||||
genisoimage \
|
||||
git \
|
||||
ipxe \
|
||||
jq \
|
||||
lsof \
|
||||
python3 \
|
||||
python3-apt \
|
||||
qemu-utils \
|
||||
rsync \
|
||||
schroot \
|
||||
squashfs-tools \
|
||||
subversion \
|
||||
syslinux \
|
||||
syslinux-efi \
|
||||
syslinux-utils \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN groupadd opengnsys
|
||||
RUN mkdir -p /opt/opengnsys/client /tmp/opengnsys/oglive_builder /var/lib/tftpboot/
|
||||
RUN ln -fs /var/lib/tftpboot /opt/opengnsys
|
||||
|
||||
## take client stuff from the OG repo
|
||||
RUN git clone -c http.sslVerify=false --branch ${OPENGNSYS_BRANCH} https://ognproject.evlt.uma.es/gitea/opengnsys/opengnsys.git /tmp/ogrepo
|
||||
RUN rsync -aH /tmp/ogrepo/client/engine /tmp/ogrepo/client/shared /tmp/opengnsys/
|
||||
|
||||
RUN echo foo4
|
||||
COPY . /tmp/opengnsys/oglive_builder/
|
||||
RUN cp /tmp/opengnsys/oglive_builder/schroot.conf /tmp/opengnsys/oglive_builder/mount-defaults /etc/schroot/ && echo '' >/etc/schroot/default/nssdatabases && rm -f /etc/schroot/setup.d/*chrootname
|
||||
|
||||
ENTRYPOINT ["/tmp/opengnsys/oglive_builder/mkoglive.py"]
|
|
@ -11,34 +11,6 @@ from . import utils
|
|||
|
||||
logger = logging.getLogger ('boottools')
|
||||
|
||||
schroot_conf_tpl = """
|
||||
[IMGogclient]
|
||||
type=loopback
|
||||
file=/var/lib/tftpboot/ogclient/ogclient.img
|
||||
description=ogclient Ubuntu image
|
||||
#priority=1
|
||||
users=root
|
||||
groups=root
|
||||
root-groups=root
|
||||
mount-options=-o offset=32256
|
||||
root-users=root
|
||||
""".strip()
|
||||
|
||||
mount_defaults_tpl = """
|
||||
# mount.defaults: static file system information for chroots.
|
||||
# Note that the mount point will be prefixed by the chroot path
|
||||
# (CHROOT_PATH)
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
proc /proc proc defaults 0 0
|
||||
#procbususb /proc/bus/usb usbfs defaults 0 0
|
||||
#/dev /dev none rw,bind 0 0
|
||||
/dev/pts /dev/pts none rw,bind 0 0
|
||||
/dev/shm /dev/shm none rw,bind 0 0
|
||||
#/home /home none rw,bind 0 0
|
||||
/tmp /tmp none rw,bind 0 0
|
||||
""".strip()
|
||||
|
||||
def GetVar (osarch):
|
||||
btdir = '/tmp/opengnsys/oglive_builder'
|
||||
bttargetdir = '/var/lib/tftpboot/ogclient/'
|
||||
|
@ -231,28 +203,6 @@ def mkrootfs (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, btt
|
|||
|
||||
logger.info (f'"{btrootfsimg}" "{btvirtualdisksize}" MB : OK')
|
||||
|
||||
#SetFsAcces: habilita el acceso al sistema root del cliente con schroot
|
||||
def configure_schroot (btrootfsimg):
|
||||
if (utils.grep (btrootfsimg, '/etc/schroot/schroot.conf')):
|
||||
return
|
||||
logger.info ('Iniciando la configuración del schroot')
|
||||
|
||||
if (os.path.exists ('/etc/schroot/schroot.conf')):
|
||||
shutil.copy ('/etc/schroot/schroot.conf', '/etc/schroot/schroot.conf.bak')
|
||||
with open ('/etc/schroot/schroot.conf', 'w') as f:
|
||||
f.write (schroot_conf_tpl + '\n')
|
||||
|
||||
if (os.path.exists ('/etc/schroot/mount-defaults')):
|
||||
shutil.copy ('/etc/schroot/mount-defaults', '/etc/schroot/mount-defaults.bak')
|
||||
with open ('/etc/schroot/mount-defaults', 'w') as f:
|
||||
f.write (mount_defaults_tpl + '\n')
|
||||
|
||||
for i in glob.glob ('/etc/schroot/setup.d/*chrootname'):
|
||||
os.unlink (i)
|
||||
|
||||
logger.info ('Finalizado: OK')
|
||||
return 0
|
||||
|
||||
# debootstrap: Genera el sistema root base con debootstrap
|
||||
# trabaja sobre un rootfs ya montado
|
||||
def debootstrap (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp):
|
||||
|
@ -438,8 +388,8 @@ def mkisofs (pxepkg, isolinux_tpl, bttargetdir, nameisoclient):
|
|||
utils.write_md5 (f'{nameisoclient}.iso')
|
||||
os.chdir (oldpwd)
|
||||
|
||||
os.rename (f'/tmp/{nameisoclient}.iso' , f'/var/lib/tftpboot/ogclient/{nameisoclient}.iso')
|
||||
os.rename (f'/tmp/{nameisoclient}.iso.sum', f'/var/lib/tftpboot/ogclient/{nameisoclient}.iso.sum')
|
||||
shutil.move (f'/tmp/{nameisoclient}.iso' , f'/var/lib/tftpboot/ogclient/{nameisoclient}.iso')
|
||||
shutil.move (f'/tmp/{nameisoclient}.iso.sum', f'/var/lib/tftpboot/ogclient/{nameisoclient}.iso.sum')
|
||||
|
||||
#def __unused_boottoolsBootGraphics():
|
||||
# find /tmp/opengnsys_installer/ -name .svn -type d -exec rm -fr {} \; 2>/dev/null;
|
||||
|
|
|
@ -36,20 +36,23 @@ def run (args):
|
|||
sel.close()
|
||||
#p.stdout.close()
|
||||
#p.stderr.close()
|
||||
#p.wait()
|
||||
stdout = stdout.strip()
|
||||
stderr = stderr.strip()
|
||||
|
||||
logger.debug (f'p.returncode {p.returncode}')
|
||||
if p.returncode:
|
||||
logger.error ('command "{}" failed with rc "{}"'.format (' '.join(args), p.returncode))
|
||||
|
||||
#logger.error ('stdout follows:')
|
||||
#for i in cp.stdout.strip().split('\n'): logger.error (' ' + i)
|
||||
#if stdout:
|
||||
# for i in stdout.split('\n'): logger.error (' ' + i)
|
||||
|
||||
logger.error ('stderr follows:')
|
||||
for i in cp.stderr.strip().split('\n'): logger.error (' ' + i)
|
||||
if stderr:
|
||||
for i in stderr.split('\n'): logger.error (' ' + i)
|
||||
|
||||
raise Exception ('command "{}" failed with rc "{}"'.format (' '.join(args), p.returncode))
|
||||
stdout = stdout.strip()
|
||||
stderr = stderr.strip()
|
||||
return stdout, stderr
|
||||
|
||||
def grep (regex, file):
|
||||
|
|
20
mkoglive.py
20
mkoglive.py
|
@ -30,11 +30,6 @@ def _logging (lvl='INFO'):
|
|||
)
|
||||
return logging.getLogger ('boottools')
|
||||
|
||||
def clone_client_dirs (ogrepo_url, ogrepo_branch, ogrepo_dir):
|
||||
if not os.path.exists ('/tmp/opengnsys/engine'):
|
||||
utils.run (['git', 'clone', '-c', 'http.sslVerify=false', '--branch', ogrepo_branch, ogrepo_url, ogrepo_dir])
|
||||
utils.run (['rsync', '-aH', f'{ogrepo_dir}/client/engine', f'{ogrepo_dir}/client/shared', '/tmp/opengnsys/'])
|
||||
|
||||
def _mount_rootfs():
|
||||
global btrootfsimg, btrootfsmnt
|
||||
try: utils.mount (btrootfsimg, btrootfsmnt, opts=['-o', 'loop,offset=32256'])
|
||||
|
@ -63,15 +58,11 @@ def _mkrootfs():
|
|||
logger.error (str (e))
|
||||
sys.exit (1)
|
||||
|
||||
def _schroot (btrootfsimg):
|
||||
logger.info ('Stage 3.2 - configure schroot in the VM')
|
||||
btog.configure_schroot (btrootfsimg)
|
||||
|
||||
## para hacer schroot --cosas, el mntpt tiene que estar desmontado
|
||||
## si está montado da un pete tal que 'E: 10mount: mount: /run/schroot/mount/IMGogclient-7fbf51a2-e37e-48e5-8e5d-83f8901fc7ed: wrong fs type, bad option, bad superblock on /dev/loop1, missing codepage or helper program, or other error.'
|
||||
|
||||
def _debootstrap():
|
||||
logger.info ('Stage 3.3 - debootstrap system')
|
||||
logger.info ('Stage 3.2 - debootstrap system')
|
||||
logger.debug ('Try creation of a file within chroot (this operation may fail with "... etc/resolv.conf: No such file or directory"--that is ok)')
|
||||
logger.debug ('Running \'schroot --chroot IMGogclient -- stat /etc\'')
|
||||
cp = subprocess.run (['schroot', '--chroot', 'IMGogclient', '--', 'stat', '/etc'])
|
||||
|
@ -151,10 +142,7 @@ except: pass
|
|||
logger.info ('OpenGnsys CLIENT installation begins')
|
||||
|
||||
logger.info ('STAGE 1 - clone opengnsys repo')
|
||||
ogrepo_url = 'https://ognproject.evlt.uma.es/gitea/opengnsys/opengnsys.git'
|
||||
ogrepo_branch = 'main'
|
||||
ogrepo_dir = '/tmp/ogrepo'
|
||||
clone_client_dirs (ogrepo_url, ogrepo_branch, ogrepo_dir)
|
||||
ogrepo_dir = '/tmp/ogrepo' ## per the Dockerfile
|
||||
|
||||
osdistrib, oscodename, osrelease, osarch, oshttp = btog.GetOsInfo1 (type_client)
|
||||
if osdistrib is None:
|
||||
|
@ -165,14 +153,10 @@ gitrelease, nameisoclient, namehostclient = btog.GetOsInfo2 (ogrepo_dir, version
|
|||
logger.info (':'.join ([osdistrib, oscodename, osrelease, osarch, oshttp]))
|
||||
|
||||
logger.info ('STAGE 2 - install software in the VM')
|
||||
apt.update()
|
||||
apt.upgrade()
|
||||
pxepkg = _get_pxepkg()
|
||||
apt.install (['jq', 'syslinux', 'syslinux-efi', 'syslinux-utils', 'debootstrap', 'subversion', 'schroot', 'squashfs-tools', 'syslinux', 'genisoimage', 'qemu-utils', 'lsof', pxepkg]) ## TODO qemu no existe, hace falta?
|
||||
|
||||
logger.info ('STAGE 3 - create and bootstrap rootfs')
|
||||
_mkrootfs()
|
||||
_schroot (btrootfsimg)
|
||||
_debootstrap()
|
||||
|
||||
logger.info ('STAGE 4 - copy files to the rootfs')
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# mount.defaults: static file system information for chroots.
|
||||
# Note that the mount point will be prefixed by the chroot path
|
||||
# (CHROOT_PATH)
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
proc /proc proc defaults 0 0
|
||||
#procbususb /proc/bus/usb usbfs defaults 0 0
|
||||
#/dev /dev none rw,bind 0 0
|
||||
/dev/pts /dev/pts none rw,bind 0 0
|
||||
/dev/shm /dev/shm none rw,bind 0 0
|
||||
#/home /home none rw,bind 0 0
|
||||
/tmp /tmp none rw,bind 0 0
|
|
@ -0,0 +1,10 @@
|
|||
[IMGogclient]
|
||||
type=loopback
|
||||
file=/var/lib/tftpboot/ogclient/ogclient.img
|
||||
description=ogclient Ubuntu image
|
||||
#priority=1
|
||||
users=root
|
||||
groups=root
|
||||
root-groups=root
|
||||
mount-options=-o offset=32256
|
||||
root-users=root
|
Loading…
Reference in New Issue