Merge branch 'master' of bitbucket.org:ronnyabraham/fabric

This commit is contained in:
ronnyabraham 2023-05-18 15:41:06 +03:00
commit 2bf156a25b
5 changed files with 82 additions and 20 deletions

View file

@ -95,7 +95,6 @@ def bootstrap():
# continue setting up the rootpath and virtualenv
setup_rootpath()
setup_virtualenv()
bootstrap_pip()

View file

@ -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
@ -122,6 +110,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(
@ -191,7 +188,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
)

View file

@ -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 = \

View file

@ -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 "

View file

@ -1,4 +1,4 @@
version: "2.3.3"
version: "3.7"
services:
{{ docker_service_name }}:
@ -11,5 +11,15 @@ 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 }}
{%- 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 %}