Skip to content

Commit

Permalink
Merge branch 'hotfix-0.1.1' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandGouny committed Aug 18, 2015
2 parents 2e8738b + 60834e4 commit c6782ce
Show file tree
Hide file tree
Showing 96 changed files with 92 additions and 1,632 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog

## 0.1.1
- Fix remove-service #1
- Add python and PyYAML
- Fix locales
- Fix my_init

## 0.1.0
- Initial release
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
NAME = osixia/light-baseimage
VERSION = 0.1.0
VERSION = 0.1.1

.PHONY: all build test tag_latest release build-tool

all: build

build-tool:
./src/py_tool/build.sh

build:
docker build -t $(NAME):$(VERSION) --rm image

Expand Down
42 changes: 25 additions & 17 deletions image/build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#!/bin/bash -ex

## Add bash tools to /sbin
ln -s /container/tool/add-host /sbin/add-host
ln -s /container/tool/install-multiple-process-stack /sbin/install-multiple-process-stack
ln -s /container/tool/install-service /sbin/install-service
ln -s /container/tool/install-service-available /sbin/install-service-available
ln -s /container/tool/remove-service /sbin/remove-service
ln -s /container/tool/run /sbin/run

# Add python tools and needed directories
ln -s /container/tool/py_tool/my_init /sbin/my_init
ln -s /container/tool/* /sbin/

# Add needed directories & files
mkdir -p /etc/service
mkdir -p /etc/my_init.d
mkdir -p /etc/container_environment
Expand All @@ -20,16 +14,10 @@ groupadd -g 8377 docker_env
chown :docker_env /etc/container_environment.sh
chmod 640 /etc/container_environment.sh

ln -s /container/tool/py_tool/setuser /sbin/setuser

# dpkg
# dpkg options
cp /container/file/dpkg_nodoc /etc/dpkg/dpkg.cfg.d/01_nodoc
cp /container/file/dpkg_nolocales /etc/dpkg/dpkg.cfg.d/01_nolocales

# Remove useless files
rm -rf /container/file
rm -rf /container/build.sh /container/Dockerfile

# General config
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -62,12 +50,32 @@ dpkg-divert --local --rename --add /usr/bin/ischroot
ln -sf /bin/true /usr/bin/ischroot

## Install apt-utils.
$minimal_apt_get_install apt-utils
$minimal_apt_get_install apt-utils python locales

## Upgrade all packages.
apt-get dist-upgrade -y --no-install-recommends

# fix locale
locale-gen en_US.UTF-8 en_us
locale-gen C.UTF-8
dpkg-reconfigure locales
/usr/sbin/update-locale LANG=C.UTF-8

echo -n C.UTF-8 > /etc/container_environment/LANG
echo -n C.UTF-8 > /etc/container_environment/LANGUAGE
echo -n C.UTF-8 > /etc/container_environment/LC_CTYPE

# install PyYAML
tar -C /container/file/ -xvf /container/file/PyYAML-3.11.tar.gz
cd /container/file/PyYAML-3.11/
python setup.py install
cd -

apt-get clean
rm -rf /tmp/* /var/tmp/*
rm -rf /var/lib/apt/lists/*
rm -f /etc/dpkg/dpkg.cfg.d/02apt-speedup

# Remove useless files
rm -rf /container/file
rm -rf /container/build.sh /container/Dockerfile
Binary file added image/file/PyYAML-3.11.tar.gz
Binary file not shown.
2 changes: 0 additions & 2 deletions image/tool/add-host

This file was deleted.

96 changes: 47 additions & 49 deletions src/py_tool/my_init.py → image/tool/my_init
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3 -u
#!/usr/bin/python -u
import os, os.path, sys, stat, signal, errno, argparse, time, re, yaml, ast

KILL_PROCESS_TIMEOUT = 5
Expand Down Expand Up @@ -142,7 +142,7 @@ def export_envvars(to_dir = True):
return
shell_dump = ""
for name, value in os.environ.items():
if name in ['HOME', 'USER', 'GROUP', 'UID', 'GID', 'SHELL', 'SHLVL', 'PYTHONPATH', 'LD_LIBRARY_PATH']:
if name in ['USER', 'GROUP', 'UID', 'GID', 'SHELL']:
continue
if to_dir:
with open("/etc/container_environment/" + name, "w") as f:
Expand Down Expand Up @@ -186,7 +186,10 @@ def waitpid_reap_other_children(pid):
status = None
while not done:
try:
this_pid, status = os.waitpid(-1, 0)
# https://github.com/phusion/baseimage-docker/issues/151#issuecomment-92660569
this_pid, status = os.waitpid(pid, os.WNOHANG)
if this_pid == 0:
this_pid, status = os.waitpid(-1, 0)
if this_pid == pid:
done = True
else:
Expand Down Expand Up @@ -322,48 +325,47 @@ def main(args):
with open("/etc/my_init_startup_files_completed", "w") as f:
f.write("1")

if not args.single_process:
runit_exited = False
exit_code = None
runit_exited = False
exit_code = None

if not args.skip_runit:
runit_pid = start_runit()
try:
exit_status = None
if len(args.main_command) == 0:
runit_exited, exit_code = wait_for_runit_or_interrupt(runit_pid)
if runit_exited:
if exit_code is None:
info("Runit exited with unknown status")
exit_status = 1
else:
exit_status = os.WEXITSTATUS(exit_code)
info("Runit exited with status %d" % exit_status)
else:
info("Running %s..." % " ".join(args.main_command))
pid = os.spawnvp(os.P_NOWAIT, args.main_command[0], args.main_command)
try:
exit_code = waitpid_reap_other_children(pid)
if exit_code is None:
info("%s exited with unknown status." % args.main_command[0])
exit_status = 1
else:
exit_status = os.WEXITSTATUS(exit_code)
info("%s exited with status %d." % (args.main_command[0], exit_status))
except KeyboardInterrupt:
stop_child_process(args.main_command[0], pid)
raise
except BaseException as s:
warn("An error occurred. Aborting.")
stop_child_process(args.main_command[0], pid)
raise
sys.exit(exit_status)
finally:
if not args.skip_runit:
runit_pid = start_runit()
try:
exit_status = None
if len(args.main_command) == 0:
runit_exited, exit_code = wait_for_runit_or_interrupt(runit_pid)
if runit_exited:
if exit_code is None:
info("Runit exited with unknown status")
exit_status = 1
else:
exit_status = os.WEXITSTATUS(exit_code)
info("Runit exited with status %d" % exit_status)
else:
info("Running %s..." % " ".join(args.main_command))
pid = os.spawnvp(os.P_NOWAIT, args.main_command[0], args.main_command)
try:
exit_code = waitpid_reap_other_children(pid)
if exit_code is None:
info("%s exited with unknown status." % args.main_command[0])
exit_status = 1
else:
exit_status = os.WEXITSTATUS(exit_code)
info("%s exited with status %d." % (args.main_command[0], exit_status))
except KeyboardInterrupt:
stop_child_process(args.main_command[0], pid)
raise
except BaseException as s:
warn("An error occurred. Aborting.")
stop_child_process(args.main_command[0], pid)
raise
sys.exit(exit_status)
finally:
if not args.skip_runit:
shutdown_runit_services()
if not runit_exited:
stop_child_process("runit daemon", runit_pid)
wait_for_runit_services()
shutdown_runit_services()
if not runit_exited:
stop_child_process("runit daemon", runit_pid)
wait_for_runit_services()

try:
os.remove("/etc/my_init_startup_files_completed")
Expand All @@ -386,23 +388,19 @@ def main(args):
parser.add_argument('--quiet', dest = 'log_level',
action = 'store_const', const = LOG_LEVEL_WARN, default = LOG_LEVEL_INFO,
help = 'Only print warnings and errors')
parser.add_argument('--single-process', dest = 'single_process',
action = 'store_const', const = True, default = False,
help = 'Only run /etc/my_init.d/* and /etc/rc.local scripts and export envvar')

args = parser.parse_args()
log_level = args.log_level

if args.skip_runit and len(args.main_command) == 0:
error("When --skip-runit is given, you must also pass a main command.")
sys.exit(1)

if args.single_process:
args.kill_all_on_exit = False

# Run main function.
signal.signal(signal.SIGTERM, lambda signum, frame: ignore_signals_and_raise_keyboard_interrupt('SIGTERM'))
signal.signal(signal.SIGINT, lambda signum, frame: ignore_signals_and_raise_keyboard_interrupt('SIGINT'))
signal.signal(signal.SIGALRM, lambda signum, frame: raise_alarm_exception())

try:
main(args)
except KeyboardInterrupt:
Expand Down
Binary file removed image/tool/py_tool/_codecs_cn.so
Binary file not shown.
Binary file removed image/tool/py_tool/_codecs_hk.so
Binary file not shown.
Binary file removed image/tool/py_tool/_codecs_iso2022.so
Binary file not shown.
Binary file removed image/tool/py_tool/_codecs_jp.so
Binary file not shown.
Binary file removed image/tool/py_tool/_codecs_kr.so
Binary file not shown.
Binary file removed image/tool/py_tool/_codecs_tw.so
Binary file not shown.
Binary file removed image/tool/py_tool/_hashlib.so
Binary file not shown.
Binary file removed image/tool/py_tool/_multibytecodec.so
Binary file not shown.
Binary file removed image/tool/py_tool/_ssl.so
Binary file not shown.
Binary file removed image/tool/py_tool/audioop.so
Binary file not shown.
Binary file removed image/tool/py_tool/bz2.so
Binary file not shown.
Binary file removed image/tool/py_tool/libbz2.so.1.0
Binary file not shown.
Binary file removed image/tool/py_tool/libcrypto.so.1.0.0
Binary file not shown.
Binary file removed image/tool/py_tool/libpython2.7.so.1.0
Binary file not shown.
Binary file removed image/tool/py_tool/libreadline.so.6
Binary file not shown.
Binary file removed image/tool/py_tool/libssl.so.1.0.0
Binary file not shown.
Binary file removed image/tool/py_tool/libtinfo.so.5
Binary file not shown.
Binary file removed image/tool/py_tool/libz.so.1
Binary file not shown.
Binary file removed image/tool/py_tool/my_init
Binary file not shown.
Binary file removed image/tool/py_tool/readline.so
Binary file not shown.
Binary file removed image/tool/py_tool/setuser
Binary file not shown.
Binary file removed image/tool/py_tool/termios.so
Binary file not shown.
11 changes: 6 additions & 5 deletions image/tool/remove-service
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ do

echo "remove-service: $i"

if [ -d /container/service/$i ]; then
echo "remove folder /container/service/$i"
rm -rf /container/service/$i
fi

if [ -d /etc/service/$i ]; then
echo "remove folder /etc/service/$i"
rm -rf /etc/service/$i
Expand All @@ -20,4 +15,10 @@ do
echo "remove file /etc/my_init.d/$i"
rm -f /etc/my_init.d/$i
fi

if [ -d /container/service/$i ]; then
echo "remove folder /container/service/$i"
rm -rf /container/service/$i
fi

done
18 changes: 6 additions & 12 deletions image/tool/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@ nbDirectories=$(find /etc/service -mindepth 1 -maxdepth 1 -type d | wc -l )

# Multiple process image
if [ "$nbDirectories" -gt 1 ]; then
echo "Execute /container/tool/py_tool/my_init"
exec /container/tool/py_tool/my_init
echo "Execute /container/tool/my_init"
exec /container/tool/my_init

# Single process image
elif [ "$nbDirectories" -eq 1 ]; then

SERVICE=$(find /etc/service -mindepth 1 -maxdepth 1 -type d)

echo "Execute /container/tool/py_tool/my_init --single-process"
/container/tool/py_tool/my_init --single-process

echo "Include /etc/container_environment.sh"
source /etc/container_environment.sh

echo "Execute $SERVICE/run"
source $SERVICE/run
echo "Execute /container/tool/my_init --skip-runit bash $SERVICE/run"
exec /container/tool/my_init --skip-runit bash $SERVICE/run

# No process set
else
echo "Execute /container/tool/py_tool/my_init --skip-runit bash"
exec /container/tool/py_tool/my_init --skip-runit bash
echo "Execute /container/tool/my_init --skip-runit bash"
exec /container/tool/my_init --skip-runit bash
fi
2 changes: 1 addition & 1 deletion src/py_tool/setuser.py → image/tool/setuser
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/python
import sys, os, pwd

if len(sys.argv) < 3:
Expand Down
11 changes: 0 additions & 11 deletions src/py_tool/build.sh

This file was deleted.

Loading

0 comments on commit c6782ce

Please sign in to comment.