Commit a9e612a8 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

Merge branch 'release/3.0.2'

parents 5fca54a1 6b7034b3
......@@ -9,5 +9,6 @@ build_php56
build_php70
build_php71
build_php72
build_php73
build_bamboo
.idea
\ No newline at end of file
Copyright (c) 2013-2015 Phusion Holding B.V.
Copyright (c) 2016 Morton Jonuschat
Copyright (c) 2018 Christian Kuhn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
NAME_BASEIMAGE = typo3gmbh/baseimage
MAJOR_BASEIMAGE=3
MINOR_BASEIMAGE=0
PATCHLEVEL_BASEIMAGE=3
PATCHLEVEL_BASEIMAGE=4
FULLVERSION_BASEIMAGE=$(MAJOR_BASEIMAGE).$(MINOR_BASEIMAGE).$(PATCHLEVEL_BASEIMAGE)
SHORTVERSION_BASEIMAGE=$(MAJOR_BASEIMAGE).$(MINOR_BASEIMAGE)
......@@ -9,57 +9,64 @@ SHORTVERSION_BASEIMAGE=$(MAJOR_BASEIMAGE).$(MINOR_BASEIMAGE)
NAME_PHP53 = typo3gmbh/php53
MAJOR_PHP53=3
MINOR_PHP53=0
PATCHLEVEL_PHP53=3
PATCHLEVEL_PHP53=4
FULLVERSION_PHP53=$(MAJOR_PHP53).$(MINOR_PHP53).$(PATCHLEVEL_PHP53)
SHORTVERSION_PHP53=$(MAJOR_PHP53).$(MINOR_PHP53)
NAME_PHP54 = typo3gmbh/php54
MAJOR_PHP54=3
MINOR_PHP54=0
PATCHLEVEL_PHP54=3
PATCHLEVEL_PHP54=4
FULLVERSION_PHP54=$(MAJOR_PHP54).$(MINOR_PHP54).$(PATCHLEVEL_PHP54)
SHORTVERSION_PHP54=$(MAJOR_PHP54).$(MINOR_PHP54)
NAME_PHP55 = typo3gmbh/php55
MAJOR_PHP55=3
MINOR_PHP55=0
PATCHLEVEL_PHP55=3
PATCHLEVEL_PHP55=4
FULLVERSION_PHP55=$(MAJOR_PHP55).$(MINOR_PHP55).$(PATCHLEVEL_PHP55)
SHORTVERSION_PHP55=$(MAJOR_PHP55).$(MINOR_PHP55)
NAME_PHP56 = typo3gmbh/php56
MAJOR_PHP56=3
MINOR_PHP56=0
PATCHLEVEL_PHP56=3
PATCHLEVEL_PHP56=4
FULLVERSION_PHP56=$(MAJOR_PHP56).$(MINOR_PHP56).$(PATCHLEVEL_PHP56)
SHORTVERSION_PHP56=$(MAJOR_PHP56).$(MINOR_PHP56)
NAME_PHP70 = typo3gmbh/php70
MAJOR_PHP70=3
MINOR_PHP70=0
PATCHLEVEL_PHP70=4
PATCHLEVEL_PHP70=5
FULLVERSION_PHP70=$(MAJOR_PHP70).$(MINOR_PHP70).$(PATCHLEVEL_PHP70)
SHORTVERSION_PHP70=$(MAJOR_PHP70).$(MINOR_PHP70)
NAME_PHP71 = typo3gmbh/php71
MAJOR_PHP71=3
MINOR_PHP71=0
PATCHLEVEL_PHP71=4
PATCHLEVEL_PHP71=5
FULLVERSION_PHP71=$(MAJOR_PHP71).$(MINOR_PHP71).$(PATCHLEVEL_PHP71)
SHORTVERSION_PHP71=$(MAJOR_PHP71).$(MINOR_PHP71)
NAME_PHP72 = typo3gmbh/php72
MAJOR_PHP72=3
MINOR_PHP72=0
PATCHLEVEL_PHP72=4
PATCHLEVEL_PHP72=5
FULLVERSION_PHP72=$(MAJOR_PHP72).$(MINOR_PHP72).$(PATCHLEVEL_PHP72)
SHORTVERSION_PHP72=$(MAJOR_PHP72).$(MINOR_PHP72)
NAME_PHP73 = typo3gmbh/php73
MAJOR_PHP73=3
MINOR_PHP73=0
PATCHLEVEL_PHP73=0
FULLVERSION_PHP73=$(MAJOR_PHP73).$(MINOR_PHP73).$(PATCHLEVEL_PHP73)
SHORTVERSION_PHP73=$(MAJOR_PHP73).$(MINOR_PHP73)
NAME_BAMBOO = typo3gmbh/bamboo-remote-agent
MAJOR_BAMBOO=1
MINOR_BAMBOO=0
PATCHLEVEL_BAMBOO=3
PATCHLEVEL_BAMBOO=5
FULLVERSION_BAMBOO=$(MAJOR_BAMBOO).$(MINOR_BAMBOO).$(PATCHLEVEL_BAMBOO)
SHORTVERSION_BAMBOO=$(MAJOR_BAMBOO).$(MINOR_BAMBOO)
......@@ -76,6 +83,7 @@ SHORTVERSION_BAMBOO=$(MAJOR_BAMBOO).$(MINOR_BAMBOO)
build_php70 \
build_php71 \
build_php72 \
build_php73 \
build_bamboo \
release \
release_baseimage \
......@@ -86,6 +94,7 @@ SHORTVERSION_BAMBOO=$(MAJOR_BAMBOO).$(MINOR_BAMBOO)
release_php70 \
release_php71 \
release_php72 \
release_php73 \
release_bamboo \
clean \
clean_baseimage \
......@@ -96,6 +105,7 @@ SHORTVERSION_BAMBOO=$(MAJOR_BAMBOO).$(MINOR_BAMBOO)
clean_php70 \
clean_php71 \
clean_php72 \
clean_php73 \
clean_bamboo \
clean_images \
clean_images_baseimage \
......@@ -106,6 +116,7 @@ SHORTVERSION_BAMBOO=$(MAJOR_BAMBOO).$(MINOR_BAMBOO)
clean_images_php70 \
clean_images_php71 \
clean_images_php72 \
clean_images_php73 \
clean_images_bamboo
......@@ -125,7 +136,8 @@ build_php: \
build_php56 \
build_php70 \
build_php71 \
build_php72
build_php72 \
build_php73
release: \
release_baseimage \
......@@ -139,7 +151,8 @@ release_php: \
release_php56 \
release_php70 \
release_php71 \
release_php72
release_php72 \
release_php73
clean: \
clean_baseimage \
......@@ -150,6 +163,7 @@ clean: \
clean_php70 \
clean_php71 \
clean_php72 \
clean_php73 \
clean_bamboo
......@@ -162,6 +176,7 @@ clean_images: \
clean_images_php70 \
clean_images_php71 \
clean_images_php72 \
clean_images_php73 \
clean_images_bamboo
......@@ -358,6 +373,30 @@ clean_images_php72:
docker rmi $(NAME_PHP72):$(FULLVERSION_PHP72) || true
build_php73: build_baseimage
rm -rf build_php73
cp -pR php73 build_php73
docker build -t $(NAME_PHP73):$(FULLVERSION_PHP73) build_php73
docker tag $(NAME_PHP73):$(FULLVERSION_PHP73) $(NAME_PHP73):$(SHORTVERSION_PHP73)
release_php73:
@if ! docker images $(NAME_PHP73) | awk '{ print $$2 }' | grep -q -F $(FULLVERSION_PHP73); then \
echo "$(NAME_PHP73) version $(FULLVERSION_PHP73) is not yet built. Please run 'make build'"; false; \
fi
docker tag $(NAME_PHP73):$(FULLVERSION_PHP73) $(NAME_PHP73):latest
docker push $(NAME_PHP73):latest
docker push $(NAME_PHP73):$(FULLVERSION_PHP73)
docker push $(NAME_PHP73):$(SHORTVERSION_PHP73)
clean_php73:
rm -rf build_php73
clean_images_php73:
docker rmi $(NAME_PHP73):latest || true
docker rmi $(NAME_PHP73):$(SHORTVERSION_PHP73) || true
docker rmi $(NAME_PHP73):$(FULLVERSION_PHP73) || true
build_bamboo: build_baseimage
rm -rf build_bamboo
......
......@@ -46,9 +46,6 @@ Users can use these images to execute unit, functional, acceptance and JS tests
identical to the core testing infrastructure. Note that some core tests need additional containers that
run a database or selenium with chrome.
Simple usage example, executing accepance tests on a fresh core clone:
### bamboo-remote-agent
......
......@@ -3,6 +3,9 @@ MAINTAINER TYPO3 GmbH <info@typo3.com>
ADD . /pd_build
RUN /pd_build/bamboo-agent.sh && \
RUN /pd_build/system_services.sh && \
/pd_build/bamboo-agent.sh && \
/pd_build/utilities.sh && \
/pd_build/finalize.sh
CMD ["/sbin/my_init"]
\ No newline at end of file
......@@ -12,4 +12,8 @@ chmod 0777 /srv/bamboo/bin
curl -SL --progress-bar https://bamboo.typo3.com/agentServer/agentInstaller/ -o /srv/bamboo-installer.jar
# Configure properties
cp -a /pd_build/config/bamboo-capabilities.properties /srv/bamboo/bin
\ No newline at end of file
cp -a /pd_build/config/bamboo-capabilities.properties /srv/bamboo/bin
# Enable agent
cp -a /pd_build/runit/bamboo-agent /etc/service/bamboo-agent
chmod 777 /etc/service/bamboo-agent
\ No newline at end of file
#!/usr/bin/python3 -u
import os, os.path, sys, stat, signal, errno, argparse, time, json, re
KILL_PROCESS_TIMEOUT = 5
KILL_ALL_PROCESSES_TIMEOUT = 5
LOG_LEVEL_ERROR = 1
LOG_LEVEL_WARN = 1
LOG_LEVEL_INFO = 2
LOG_LEVEL_DEBUG = 3
SHENV_NAME_WHITELIST_REGEX = re.compile('[^\w\-_\.]')
log_level = None
terminated_child_processes = {}
class AlarmException(Exception):
pass
def error(message):
if log_level >= LOG_LEVEL_ERROR:
sys.stderr.write("*** %s\n" % message)
def warn(message):
if log_level >= LOG_LEVEL_WARN:
sys.stderr.write("*** %s\n" % message)
def info(message):
if log_level >= LOG_LEVEL_INFO:
sys.stderr.write("*** %s\n" % message)
def debug(message):
if log_level >= LOG_LEVEL_DEBUG:
sys.stderr.write("*** %s\n" % message)
def ignore_signals_and_raise_keyboard_interrupt(signame):
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN)
raise KeyboardInterrupt(signame)
def raise_alarm_exception():
raise AlarmException('Alarm')
def listdir(path):
try:
result = os.stat(path)
except OSError:
return []
if stat.S_ISDIR(result.st_mode):
return sorted(os.listdir(path))
else:
return []
def is_exe(path):
try:
return os.path.isfile(path) and os.access(path, os.X_OK)
except OSError:
return False
def import_envvars(clear_existing_environment = True, override_existing_environment = True):
if not os.path.exists("/etc/container_environment"):
return
new_env = {}
for envfile in listdir("/etc/container_environment"):
name = os.path.basename(envfile)
with open("/etc/container_environment/" + envfile, "r") as f:
# Text files often end with a trailing newline, which we
# don't want to include in the env variable value. See
# https://github.com/phusion/baseimage-docker/pull/49
value = re.sub('\n\Z', '', f.read())
new_env[name] = value
if clear_existing_environment:
os.environ.clear()
for name, value in new_env.items():
if override_existing_environment or not name in os.environ:
os.environ[name] = value
def export_envvars(to_dir = True):
if not os.path.exists("/etc/container_environment"):
return
shell_dump = ""
for name, value in os.environ.items():
if name in ['HOME', 'USER', 'GROUP', 'UID', 'GID', 'SHELL']:
continue
if to_dir:
with open("/etc/container_environment/" + name, "w") as f:
f.write(value)
shell_dump += "export " + sanitize_shenvname(name) + "=" + shquote(value) + "\n"
with open("/etc/container_environment.sh", "w") as f:
f.write(shell_dump)
with open("/etc/container_environment.json", "w") as f:
f.write(json.dumps(dict(os.environ)))
_find_unsafe = re.compile(r'[^\w@%+=:,./-]').search
def shquote(s):
"""Return a shell-escaped version of the string *s*."""
if not s:
return "''"
if _find_unsafe(s) is None:
return s
# use single quotes, and put single quotes into double quotes
# the string $'b is then quoted as '$'"'"'b'
return "'" + s.replace("'", "'\"'\"'") + "'"
def sanitize_shenvname(s):
return re.sub(SHENV_NAME_WHITELIST_REGEX, "_", s)
# 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
# processes that have terminated).
def waitpid_reap_other_children(pid):
global terminated_child_processes
status = terminated_child_processes.get(pid)
if status:
# A previous call to waitpid_reap_other_children(),
# with an argument not equal to the current argument,
# already waited for this process. Return the status
# that was obtained back then.
del terminated_child_processes[pid]
return status
done = False
status = None
while not done:
try:
# 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:
# Save status for later.
terminated_child_processes[this_pid] = status
except OSError as e:
if e.errno == errno.ECHILD or e.errno == errno.ESRCH:
return None
else:
raise
return status
def stop_child_process(name, pid, signo = signal.SIGTERM, time_limit = KILL_PROCESS_TIMEOUT):
info("Shutting down %s (PID %d)..." % (name, pid))
try:
os.kill(pid, signo)
except OSError:
pass
signal.alarm(time_limit)
try:
try:
waitpid_reap_other_children(pid)
except OSError:
pass
except AlarmException:
warn("%s (PID %d) did not shut down in time. Forcing it to exit." % (name, pid))
try:
os.kill(pid, signal.SIGKILL)
except OSError:
pass
try:
waitpid_reap_other_children(pid)
except OSError:
pass
finally:
signal.alarm(0)
def run_command_killable(*argv):
filename = argv[0]
status = None
pid = os.spawnvp(os.P_NOWAIT, filename, argv)
try:
status = waitpid_reap_other_children(pid)
except BaseException as s:
warn("An error occurred. Aborting.")
stop_child_process(filename, pid)
raise
if status != 0:
if status is None:
error("%s exited with unknown status\n" % filename)
else:
error("%s failed with status %d\n" % (filename, os.WEXITSTATUS(status)))
sys.exit(1)
def run_command_killable_and_import_envvars(*argv):
run_command_killable(*argv)
import_envvars()
export_envvars(False)
def kill_all_processes(time_limit):
info("Killing all processes...")
try:
os.kill(-1, signal.SIGTERM)
except OSError:
pass
signal.alarm(time_limit)
try:
# Wait until no more child processes exist.
done = False
while not done:
try:
os.waitpid(-1, 0)
except OSError as e:
if e.errno == errno.ECHILD:
done = True
else:
raise
except AlarmException:
warn("Not all processes have exited in time. Forcing them to exit.")
try:
os.kill(-1, signal.SIGKILL)
except OSError:
pass
finally:
signal.alarm(0)
def run_startup_files():
# Run /etc/my_init.d/*
for name in listdir("/etc/my_init.d"):
filename = "/etc/my_init.d/" + name
if is_exe(filename):
info("Running %s..." % filename)
run_command_killable_and_import_envvars(filename)
# Run /etc/rc.local.
if is_exe("/etc/rc.local"):
info("Running /etc/rc.local...")
run_command_killable_and_import_envvars("/etc/rc.local")
def start_runit():
info("Booting runit daemon...")
pid = os.spawnl(os.P_NOWAIT, "/usr/bin/runsvdir", "/usr/bin/runsvdir",
"-P", "/etc/service")
info("Runit started as PID %d" % pid)
return pid
def wait_for_runit_or_interrupt(pid):
try:
status = waitpid_reap_other_children(pid)
return (True, status)
except KeyboardInterrupt:
return (False, None)
def shutdown_runit_services():
debug("Begin shutting down runit services...")
os.system("/usr/bin/sv down /etc/service/*")
def wait_for_runit_services():
debug("Waiting for runit services to exit...")
done = False
while not done:
done = os.system("/usr/bin/sv status /etc/service/* | grep -q '^run:'") != 0
if not done:
time.sleep(0.1)
def main(args):
import_envvars(False, False)
export_envvars()
if not args.skip_startup_files:
run_startup_files()
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:
shutdown_runit_services()
if not runit_exited:
stop_child_process("runit daemon", runit_pid)
wait_for_runit_services()
# Parse options.
parser = argparse.ArgumentParser(description = 'Initialize the system.')
parser.add_argument('main_command', metavar = 'MAIN_COMMAND', type = str, nargs = '*',
help = 'The main command to run. (default: runit)')
parser.add_argument('--skip-startup-files', dest = 'skip_startup_files',
action = 'store_const', const = True, default = False,
help = 'Skip running /etc/my_init.d/* and /etc/rc.local')
parser.add_argument('--skip-runit', dest = 'skip_runit',
action = 'store_const', const = True, default = False,
help = 'Do not run runit services')
parser.add_argument('--no-kill-all-on-exit', dest = 'kill_all_on_exit',
action = 'store_const', const = False, default = True,
help = 'Don\'t kill all processes on the system upon exiting')
parser.add_argument('--quiet', dest = 'log_level',
action = 'store_const', const = LOG_LEVEL_WARN, default = LOG_LEVEL_INFO,
help = 'Only print warnings and errors')
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)
# 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:
warn("Init system aborted.")
exit(2)
finally:
if args.kill_all_on_exit:
kill_all_processes(KILL_ALL_PROCESSES_TIMEOUT)
#!/bin/sh
exec 2>&1
/usr/bin/java -Dbamboo.home=/srv/bamboo -jar /srv/bamboo-installer.jar https://bamboo.typo3.com/agentServer -t ${BAMBOO_SECURITY_TOKEN}
\ No newline at end of file
#!/bin/bash
set -e
source /pd_build/buildconfig
set -x
# Install init process.
cp /pd_build/bin/my_init /sbin/
mkdir -p /etc/my_init.d
mkdir -p /etc/container_environment
touch /etc/container_environment.sh
touch /etc/container_environment.json
chmod 777 /etc/container_environment
chmod 777 /etc/container_environment/*
chmod 777 /etc/container_environment.sh /etc/container_environment.json
ln -s /etc/container_environment.sh /etc/profile.d/
# Install runit.
minimal_apt_get_install runit
FROM typo3gmbh/baseimage:3.0
MAINTAINER TYPO3 GmbH <info@typo3.com>
ADD . /pd_build
RUN /pd_build/enable_repos.sh && \
/pd_build/nodejs.sh && \
/pd_build/php.sh && \
/pd_build/finalize.sh
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
function minimal_apt_get_install()
{
if [[ ! -e /var/lib/apt/lists/lock ]]; then
apt-get update
fi
apt-get install -y --no-install-recommends "$@"
}
#!/bin/bash
set -e
source /pd_build/buildconfig
set -x
apt-get update
# ondrej with a php 7.3
echo deb http://ppa.launchpad.net/ondrej/php/ubuntu bionic main > /etc/apt/sources.list.d/php.list
# ondrej key - the recv-keys part takes a bit of time, so it's faster to receive multiple keys at once.