Skip to content

Commit

Permalink
Add library injector
Browse files Browse the repository at this point in the history
  • Loading branch information
shaded-enmity committed Apr 25, 2016
1 parent b7eff5f commit bc42558
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HICA (Host Integrated Container Applications) v0.5.1
HICA (Host Integrated Container Applications) v0.6.0
----------------------------------------------------
[hɑɪkː]

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.1
0.6.0
1 change: 1 addition & 0 deletions docs/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ under `schema` versions.
| io.hica.kvm_passthrough | --kvm-device | *path* | `/dev/kvm` |
| io.hica.introspect_runtime=[] | --introspect-runtime | *path* | `none` |
| io.hica.tty | *none* | *none* | *none* |
| io.hica.libraries | --libraries, --library-path | `["a", "b" ...]` list, `path` | `none` |
| io.hica.command_aliases | *none* | `JSON Document` | {} |

---
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions injectors/libs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# vim: set fileencoding=utf-8
# Pavel Odvody <[email protected]>
#
# HICA - Host integrated container applications
#
# MIT License (C) 2015

import os, sys
from json import loads
from base.hica_base import *

library_path='/usr/lib64'

class LibraryInjector(HicaInjector):
def _get_libs(self):
return sorted(loads(self.labels.get_value('io.hica.libraries')))

def get_description(self):
return 'Bind mounts libraries {0} into the container'.format(', '.join(self._get_libs()))

def get_config_key(self):
return 'io.hica.libraries'

def get_injected_args(self):
return (('--libraries', HicaValueType.STRING, ''), ('--library-path', HicaValueType.PATH, '/usr/lib64'))

def inject_config(self, config, from_args):
"""
:param config:
:type config: list
:param from_args:
:type from_args: dict
"""

load_libs = self._get_libs()

all_libs = {}
found_libs = []

for root, dirs, files in os.walk(library_path):
for f in files:
if not f.endswith('.so'):
continue

full_path = os.path.join(root, f)
if '.' in f:
name, ext = f.split('.', 1)
else:
name = f

if name in all_libs:
all_libs[name].append(full_path)
else:
all_libs[name] = [full_path]

for lib in load_libs:
if 'lib' + lib in all_libs:
p = list(sorted(all_libs['lib' + lib], key=lambda x: len(x))).pop()
v = '--volume={0}:{1}'.format(os.path.realpath(p), p)
config.append(v)
else:
print('*** Unknown lib: {}'.format(lib))
sys.exit(1)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
os.mkdir(injectors)
setup(
name = 'docker-hica',
version = '0.5.1',
version = '0.6.0',
packages = find_packages(),
scripts = ['docker-hica'],
scripts = ['hica'],
install_requires = ['docker-py'],
package_data = {
'': ['LICENSE', 'README.md', 'VERSION', 'CONTRIBUTORS']
Expand Down

0 comments on commit bc42558

Please sign in to comment.