From dbc60c1cdc57b45c0d540b3a22fd4edb7794b9ba Mon Sep 17 00:00:00 2001 From: ronnyabraham Date: Thu, 1 Sep 2022 22:24:49 +0300 Subject: [PATCH 1/4] making it possible to add volumes to the docker section of the project file --- modules/docker.py | 9 ++++ modules/initialize.py | 54 +++++++++++++++++++ .../conf/docker/files/database.jinja2 | 7 +++ 3 files changed, 70 insertions(+) diff --git a/modules/docker.py b/modules/docker.py index a98cf65..d4aad8b 100644 --- a/modules/docker.py +++ b/modules/docker.py @@ -122,6 +122,15 @@ def generate(): context['database_pass'] = configuration.server.database.admin.password context['database_name'] = configuration.server.database.name + if hasattr(configuration.docker.database, 'volumes') and \ + hasattr(configuration.docker.database.volumes, 'data'): + + context['docker_volume_data_external'] = \ + configuration.docker.database.volumes.data.external + + context['docker_volume_data_internal'] = \ + configuration.docker.database.volumes.data.internal + if env.debug: for key in context.keys(): logger.debug("context[{key}] : {value}".format( diff --git a/modules/initialize.py b/modules/initialize.py index 68fbbd1..719f4b4 100644 --- a/modules/initialize.py +++ b/modules/initialize.py @@ -989,6 +989,60 @@ def _init_docker(configuration, layout, config): configuration.docker.database.container_name = \ config['docker']['database']['name'] + # + # if the project file contains a 'volumes' reference it means + # that we are using an external directory to store data + # + # normally this will be generated, ie there is no 'paths' keys + # under 'volumes.data', but if 'paths' is specified, then we + # will look for an 'external' and 'internal' paths to apply + + if 'volumes' in config['docker']['database'] and \ + 'data' in config['docker']['database']['volumes']: + + configuration.docker.database.addbranch("volumes") + configuration.docker.database.volumes.addbranch("data") + + configuration.docker.database.volumes.data.internal = \ + "/var/lib/postgresql/data" + + workingdir = "{root}/{projectname}/{branch}".format( + root=config['project']['paths']['root'], + projectname=config['project']['name'], + branch=config['project']['branch']) + + varlocation = "/var/%s/data" % config[ + 'docker']['database']['image'] + + configuration.docker.database.volumes.data.external = \ + "{workingdir}{varlocation}".format( + workingdir=workingdir, + varlocation=varlocation) +# "/home/website/ronnyabraham/staging/var/postgresql/data" + + # + # to make it a bit easier to read I'm referencing the part + # of the config dictioanry we are using + + docker_volume = config['docker']['database']['volumes'] + docker_volume_data = docker_volume['data'] + + # + # if external and internal paths were specified, then we will + # use that instead + + if docker_volume_data is not None and \ + type(docker_volume_data) is dict and \ + 'paths' in docker_volume_data: + + if 'external' in docker_volume_data['paths']: + configuration.docker.database.volumes.data.external = \ + docker_volume_data['paths']['external'] + + if 'internal' in docker_volume_data['paths']: + configuration.docker.database.volumes.data.internal = \ + docker_volume_data['paths']['internal'] + # # not sure what "service name" is for configuration.docker.database.service_name = \ diff --git a/share/templates/conf/docker/files/database.jinja2 b/share/templates/conf/docker/files/database.jinja2 index 4c46582..ec1568f 100644 --- a/share/templates/conf/docker/files/database.jinja2 +++ b/share/templates/conf/docker/files/database.jinja2 @@ -13,3 +13,10 @@ services: {{ docker_database_env_db }} : "{{ database_name }}" container_name: {{ docker_container_name }} + + {%- if docker_volume_data_external is defined %} + {% if docker_volume_data_internal is defined %} + volumes: + - {{ docker_volume_data_external }}:{{ docker_volume_data_internal }} + {% endif %} + {% endif %} From b66c1fa18f2a934858ad4541a7972bc4658fafd1 Mon Sep 17 00:00:00 2001 From: ronnyabraham Date: Fri, 2 Sep 2022 01:16:43 +0300 Subject: [PATCH 2/4] added a TIMEOUT to the docker remote up, bc it was timing out --- share/templates/conf/docker/files/database.jinja2 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/share/templates/conf/docker/files/database.jinja2 b/share/templates/conf/docker/files/database.jinja2 index ec1568f..a9fcaec 100644 --- a/share/templates/conf/docker/files/database.jinja2 +++ b/share/templates/conf/docker/files/database.jinja2 @@ -1,4 +1,4 @@ -version: "2.3.3" +version: "3.7" services: {{ docker_service_name }}: @@ -11,6 +11,9 @@ services: {{ docker_database_env_user }} : "{{ database_user }}" {{ docker_database_env_pass }} : "{{ database_pass }}" {{ docker_database_env_db }} : "{{ database_name }}" + + # this is bc compose will time out on remotes + COMPOSE_HTTP_TIMEOUT: 180 container_name: {{ docker_container_name }} From dc564de0c143954da2a1ad2c0764f276b0c9f871 Mon Sep 17 00:00:00 2001 From: ronnyabraham Date: Sun, 4 Sep 2022 00:24:18 +0300 Subject: [PATCH 3/4] fixed docker-compose so it's now 'docker compose' --- modules/deploy.py | 1 - modules/docker.py | 2 +- modules/pip.py | 6 ++++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/deploy.py b/modules/deploy.py index 85caa73..db00a82 100644 --- a/modules/deploy.py +++ b/modules/deploy.py @@ -95,7 +95,6 @@ def bootstrap(): # continue setting up the rootpath and virtualenv setup_rootpath() - setup_virtualenv() bootstrap_pip() diff --git a/modules/docker.py b/modules/docker.py index d4aad8b..2398fa0 100644 --- a/modules/docker.py +++ b/modules/docker.py @@ -200,7 +200,7 @@ under "docker" docker_service_name = configuration.docker.database.service_name dockercompose_cmd = \ - "docker-compose -f {build_path} up -d {docker_service_name}".format( + "docker compose -f {build_path} up -d {docker_service_name}".format( build_path=build_path, docker_service_name=docker_service_name ) diff --git a/modules/pip.py b/modules/pip.py index 0bcc2ef..d305ac0 100644 --- a/modules/pip.py +++ b/modules/pip.py @@ -51,8 +51,10 @@ def setup_virtualenv(python3=True): logging.debug("mkvirtualenv_cmd: %s" % mkvirtualenv_cmd) - logging.debug("with virtualenv_source(): run(\"\n\t%s\n\t\")".format( - mkvirtualenv_cmd)) + logging.debug( + "with virtualenv_source(): " + "run(\"\n\t{mkvirtualenv_cmd}\n\t\")".format( + mkvirtualenv_cmd=mkvirtualenv_cmd)) else: # run("source virtualenvwrapper.sh; mkvirtualenv " From b4954662d58c74dfeafcc4339d3c4d6675763680 Mon Sep 17 00:00:00 2001 From: ronnyabraham Date: Mon, 12 Sep 2022 14:00:05 +0300 Subject: [PATCH 4/4] got rid of some dead code --- modules/docker.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/modules/docker.py b/modules/docker.py index 2398fa0..c166c48 100644 --- a/modules/docker.py +++ b/modules/docker.py @@ -35,7 +35,6 @@ def docker_ip(): def docker_run(cmd): - from fabric.context_managers import prefix configuration = env.config if env.debug: @@ -53,21 +52,10 @@ def docker_run(cmd): if configuration.docker.database.host != 'local': _execute = executize("sudo") - if configuration.docker.machine: - docker_eval = "eval $(docker-machine env %s)" % \ - configuration.docker.machine - - with prefix(docker_eval): - if env.debug: - logger.debug("_execute(cmd): %s" % cmd) - else: - _execute(cmd) - + if env.debug: + logger.debug("_execute(cmd): %s" % cmd) else: - if env.debug: - logger.debug("_execute(cmd): %s" % cmd) - else: - _execute(cmd) + _execute(cmd) @task