This commit is contained in:
Disassembler 2018-09-11 19:20:18 +02:00
parent a9e99a82c5
commit e8354e59c9
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
2 changed files with 15 additions and 5 deletions

View File

@ -30,6 +30,9 @@ lxc.init.cmd = {cmd}
lxc.init.uid = {uid} lxc.init.uid = {uid}
lxc.init.gid = {gid} lxc.init.gid = {gid}
# Environment
{env}
# Halt # Halt
lxc.signal.halt = SIGTERM lxc.signal.halt = SIGTERM
@ -48,6 +51,7 @@ class LXCImage:
self.name = None self.name = None
self.layers = [] self.layers = []
self.mounts = [] self.mounts = []
self.env = []
self.uid = 0 self.uid = 0
self.gid = 0 self.gid = 0
self.cmd = '/bin/true' self.cmd = '/bin/true'
@ -85,6 +89,9 @@ class LXCImage:
elif line.startswith('MOUNT'): elif line.startswith('MOUNT'):
srcdst = line.split() srcdst = line.split()
self.add_mount(srcdst[1], srcdst[2]) self.add_mount(srcdst[1], srcdst[2])
elif line.startswith('ENV'):
env = line.split()
self.add_env(env[1], env[2])
elif line.startswith('USER'): elif line.startswith('USER'):
uidgid = line.split() uidgid = line.split()
self.set_user(uidgid[1], uidgid[2]) self.set_user(uidgid[1], uidgid[2])
@ -100,8 +107,9 @@ class LXCImage:
# Multiple lower overlayfs layers are ordered from right to left (lower2:lower1:rootfs:upper) # Multiple lower overlayfs layers are ordered from right to left (lower2:lower1:rootfs:upper)
rootfs_path = 'overlay:{}:{}'.format(':'.join(self.layers[:-1][::-1]), self.layers[-1]) rootfs_path = 'overlay:{}:{}'.format(':'.join(self.layers[:-1][::-1]), self.layers[-1])
mount_entries = '\n'.join(['lxc.mount.entry = {} none bind 0 0'.format(m) for m in self.mounts]) mount_entries = '\n'.join(['lxc.mount.entry = {} none bind 0 0'.format(m) for m in self.mounts])
env_entries = '\n'.join(['lxc.environment = {}'.format(e) for e in self.env])
with open(os.path.join(LXC_ROOT, self.name, 'config'), 'w') as fd: with open(os.path.join(LXC_ROOT, self.name, 'config'), 'w') as fd:
fd.write(CONFIG_TEMPLATE.format(name=self.name, rootfs=rootfs_path, mounts=mount_entries, uid=self.uid, gid=self.gid, cmd=self.cmd)) fd.write(CONFIG_TEMPLATE.format(name=self.name, rootfs=rootfs_path, mounts=mount_entries, env=env_entries, uid=self.uid, gid=self.gid, cmd=self.cmd))
def run_script(self, script): def run_script(self, script):
sh = os.path.join(self.layers[-1], 'run.sh') sh = os.path.join(self.layers[-1], 'run.sh')
@ -130,6 +138,10 @@ class LXCImage:
self.mounts.append('{} {}'.format(src, dst)) self.mounts.append('{} {}'.format(src, dst))
self.rebuild_config() self.rebuild_config()
def add_env(self, key, value):
self.env.append('{}={}'.format(key, value))
self.rebuild_config()
def set_user(self, uid, gid): def set_user(self, uid, gid):
self.uid = uid self.uid = uid
self.gid = gid self.gid = gid

View File

@ -15,13 +15,11 @@ SCRIPT
# Create OS user # Create OS user
addgroup -S -g 8983 solr addgroup -S -g 8983 solr
adduser -S -u 8983 -h /var/lib/solr -s /bin/false -g solr -G solr solr adduser -S -u 8983 -h /var/lib/solr -s /bin/false -g solr -G solr solr
chown -R solr:solr /opt/solr/ chown -R solr:solr /opt/solr
# Copy basic configuration file to data location
cp -p /opt/solr/server/solr/solr.xml /var/lib/solr/solr.xml
RUN RUN
MOUNT /srv/solr/data var/lib/solr MOUNT /srv/solr/data var/lib/solr
USER 8983 8983 USER 8983 8983
ENV HOME /var/lib/solr
CMD /opt/solr/bin/solr start -f CMD /opt/solr/bin/solr start -f