Commits (1)
...@@ -35,6 +35,7 @@ env.docker_workspace = '/opt/sfl' ...@@ -35,6 +35,7 @@ env.docker_workspace = '/opt/sfl'
env.docker_site_root = '{}/src/drupal'.format(env.docker_workspace) env.docker_site_root = '{}/src/drupal'.format(env.docker_workspace)
env.bind_port = 8001 env.bind_port = 8001
env.apache_user = 'www-data' env.apache_user = 'www-data'
env.container_ip = '172.0.0.0'
# Hook commands # Hook commands
......
...@@ -147,10 +147,12 @@ def container_start(role='local'): ...@@ -147,10 +147,12 @@ def container_start(role='local'):
if env.interactive_mode: if env.interactive_mode:
h.fab_update_hosts(CONTAINER_IP, env.site_hostname) h.fab_update_hosts(CONTAINER_IP, env.site_hostname)
print(green('Docker container {}_container was build successful. ' print(green('Docker container {}_container was build successful. '
'To visit the Website open a web browser in http://{} or ' 'To visit the Website open a web browser in http://{} or '
'http://localhost:{}.'.format(env.project_name, env.site_hostname, env.bind_port))) 'http://localhost:{}.'.format(env.project_name, env.site_hostname, env.bind_port)))
h.fab_update_container_ip()
else: else:
print(red('Docker image {}/drupal not found and is a requirement to run the {}_container.' print(red('Docker image {}/drupal not found and is a requirement to run the {}_container.'
'Please, run first "fab create" in order to build the {}/drupal ' 'Please, run first "fab create" in order to build the {}/drupal '
...@@ -214,3 +216,17 @@ def image_remove(role='local'): ...@@ -214,3 +216,17 @@ def image_remove(role='local'):
print(red('Docker image {}/drupal was not found'.format(env.project_name))) print(red('Docker image {}/drupal was not found'.format(env.project_name)))
@task
@roles('docker')
def update_host():
"""
Update hostname resolution in the container.
"""
site_hostname = run("hostname")
run("sed '/{}/c\{} {} localhost.domainlocal' "
"/etc/hosts > /root/hosts.backup".format(env.container_ip, env.container_ip, site_hostname))
run("cat /root/hosts.backup > /etc/hosts")
h.fab_update_container_ip()
...@@ -26,6 +26,8 @@ from fabric.contrib.files import exists ...@@ -26,6 +26,8 @@ from fabric.contrib.files import exists
# Import socket to find the localhost IP address # Import socket to find the localhost IP address
import socket import socket
import os
# Import datetime # Import datetime
from datetime import datetime from datetime import datetime
...@@ -47,7 +49,7 @@ host_name = local("hostname", capture=True) ...@@ -47,7 +49,7 @@ host_name = local("hostname", capture=True)
# Set the env dict with the roles and the hosts # Set the env dict with the roles and the hosts
env.roledefs['local'] = ["{}@{}".format(user_name, host_name)] env.roledefs['local'] = ["{}@{}".format(user_name, host_name)]
env.roledefs['docker'] = ["root@{}".format(env.site_hostname)] env.roledefs['docker'] = ["root@{}".format(env.container_ip)]
env.builddir = path.join(env.workspace, 'build') env.builddir = path.join(env.workspace, 'build')
env.makefile = '{}/{}/{}'.format(env.builddir, env.site_profile, env.site_profile_makefile) env.makefile = '{}/{}/{}'.format(env.builddir, env.site_profile, env.site_profile_makefile)
...@@ -121,6 +123,15 @@ def fab_remove_from_hosts(site_hostname): ...@@ -121,6 +123,15 @@ def fab_remove_from_hosts(site_hostname):
local('sudo sed -i "/{}/d" /etc/hosts'.format(site_hostname)) local('sudo sed -i "/{}/d" /etc/hosts'.format(site_hostname))
def fab_update_container_ip():
container_ip = fab_run('local', 'docker inspect -f "{{{{.NetworkSettings.IPAddress}}}}" '
'{}_container'.format(env.project_name), capture=True)
local('sed -i "/env.container_ip/d" {}/local_vars.py'.format(os.path.dirname(os.path.abspath(__file__))))
local('sed -i "/# Docker auto-added container IP/a env.container_ip = \'{}\'" {}/local_vars.py'.format(''.join(container_ip), os.path.dirname(os.path.abspath(__file__))))
def fab_update_hosts(ip, site_hostname): def fab_update_hosts(ip, site_hostname):
""" """
Helper function to update the file /etc/hosts Helper function to update the file /etc/hosts
......