diff --git a/src/travis2docker/cli.py b/src/travis2docker/cli.py index 2d0eb5b..fab3ec1 100644 --- a/src/travis2docker/cli.py +++ b/src/travis2docker/cli.py @@ -274,14 +274,6 @@ def main(return_result=False): stdout.write('\nGenerated scripts:\n%s\n' % fname_list) if deployv: stdout.write("=" * 80) - stdout.write( - '\nUsing --deployv option you will need to run the following extra step ' - 'manually after to create the container or after running 20-run.sh script' - ) - stdout.write( - '\ndocker exec -it --user=root CONTAINER ' - 'find /home/odoo -maxdepth 1 -not -user odoo -exec chown -R odoo:odoo {} \\;\n' - ) if not default_docker_image: # TODO: Add the URL to open the pipelines stdout.write( diff --git a/src/travis2docker/templates/Dockerfile_deployv b/src/travis2docker/templates/Dockerfile_deployv index 8abb1d3..34188f2 100644 --- a/src/travis2docker/templates/Dockerfile_deployv +++ b/src/travis2docker/templates/Dockerfile_deployv @@ -2,8 +2,6 @@ FROM {{ image }} ARG HOME=/home/odoo -# rm -rf /home/odoo/.ssh - {%- for src, dest in copies or [] %} COPY {{ src }} {{ dest }} {% endfor -%} @@ -43,10 +41,8 @@ RUN . /home/odoo/build.sh && \ RUN {{ step }} {% endfor %} -USER {{ user }} - # TODO: Use .profile as bash profiler by default -ENTRYPOINT /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh", "--docker"] WORKDIR $MAIN_REPO_FULL_PATH diff --git a/src/travis2docker/templates/entrypoint_deployv.sh b/src/travis2docker/templates/entrypoint_deployv.sh index 69e206b..3d260b2 100755 --- a/src/travis2docker/templates/entrypoint_deployv.sh +++ b/src/travis2docker/templates/entrypoint_deployv.sh @@ -3,11 +3,31 @@ from __future__ import print_function import os +import sys import subprocess import time import pwd +def fix_permissions(): + """Fix file permissions into the HOME directory of the odoo user. + + Since the parent image marks some directories as volumes (e.g. ~/.ssh), permissions can't be fixed during + build. + """ + if not is_root(): + return + print("* Fixing file permissions...") + chown_cmd = [ + "find", + "/home/odoo", + "-maxdepth", "1", + "-not", "-user", "odoo", + "-exec", "chown", "-Rv", "odoo:odoo", "{}", "+", + ] + result = subprocess.run(chown_cmd) + + def start_psql(): # Start postgresql service if not str2bool(os.environ.get("START_PSQL", True)): @@ -82,6 +102,10 @@ def str2bool(string): return str(string or "").lower() in ["1", "true", "yes"] +def cmd_as_user(cmd, user): + return ["sudo", "-u", user] + cmd + + def start_odoo(): if not str2bool(os.environ.get("START_ODOO", True)): return @@ -95,8 +119,8 @@ def start_odoo(): "SELECT 1 FROM res_users LIMIT 1;", ] if is_root(): - cmd = ["sudo", "-u", "odoo"] + cmd - psql_cmd = ["sudo", "-u", "postgres"] + psql_cmd + cmd = cmd_as_user(cmd, "odoo") + psql_cmd = cmd_as_user(psql_cmd, "postgres") try: subprocess.check_output(psql_cmd) @@ -119,7 +143,18 @@ def start_ssh(): subprocess.call("/etc/init.d/ssh start", shell=True) +def start_bash(): + # Start bash only if it's run as a docker entrypoint (not by the user) and Odoo was asked to don't start + if "--docker" not in sys.argv or str2bool(os.environ.get("START_ODOO", True)): + return + print("Starting shell") + cmd_bash = ["su", "odoo"] if is_root() else ["bash"] + os.execvp(cmd_bash[0], cmd_bash) + + if __name__ == "__main__": + fix_permissions() start_ssh() start_psql() start_odoo() + start_bash()