Skip to content

Commit

Permalink
Update default entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
odelaere authored and duchenean committed Jun 9, 2022
1 parent 364b811 commit 46db531
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 15 deletions.
4 changes: 2 additions & 2 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[buildout]

extends =
communes.cfg
# communes-dev.cfg
# communes.cfg
communes-dev.cfg
# bep.cfg
# bep-dev.cfg
# charleroi.cfg
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-base
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ ENV ZEO_ADDRESS=zeo:8100 \

EXPOSE 8081
ENTRYPOINT ["/plone/docker-entrypoint.sh"]
CMD ["instance"]
CMD [""]
2 changes: 1 addition & 1 deletion docker/Dockerfile-demo
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ ENV ZEO_ADDRESS=zeo:8100 \

EXPOSE 8081
ENTRYPOINT ["/plone/docker-entrypoint.sh"]
CMD ["instance"]
CMD [""]
2 changes: 1 addition & 1 deletion docker/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ RUN sed -i "s/\${buildout:directory}\/var/\/data/g" *.cfg \
USER imio
EXPOSE 8081
ENTRYPOINT ["/plone/docker-entrypoint.sh"]
CMD ["instance"]
CMD [""]
2 changes: 1 addition & 1 deletion docker/Dockerfile-latest
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ ENV ZEO_ADDRESS=zeo:8100 \

EXPOSE 8081
ENTRYPOINT ["/plone/docker-entrypoint.sh"]
CMD ["instance"]
CMD [""]
1 change: 0 additions & 1 deletion docker/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ services:
# SERVICE_NAME: "worker-cron"
maintenance:
image: imiobe/iadelib:dev
command: maintenance
ports:
- "20089:8080"
networks:
Expand Down
2 changes: 0 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ services:

maintenance:
image: imiobe/iadelib:demo-latest
# command: maintenance
entrypoint: bash
ports:
- "20089:8080"
networks:
Expand Down
13 changes: 8 additions & 5 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function wait_for_cron() {
INTERVAL=5
set +e
SECONDS=0
response="$($CURL)"
tries=1
response="404"
tries=0
while [[ $response != "200" && $tries -lt $MAX_TRIES ]]
do
echo "Waiting for cron"
sleep $INTERVAL
echo "Waiting for cron"
response=$($CURL)
((tries+=1))
done
Expand Down Expand Up @@ -54,19 +54,22 @@ function start() {

trap _stop SIGTERM SIGINT
$cmd start
# ensure file xists otherwise logtail returns 1
# ensure file exists otherwise logtail returns 1
touch "/data/log/$HOSTNAME.log"
exec "$cmd" "logtail"
}

setup "$1"

PRIORIY="instance-cron instance-debug maintenance zeoserver"
if [[ "instance" == "$1" || ! $PRIORIY == *"$1"* ]]; then
if [[ "instance" == "$1" || ( ! $PRIORIY == *"$1"* && $# -gt 0 ) ]]; then
wait_for_cron "$1"
fi

case "$1" in
"")
exit 0
;;
"maintenance")
shift
echo "Executing maintenance command : '$*'"
Expand Down
1 change: 1 addition & 0 deletions lib64/python2.7/config/Makefile
1 change: 1 addition & 0 deletions lib64/python2.7/lib-dynload
1 change: 1 addition & 0 deletions lib64/python2.7/os.py
1 change: 1 addition & 0 deletions lib64/python2.7/os.pyc
190 changes: 190 additions & 0 deletions lib64/python2.7/site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# -*- coding: utf-8 -*-
"""
A simple shim module to fix up things on Python 2 only.
Note: until we setup correctly the paths we can only import built-ins.
"""
import sys


def main():
"""Patch what needed, and invoke the original site.py"""
here = __file__ # the distutils.install patterns will be injected relative to this site.py, save it here
config = read_pyvenv()
sys.real_prefix = sys.base_prefix = config["base-prefix"]
sys.base_exec_prefix = config["base-exec-prefix"]
sys.base_executable = config["base-executable"]
global_site_package_enabled = config.get("include-system-site-packages", False) == "true"
rewrite_standard_library_sys_path()
disable_user_site_package()
load_host_site(here)
if global_site_package_enabled:
add_global_site_package()
rewrite_getsitepackages(here)


def load_host_site(here):
"""trigger reload of site.py - now it will use the standard library instance that will take care of init"""
# we have a duality here, we generate the platform and pure library path based on what distutils.install specifies
# because this is what pip will be using; the host site.py though may contain it's own pattern for where the
# platform and pure library paths should exist

# notably on Ubuntu there's a patch for getsitepackages to point to
# - prefix + local/lib/pythonx.y/dist-packages
# - prefix + lib/pythonx.y/dist-packages
# while distutils.install.cmd still points both of these to
# - prefix + lib/python2.7/site-packages

# to facilitate when the two match, or not we first reload the site.py, now triggering the import of host site.py,
# as this will ensure that initialization code within host site.py runs

reload(sys.modules["site"]) # noqa # call system site.py to setup import libraries

# and then if the distutils site packages are not on the sys.path we add them via add_site_dir; note we must add
# them by invoking add_site_dir to trigger the processing of pth files

add_site_dir = sys.modules["site"].addsitedir
for path in get_site_packages_dirs(here):
add_site_dir(path)


def get_site_packages_dirs(here):
import json
import os

site_packages = r"""
["../site-packages", "../../../lib/python2.7/site-packages"]
"""

for path in json.loads(site_packages):
yield os.path.abspath(os.path.join(here, path.encode("utf-8")))


sep = "\\" if sys.platform == "win32" else "/" # no os module here yet - poor mans version


def read_pyvenv():
"""read pyvenv.cfg"""
config_file = "{}{}pyvenv.cfg".format(sys.prefix, sep)
with open(config_file) as file_handler:
lines = file_handler.readlines()
config = {}
for line in lines:
try:
split_at = line.index("=")
except ValueError:
continue # ignore bad/empty lines
else:
config[line[:split_at].strip()] = line[split_at + 1 :].strip()
return config


def rewrite_standard_library_sys_path():
"""Once this site file is loaded the standard library paths have already been set, fix them up"""
exe, prefix, exec_prefix = get_exe_prefixes(base=False)
base_exe, base_prefix, base_exec = get_exe_prefixes(base=True)
exe_dir = exe[: exe.rfind(sep)]
for at, path in enumerate(sys.path):
path = abs_path(path) # replace old sys prefix path starts with new
skip_rewrite = path == exe_dir # don't fix the current executable location, notably on Windows this gets added
skip_rewrite = skip_rewrite
if not skip_rewrite:
sys.path[at] = map_path(path, base_exe, exe_dir, exec_prefix, base_prefix, prefix, base_exec)

# the rewrite above may have changed elements from PYTHONPATH, revert these if on
if sys.flags.ignore_environment:
return
import os

python_paths = []
if "PYTHONPATH" in os.environ and os.environ["PYTHONPATH"]:
for path in os.environ["PYTHONPATH"].split(os.pathsep):
if path not in python_paths:
python_paths.append(path)
sys.path[: len(python_paths)] = python_paths


def get_exe_prefixes(base=False):
return tuple(abs_path(getattr(sys, ("base_" if base else "") + i)) for i in ("executable", "prefix", "exec_prefix"))


def abs_path(value):
values, keep = value.split(sep), []
at = len(values) - 1
while at >= 0:
if values[at] == "..":
at -= 1
else:
keep.append(values[at])
at -= 1
return sep.join(keep[::-1])


def map_path(path, base_executable, exe_dir, exec_prefix, base_prefix, prefix, base_exec_prefix):
if path_starts_with(path, exe_dir):
# content inside the exe folder needs to remap to original executables folder
orig_exe_folder = base_executable[: base_executable.rfind(sep)]
return "{}{}".format(orig_exe_folder, path[len(exe_dir) :])
elif path_starts_with(path, prefix):
return "{}{}".format(base_prefix, path[len(prefix) :])
elif path_starts_with(path, exec_prefix):
return "{}{}".format(base_exec_prefix, path[len(exec_prefix) :])
return path


def path_starts_with(directory, value):
return directory.startswith(value if value[-1] == sep else value + sep)


def disable_user_site_package():
"""Flip the switch on enable user site package"""
# sys.flags is a c-extension type, so we cannot monkeypatch it, replace it with a python class to flip it
sys.original_flags = sys.flags

class Flags(object):
def __init__(self):
self.__dict__ = {key: getattr(sys.flags, key) for key in dir(sys.flags) if not key.startswith("_")}

sys.flags = Flags()
sys.flags.no_user_site = 1


def add_global_site_package():
"""add the global site package"""
import site

# add user site package
sys.flags = sys.original_flags # restore original
site.ENABLE_USER_SITE = None # reset user site check
# add the global site package to the path - use new prefix and delegate to site.py
orig_prefixes = None
try:
orig_prefixes = site.PREFIXES
site.PREFIXES = [sys.base_prefix, sys.base_exec_prefix]
site.main()
finally:
site.PREFIXES = orig_prefixes + site.PREFIXES


# Debian and it's derivatives patch this function. We undo the damage
def rewrite_getsitepackages(here):
site = sys.modules["site"]

site_package_dirs = get_site_packages_dirs(here)
orig_getsitepackages = site.getsitepackages

def getsitepackages():
sitepackages = orig_getsitepackages()
if sys.prefix not in site.PREFIXES or sys.exec_prefix not in site.PREFIXES:
# Someone messed with the prefixes, so we stop patching
return sitepackages
for path in site_package_dirs:
if path not in sitepackages:
sitepackages.insert(0, path)

return sitepackages

site.getsitepackages = getsitepackages


main()
Binary file added lib64/python2.7/site.pyc
Binary file not shown.
Binary file added lib64/python2.7/site.pyo
Binary file not shown.
2 changes: 1 addition & 1 deletion sources.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ imio.zamqp.pm = git ${remotes:imio}/imio.zamqp.pm.git pushurl=${remotes:imio_pus

Products.CPUtils = git ${remotes:imio}/Products.CPUtils.git pushurl=${remotes:imio_push}/Products.CPUtils.git
# used to test branches on Jenkins, leave branch=master by default
Products.PloneMeeting = git ${remotes:imio}/Products.PloneMeeting.git pushurl=${remotes:imio_push}/Products.PloneMeeting.git branch=master
Products.PloneMeeting = git ${remotes:imio}/Products.PloneMeeting.git pushurl=${remotes:imio_push}/Products.PloneMeeting.git branch=PM-3908_history_tooltip_fix
# profiles specific package
Products.MeetingCommunes = git ${remotes:imio}/Products.MeetingCommunes.git pushurl=${remotes:imio_push}/Products.MeetingCommunes.git branch=master

Expand Down

0 comments on commit 46db531

Please sign in to comment.