Skip to content

Commit

Permalink
refs #44, #45, #46: Update C/C++/Java kernels
Browse files Browse the repository at this point in the history
 * Rename "java" to "java8"
 * java8 kernel image now uses the Alpine Linux's openjdk package for faster builds
 * Removed no-longer necessary chmod commands in C/C++ kernels
  • Loading branch information
achimnol committed Aug 30, 2017
1 parent 72b52c7 commit eb6805b
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 97 deletions.
12 changes: 5 additions & 7 deletions c/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ MAINTAINER DevOps "[email protected]"
# Install minimal C compile environments
RUN apk add --no-cache gcc musl-dev

# Install Python packages
RUN pip install --no-cache-dir aiozmq

COPY run.py /home/sorna/run.py
COPY policy.yml /home/sorna/policy.yml
COPY patch-libs.so /home/sorna/patch-libs.so
COPY base_run.py /home/sorna/base_run.py
#COPY patch-libs.so /home/sorna/patch-libs.so
#COPY base_run.py /home/sorna/base_run.py

LABEL io.sorna.features "batch query uid-match user-input"

USER work
CMD ["/home/sorna/sorna-jail", "-policy", "/home/sorna/policy.yml", "/usr/local/bin/python3", "/home/sorna/run.py"]
CMD ["/home/sorna/jail", "-policy", "/home/sorna/policy.yml", "/usr/local/bin/python3", "/home/sorna/run.py"]
11 changes: 5 additions & 6 deletions cpp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM lablup/kernel-base-python3-minimal:latest
MAINTAINER DevOps "[email protected]"

# Install Python packages
RUN pip install --no-cache-dir aiozmq

# Install minimal C++ compile environments
RUN apk add --no-cache g++
RUN apk add --no-cache g++ libstdc++

COPY run.py /home/sorna/run.py
COPY policy.yml /home/sorna/policy.yml

LABEL io.sorna.features "batch query uid-match user-input"

USER work
CMD ["/home/sorna/jail", "python3", "/usr/local/bin/python3", "/home/sorna/run.py"]
CMD ["/home/sorna/jail", "-policy", "/home/sorna/policy.yml", "/usr/local/bin/python3", "/home/sorna/run.py"]
23 changes: 23 additions & 0 deletions cpp/policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
whitelist_paths:
OP_OPEN: ["*"]
OP_ACCESS: ["*"]
OP_EXEC: ["*"]
OP_STAT: ["*"]
OP_CHMOD: ["/home/work/*", "/tmp/*"]
exec_allowance: -1
fork_allowance: -1
max_child_procs: 32
extra_envs: []
preserved_env_keys: [
"HOME", "PATH", "LANG",
"USER", "SHELL", "TERM",
"LD_LIBRARY_PATH",
"LD_PRELOAD",
]

diff_to_default: true

# Following syscalls are blindly allowed.
# IMPORTANT: ptrace MUST NOT be included!
allowed_syscalls:
- "umask"
8 changes: 4 additions & 4 deletions cpp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def build(self, build_cmd):
cppfiles = Path('.').glob('**/*.cpp')
cppfiles = ' '.join(map(lambda p: shlex.quote(str(p)), cppfiles))
cmd = (f'g++ {cppfiles} {DEFAULT_CFLAGS} -o ./main {DEFAULT_LDFLAGS}; '
f'chmod 755 ./main')
f'./main')
await self.run_subproc(cmd)
else:
log.error('cannot find build script ("Makefile") '
Expand All @@ -65,9 +65,9 @@ async def execute(self, exec_cmd):
return
elif exec_cmd == '*':
if Path('./main').is_file():
await self.run_subproc('chmod 755 ./main; ./main')
await self.run_subproc('./main')
elif Path('./a.out').is_file():
await self.run_subproc('chmod 755 ./a.out; ./a.out')
await self.run_subproc('./a.out')
else:
log.error('cannot find executable ("a.out" or "main").')
else:
Expand All @@ -82,7 +82,7 @@ async def query(self, code_text):
tmpf.write(code_text.encode('utf8'))
tmpf.flush()
cmd = (f'g++ {tmpf.name} {DEFAULT_CFLAGS} -o ./main {DEFAULT_LDFLAGS} '
f'&& chmod 755 ./main && ./main')
f'&& ./main')
await self.run_subproc(cmd)


Expand Down
78 changes: 0 additions & 78 deletions java/Dockerfile

This file was deleted.

29 changes: 29 additions & 0 deletions java8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM lablup/kernel-base-python3-minimal:latest
MAINTAINER DevOps "[email protected]"

# Install Java compile environments
# ref: https://github.com/docker-library/openjdk/blob/master/8-jdk/alpine/Dockerfile
# You may need to check the Alpine package repository for latest OpenJDK package available.
# ref: https://pkgs.alpinelinux.org/packages?name=openjdk8&branch=v3.6&repo=&arch=x86_64
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
ENV JAVA_VERSION 8u131
ENV JAVA_ALPINE_VERSION 8.131.11-r2
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home
RUN set -x \
&& apk add --no-cache \
openjdk8="$JAVA_ALPINE_VERSION" \
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]

COPY run.py /home/sorna/run.py
COPY policy.yml /home/sorna/policy.yml

LABEL io.sorna.features "batch query uid-match user-input"

CMD ["/home/sorna/jail", "-policy", "/home/sorna/policy.yml", "/usr/local/bin/python3", "/home/sorna/run.py"]
23 changes: 23 additions & 0 deletions java8/policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
whitelist_paths:
OP_OPEN: ["*"]
OP_ACCESS: ["*"]
OP_EXEC: ["*"]
OP_STAT: ["*"]
OP_CHMOD: ["/home/work/*", "/tmp/*"]
exec_allowance: -1
fork_allowance: -1
max_child_procs: 32
extra_envs: []
preserved_env_keys: [
"HOME", "PATH", "LANG",
"USER", "SHELL", "TERM",
"LD_LIBRARY_PATH",
"LD_PRELOAD",
]

diff_to_default: true

# Following syscalls are blindly allowed.
# IMPORTANT: ptrace MUST NOT be included!
allowed_syscalls:
- "umask"
7 changes: 5 additions & 2 deletions java/run.py → java8/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

JCC = 'javac'
JCR = 'java'
DEFAULT_JFLAGS = '-d .'

# Let Java respect container resource limits
DEFAULT_JFLAGS = '-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -d .'

CHILD_ENV = {
'TERM': 'xterm',
'LANG': 'C.UTF-8',
'SHELL': '/bin/ash',
'USER': 'work',
'HOME': '/home/work',
'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/jdk/bin',
'PATH': '/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}


Expand Down
1 change: 1 addition & 0 deletions python2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ COPY policy.yml /home/sorna/
COPY run.py /home/sorna/

LABEL io.sorna.envs.corecount="OPENBLAS_NUM_THREADS,NPROC"
LABEL io.sorna.features "query uid-match user-input"

CMD ["/home/sorna/jail", "-policy", "/home/sorna/policy.yml", "/usr/local/bin/python", "/home/sorna/run.py"]

Expand Down
1 change: 1 addition & 0 deletions python3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ COPY policy.yml /home/sorna/
COPY run.py /home/sorna/

LABEL io.sorna.envs.corecount="OPENBLAS_NUM_THREADS,NPROC"
LABEL io.sorna.features "batch query uid-match user-input"

CMD ["/home/sorna/jail", "-policy", "/home/sorna/policy.yml", "/usr/local/bin/python3", "/home/sorna/run.py"]

Expand Down

0 comments on commit eb6805b

Please sign in to comment.