1
0
mirror of https://github.com/phusion/baseimage-docker.git synced 2026-03-26 12:29:07 +00:00

Compare commits

..

20 Commits

Author SHA1 Message Date
Travis Rowland
cd23614b27 Revert "Incrementing version to 0.9.23"
This reverts commit 914f0967b0.
2017-05-17 15:14:56 -07:00
Travis Rowland
914f0967b0 Incrementing version to 0.9.23 2017-05-17 15:12:05 -07:00
Zsolt Ero
068b4534d4 prepare pre and post shudown.d folders (#407) 2017-05-11 17:13:49 +02:00
Zsolt Ero
2a8c9ebe38 apt-get fixes (#406)
* apt-fixes

* DEBIAN_FRONTEND teletype at the end
2017-05-09 11:39:43 +02:00
Zsolt Ero
7f77348a6b pre and post shutdown scripts added (#402) 2017-05-09 10:50:59 +02:00
Zsolt Ero
9f998e1a09 more pep8 linting (#400) 2017-05-09 09:52:48 +02:00
Travis Rowland
59d209cbe8 Merge pull request #399 from josegonzalez/patch-1
Improve pep8 compliance
2017-05-08 20:46:45 -07:00
Jose Diaz-Gonzalez
7022d31858 chore: remove all E501 updates 2017-05-08 17:41:25 -06:00
Jose Diaz-Gonzalez
263b582139 feat: add newline and enforce file encoding 2017-05-08 17:23:07 -06:00
Jose Diaz-Gonzalez
f7dfb05850 refactor: improve pep8 compliance
This changeset fixes PEP8 issues, minus `E501 line too long (80 > 79 characters)`, as that should be more of a guideline than a strict rule, and harder to follow without silly refactoring.

Also removed two unused exception variables.
2017-05-08 17:07:48 -06:00
Travis Rowland
8f7fcfec33 Merge pull request #396 from xmjiao/patch-1
Suppress the status reports from "sv -w"
2017-04-22 23:46:32 -07:00
Xiangmin Jiao
b2c329af51 Suppress the status reports from "sv -w" 2017-04-22 20:46:36 -04:00
Kingdon Barrett
f012793a75 Merge pull request #395 from phusion/fix-pam-build
fixes the build
2017-04-19 20:21:17 -04:00
Kingdon Barrett
d3af157387 fixes the build
pam sources are missing (they were in main)
2017-04-19 20:11:06 -04:00
Travis Rowland
9c934771ad Merge pull request #392 from tgranqvist/master
https://github.com/phusion/baseimage-docker/issues/391
2017-04-13 01:14:01 -07:00
Tom Granqvist
7f7b164d20 Merge pull request #1 from tgranqvist/tgranqvist-patch-1
Fixing bug in my_init.shutdown_runit_services
2017-04-13 11:09:37 +03:00
Tom Granqvist
06b065782d Fixing bug in my_init.shutdown_runit_services
The os.system() call received two arguments from a typo with string formatting.
2017-04-13 11:05:39 +03:00
Travis Rowland
287e96c811 Update Makefile
Incrementing version for next release.
2017-04-11 01:31:10 -07:00
Travis Rowland
a6fd9f8b56 Merge pull request #389 from phusion/next
Release 0.9.20
2017-04-11 01:22:41 -07:00
Travis Rowland
ce6a9e0dfc Merge pull request #378 from phusion/next
Release 0.9.20
2017-03-21 04:23:33 -07:00
6 changed files with 368 additions and 299 deletions

View File

@@ -1,5 +1,5 @@
NAME = phusion/baseimage NAME = phusion/baseimage
VERSION = 0.9.21 VERSION = 0.9.22
.PHONY: all build test tag_latest release ssh .PHONY: all build test tag_latest release ssh
@@ -16,9 +16,8 @@ tag_latest:
release: test tag_latest release: test tag_latest
@if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi @if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi
@if ! head -n 1 Changelog.md | grep -q 'release date'; then echo 'Please note the release date in Changelog.md.' && false; fi
docker push $(NAME) docker push $(NAME)
@echo "*** Don't forget to create a tag. git tag $(VERSION) && git push origin $(VERSION)" @echo "*** Don't forget to create a tag by creating an official GitHub release."
ssh: ssh:
chmod 600 image/services/sshd/keys/insecure_key chmod 600 image/services/sshd/keys/insecure_key

View File

@@ -9,6 +9,8 @@ RUN /bd_build/prepare.sh && \
/bd_build/fix_pam_bug.sh && \ /bd_build/fix_pam_bug.sh && \
/bd_build/cleanup.sh /bd_build/cleanup.sh
ENV DEBIAN_FRONTEND teletype
ENV LANG en_US.UTF-8 ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8 ENV LC_ALL en_US.UTF-8

View File

@@ -1,5 +1,16 @@
#!/usr/bin/python3 -u #!/usr/bin/python3 -u
import os, os.path, sys, stat, signal, errno, argparse, time, json, re # -*- coding: utf-8 -*-
import argparse
import errno
import json
import os
import os.path
import re
import signal
import stat
import sys
import time
KILL_PROCESS_TIMEOUT = int(os.environ.get('KILL_PROCESS_TIMEOUT', 5)) KILL_PROCESS_TIMEOUT = int(os.environ.get('KILL_PROCESS_TIMEOUT', 5))
KILL_ALL_PROCESSES_TIMEOUT = int(os.environ.get('KILL_ALL_PROCESSES_TIMEOUT', 5)) KILL_ALL_PROCESSES_TIMEOUT = int(os.environ.get('KILL_ALL_PROCESSES_TIMEOUT', 5))
@@ -15,33 +26,43 @@ log_level = None
terminated_child_processes = {} terminated_child_processes = {}
_find_unsafe = re.compile(r'[^\w@%+=:,./-]').search
class AlarmException(Exception): class AlarmException(Exception):
pass pass
def error(message): def error(message):
if log_level >= LOG_LEVEL_ERROR: if log_level >= LOG_LEVEL_ERROR:
sys.stderr.write("*** %s\n" % message) sys.stderr.write("*** %s\n" % message)
def warn(message): def warn(message):
if log_level >= LOG_LEVEL_WARN: if log_level >= LOG_LEVEL_WARN:
sys.stderr.write("*** %s\n" % message) sys.stderr.write("*** %s\n" % message)
def info(message): def info(message):
if log_level >= LOG_LEVEL_INFO: if log_level >= LOG_LEVEL_INFO:
sys.stderr.write("*** %s\n" % message) sys.stderr.write("*** %s\n" % message)
def debug(message): def debug(message):
if log_level >= LOG_LEVEL_DEBUG: if log_level >= LOG_LEVEL_DEBUG:
sys.stderr.write("*** %s\n" % message) sys.stderr.write("*** %s\n" % message)
def ignore_signals_and_raise_keyboard_interrupt(signame): def ignore_signals_and_raise_keyboard_interrupt(signame):
signal.signal(signal.SIGTERM, signal.SIG_IGN) signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGINT, signal.SIG_IGN)
raise KeyboardInterrupt(signame) raise KeyboardInterrupt(signame)
def raise_alarm_exception(): def raise_alarm_exception():
raise AlarmException('Alarm') raise AlarmException('Alarm')
def listdir(path): def listdir(path):
try: try:
result = os.stat(path) result = os.stat(path)
@@ -52,12 +73,14 @@ def listdir(path):
else: else:
return [] return []
def is_exe(path): def is_exe(path):
try: try:
return os.path.isfile(path) and os.access(path, os.X_OK) return os.path.isfile(path) and os.access(path, os.X_OK)
except OSError: except OSError:
return False return False
def import_envvars(clear_existing_environment=True, override_existing_environment=True): def import_envvars(clear_existing_environment=True, override_existing_environment=True):
if not os.path.exists("/etc/container_environment"): if not os.path.exists("/etc/container_environment"):
return return
@@ -73,9 +96,10 @@ def import_envvars(clear_existing_environment = True, override_existing_environm
if clear_existing_environment: if clear_existing_environment:
os.environ.clear() os.environ.clear()
for name, value in new_env.items(): for name, value in new_env.items():
if override_existing_environment or not name in os.environ: if override_existing_environment or name not in os.environ:
os.environ[name] = value os.environ[name] = value
def export_envvars(to_dir=True): def export_envvars(to_dir=True):
if not os.path.exists("/etc/container_environment"): if not os.path.exists("/etc/container_environment"):
return return
@@ -92,7 +116,6 @@ def export_envvars(to_dir = True):
with open("/etc/container_environment.json", "w") as f: with open("/etc/container_environment.json", "w") as f:
f.write(json.dumps(dict(os.environ))) f.write(json.dumps(dict(os.environ)))
_find_unsafe = re.compile(r'[^\w@%+=:,./-]').search
def shquote(s): def shquote(s):
"""Return a shell-escaped version of the string *s*.""" """Return a shell-escaped version of the string *s*."""
@@ -105,12 +128,15 @@ def shquote(s):
# the string $'b is then quoted as '$'"'"'b' # the string $'b is then quoted as '$'"'"'b'
return "'" + s.replace("'", "'\"'\"'") + "'" return "'" + s.replace("'", "'\"'\"'") + "'"
def sanitize_shenvname(s): def sanitize_shenvname(s):
return re.sub(SHENV_NAME_WHITELIST_REGEX, "_", s) return re.sub(SHENV_NAME_WHITELIST_REGEX, "_", s)
# Waits for the child process with the given PID, while at the same time # Waits for the child process with the given PID, while at the same time
# reaping any other child processes that have exited (e.g. adopted child # reaping any other child processes that have exited (e.g. adopted child
# processes that have terminated). # processes that have terminated).
def waitpid_reap_other_children(pid): def waitpid_reap_other_children(pid):
global terminated_child_processes global terminated_child_processes
@@ -143,6 +169,7 @@ def waitpid_reap_other_children(pid):
raise raise
return status return status
def stop_child_process(name, pid, signo=signal.SIGTERM, time_limit=KILL_PROCESS_TIMEOUT): def stop_child_process(name, pid, signo=signal.SIGTERM, time_limit=KILL_PROCESS_TIMEOUT):
info("Shutting down %s (PID %d)..." % (name, pid)) info("Shutting down %s (PID %d)..." % (name, pid))
try: try:
@@ -168,13 +195,14 @@ def stop_child_process(name, pid, signo = signal.SIGTERM, time_limit = KILL_PROC
finally: finally:
signal.alarm(0) signal.alarm(0)
def run_command_killable(*argv): def run_command_killable(*argv):
filename = argv[0] filename = argv[0]
status = None status = None
pid = os.spawnvp(os.P_NOWAIT, filename, argv) pid = os.spawnvp(os.P_NOWAIT, filename, argv)
try: try:
status = waitpid_reap_other_children(pid) status = waitpid_reap_other_children(pid)
except BaseException as s: except BaseException:
warn("An error occurred. Aborting.") warn("An error occurred. Aborting.")
stop_child_process(filename, pid) stop_child_process(filename, pid)
raise raise
@@ -185,11 +213,13 @@ def run_command_killable(*argv):
error("%s failed with status %d\n" % (filename, os.WEXITSTATUS(status))) error("%s failed with status %d\n" % (filename, os.WEXITSTATUS(status)))
sys.exit(1) sys.exit(1)
def run_command_killable_and_import_envvars(*argv): def run_command_killable_and_import_envvars(*argv):
run_command_killable(*argv) run_command_killable(*argv)
import_envvars() import_envvars()
export_envvars(False) export_envvars(False)
def kill_all_processes(time_limit): def kill_all_processes(time_limit):
info("Killing all processes...") info("Killing all processes...")
try: try:
@@ -217,6 +247,7 @@ def kill_all_processes(time_limit):
finally: finally:
signal.alarm(0) signal.alarm(0)
def run_startup_files(): def run_startup_files():
# Run /etc/my_init.d/* # Run /etc/my_init.d/*
for name in listdir("/etc/my_init.d"): for name in listdir("/etc/my_init.d"):
@@ -230,6 +261,29 @@ def run_startup_files():
info("Running /etc/rc.local...") info("Running /etc/rc.local...")
run_command_killable_and_import_envvars("/etc/rc.local") run_command_killable_and_import_envvars("/etc/rc.local")
def run_pre_shutdown_scripts():
debug("Running pre-shutdown scripts...")
# Run /etc/my_init.pre_shutdown.d/*
for name in listdir("/etc/my_init.pre_shutdown.d"):
filename = "/etc/my_init.pre_shutdown.d/" + name
if is_exe(filename):
info("Running %s..." % filename)
run_command_killable(filename)
def run_post_shutdown_scripts():
debug("Running post-shutdown scripts...")
# Run /etc/my_init.post_shutdown.d/*
for name in listdir("/etc/my_init.post_shutdown.d"):
filename = "/etc/my_init.post_shutdown.d/" + name
if is_exe(filename):
info("Running %s..." % filename)
run_command_killable(filename)
def start_runit(): def start_runit():
info("Booting runit daemon...") info("Booting runit daemon...")
pid = os.spawnl(os.P_NOWAIT, "/usr/bin/runsvdir", "/usr/bin/runsvdir", pid = os.spawnl(os.P_NOWAIT, "/usr/bin/runsvdir", "/usr/bin/runsvdir",
@@ -237,6 +291,7 @@ def start_runit():
info("Runit started as PID %d" % pid) info("Runit started as PID %d" % pid)
return pid return pid
def wait_for_runit_or_interrupt(pid): def wait_for_runit_or_interrupt(pid):
try: try:
status = waitpid_reap_other_children(pid) status = waitpid_reap_other_children(pid)
@@ -244,10 +299,12 @@ def wait_for_runit_or_interrupt(pid):
except KeyboardInterrupt: except KeyboardInterrupt:
return (False, None) return (False, None)
def shutdown_runit_services(quiet=False): def shutdown_runit_services(quiet=False):
if not quiet: if not quiet:
debug("Begin shutting down runit services...") debug("Begin shutting down runit services...")
os.system("/usr/bin/sv -w %d down /etc/service/*", KILL_PROCESS_TIMEOUT) os.system("/usr/bin/sv -w %d down /etc/service/* > /dev/null" % KILL_PROCESS_TIMEOUT)
def wait_for_runit_services(): def wait_for_runit_services():
debug("Waiting for runit services to exit...") debug("Waiting for runit services to exit...")
@@ -263,10 +320,12 @@ def wait_for_runit_services():
# services. # services.
shutdown_runit_services(True) shutdown_runit_services(True)
def install_insecure_key(): def install_insecure_key():
info("Installing insecure SSH key for user root") info("Installing insecure SSH key for user root")
run_command_killable("/usr/sbin/enable_insecure_key") run_command_killable("/usr/sbin/enable_insecure_key")
def main(args): def main(args):
import_envvars(False, False) import_envvars(False, False)
export_envvars() export_envvars()
@@ -307,17 +366,19 @@ def main(args):
except KeyboardInterrupt: except KeyboardInterrupt:
stop_child_process(args.main_command[0], pid) stop_child_process(args.main_command[0], pid)
raise raise
except BaseException as s: except BaseException:
warn("An error occurred. Aborting.") warn("An error occurred. Aborting.")
stop_child_process(args.main_command[0], pid) stop_child_process(args.main_command[0], pid)
raise raise
sys.exit(exit_status) sys.exit(exit_status)
finally: finally:
if not args.skip_runit: if not args.skip_runit:
run_pre_shutdown_scripts()
shutdown_runit_services() shutdown_runit_services()
if not runit_exited: if not runit_exited:
stop_child_process("runit daemon", runit_pid) stop_child_process("runit daemon", runit_pid)
wait_for_runit_services() wait_for_runit_services()
run_post_shutdown_scripts()
# Parse options. # Parse options.
parser = argparse.ArgumentParser(description='Initialize the system.') parser = argparse.ArgumentParser(description='Initialize the system.')

View File

@@ -1,4 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
''' '''
Copyright (c) 2013-2015 Phusion Holding B.V. Copyright (c) 2013-2015 Phusion Holding B.V.

View File

@@ -10,7 +10,8 @@ export INITRD=no
mkdir -p /etc/container_environment mkdir -p /etc/container_environment
echo -n no > /etc/container_environment/INITRD echo -n no > /etc/container_environment/INITRD
## Enable Ubuntu Universe and Multiverse. ## Enable Ubuntu Universe, Multiverse, and deb-src for main.
sed -i 's/^#\s*\(deb.*main restricted\)$/\1/g' /etc/apt/sources.list
sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
sed -i 's/^#\s*\(deb.*multiverse\)$/\1/g' /etc/apt/sources.list sed -i 's/^#\s*\(deb.*multiverse\)$/\1/g' /etc/apt/sources.list
apt-get update apt-get update
@@ -27,6 +28,9 @@ ln -sf /bin/true /sbin/initctl
dpkg-divert --local --rename --add /usr/bin/ischroot dpkg-divert --local --rename --add /usr/bin/ischroot
ln -sf /bin/true /usr/bin/ischroot ln -sf /bin/true /usr/bin/ischroot
# apt-utils fix for Ubuntu 16.04
$minimal_apt_get_install apt-utils
## Install HTTPS support for APT. ## Install HTTPS support for APT.
$minimal_apt_get_install apt-transport-https ca-certificates $minimal_apt_get_install apt-transport-https ca-certificates
@@ -34,7 +38,7 @@ $minimal_apt_get_install apt-transport-https ca-certificates
$minimal_apt_get_install software-properties-common $minimal_apt_get_install software-properties-common
## Upgrade all packages. ## Upgrade all packages.
apt-get dist-upgrade -y --no-install-recommends apt-get dist-upgrade -y --no-install-recommends -o Dpkg::Options::="--force-confold"
## Fix locale. ## Fix locale.
$minimal_apt_get_install language-pack-en $minimal_apt_get_install language-pack-en

View File

@@ -6,6 +6,8 @@ set -x
## Install init process. ## Install init process.
cp /bd_build/bin/my_init /sbin/ cp /bd_build/bin/my_init /sbin/
mkdir -p /etc/my_init.d mkdir -p /etc/my_init.d
mkdir -p /etc/my_init.pre_shutdown.d
mkdir -p /etc/my_init.post_shutdown.d
mkdir -p /etc/container_environment mkdir -p /etc/container_environment
touch /etc/container_environment.sh touch /etc/container_environment.sh
touch /etc/container_environment.json touch /etc/container_environment.json