From b7a23c41da43b8ce1ffa0519de65c21a3f7da8c2 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Thu, 2 Jun 2016 17:58:56 +0200 Subject: [PATCH 1/2] Encode xml before writing --- vocker | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vocker b/vocker index 0ddc49f..6ae0b36 100755 --- a/vocker +++ b/vocker @@ -345,6 +345,8 @@ if __name__ == "__main__": with tempfile.NamedTemporaryFile("wb") as spec: + if type(xml) == str: + xml = xml.encode() spec.write(xml) spec.flush() sh.virsh("define", spec.name) From 696c1c19e57fefb5d4d689f1fa99cc298fea8d69 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Fri, 3 Jun 2016 11:23:30 +0200 Subject: [PATCH 2/2] Run CMD on ttyS0 terminal trough .bashrc A very simple way to have automatic login with everything set up and making sure that we run CMD only once by checking in .bashrc if tty confirms that we run on ttyS0. After CMD is done, 'shutdown -h now' is invoked. --- examples/Dockerfile.simple | 2 +- vocker | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/Dockerfile.simple b/examples/Dockerfile.simple index 5a2a9a5..6698016 100644 --- a/examples/Dockerfile.simple +++ b/examples/Dockerfile.simple @@ -7,4 +7,4 @@ RUN echo Hello > /marker EXPOSE 1234 -CMD echo World >> /marker +CMD echo World >> /marker && echo "Ciao!" diff --git a/vocker b/vocker index 6ae0b36..9e01208 100755 --- a/vocker +++ b/vocker @@ -145,13 +145,16 @@ class CmdOperation(Operation): log.warn("Not supporting CMD […], copying it anyway") env = ["export %s" % e for e in self.env if "=" in e] - cmd = "#!/bin/bash\n\n%s\n\n%s" % ("\n".join(env), self.args) + cmd = "#!/bin/bash\n\n%s\n\n%s\n" % ("\n".join(env), self.args) + ttyS0 = "#!/bin/bash\n\nif [ `tty | sed -e \"s#^.\+/##\"` == ttyS0 ]; then /etc/vocker.sh; shutdown -h now; fi\n" log.debug("rc.local: %s" % cmd) fish(layer.filename, - "write", "/etc/rc.d/rc.local", cmd, + "write", "/etc/vocker.sh", cmd, ":", - "sh", "chmod a+x /etc/rc.d/rc.local", + "write", "/root/.bashrc", ttyS0, + ":", + "sh", "chmod a+x /etc/vocker.sh", ":", "sh", "sed -i '/^ExecStart=/ s/$/ --autologin root/' /usr/lib/systemd/system/getty@.service /usr/lib/systemd/system/serial-getty@.service", ":",