Skip to content

Commit

Permalink
Ensure access to tty within container (close #3).
Browse files Browse the repository at this point in the history
And return exit value of command if invoked as `switch biolinux blastp ...`.

Signed-off-by: Anurag Priyam <[email protected]>
  • Loading branch information
yeban committed Jan 13, 2015
1 parent 147381f commit 945a49d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
11 changes: 6 additions & 5 deletions Dockerfiles/baseimage/_init
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if [ $? -ne 0 ]; then
passwd -d $user &> /dev/null
fi

if [ $# -eq 0 ]; then
su -l $user -s $shell -c "[ -d $cwd ] && cd $cwd; exec $shell"
else
su -l $user -s $shell -c "[ -d $cwd ] && cd $cwd; $*"
fi
exec sudo -u $user -i exec $shell -c \
"
[ -d $cwd ] && cd $cwd;
[ $# -gt 0 ] && exec $*;
exec $shell;
"
11 changes: 3 additions & 8 deletions lib/switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def to_s

include Timeout

# Captures a docker image.
# Captures a docker image's metadata.
Image = Struct.new :repository, :tag, :id, :created, :size

class Image
Expand Down Expand Up @@ -147,19 +147,14 @@ def initialize(package, command = [])
# images on the user's system. It must be noted though that other program
# may use the same prefix, and thus our images aren't truly isolated.
@imgname = "switch/#{@package.gsub('_', ':')}"
# We don't give up the pid untill docker completes. Thus appending pid to
# the package name gurantees us a unique container name. If we were using
# exec or fork, we would have to worry about pids being recycled.

@cntname = "#@package-#{Process.pid}"

exec
end

attr_reader :package, :command, :imgname, :cntname

# NOTE:
# Doesn't really exec. Our ruby proecess waits till docker process started
# has been terminated.
def exec
ping and build and switch
rescue ENODKR, ENOPKG => e
Expand All @@ -172,7 +167,7 @@ def exec
def switch
cmdline = "docker run --name #{cntname} --hostname #{cntname} -it --rm=true" \
" #{mountargs} #{imgname} #{userargs} #{command}"
system cmdline
Kernel.exec cmdline
end

def build
Expand Down

0 comments on commit 945a49d

Please sign in to comment.