Skip to content
This repository has been archived by the owner on Aug 22, 2018. It is now read-only.

WIP: make TmDeploy compatible with Ansible Container 0.9 #10

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 45 additions & 29 deletions bin/tm_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,41 @@ def _get_group_variables(vars_dir):
variables = collections.OrderedDict()
if os.path.exists(vars_dir):
group_dirs = os.listdir(vars_dir)
for group in group_dirs:
filename = os.path.abspath(
os.path.join(vars_dir, group, 'vars.yml')
)
with open(filename) as f:
for line in f.readlines():
var_mapping = yaml.load(line)
if var_mapping is None:
continue
for k, v in var_mapping.items():
if type(v) in {list, dict}:
raise TypeError(
'Only simply key=value variables are supported.'
)
variables[k] = v
else:
group_dirs = []
for group in group_dirs:
filename = os.path.abspath(
os.path.join(vars_dir, group, 'vars.yml')
)
with open(filename) as f:
for line in f.readlines():
var_mapping = yaml.load(line)
if var_mapping is None:
continue
for k, v in var_mapping.items():
if type(v) in {list, dict}:
raise TypeError(
'Only simply key=value variables are supported.'
)
variables[k] = v
return variables


def _build_ansible_container_command(verbosity, action_command):
playbooks_dir = _get_playbooks_dir('tissuemaps')
roles_dir, vars_dir = _get_roles_and_variables_directories('tissuemaps')
project_dir = os.path.join(
project_dir = os.path.abspath(os.path.join(
playbooks_dir, '../../container/projects/tissuemaps'
)
cmd = ['ansible-container', '--project', os.path.abspath(project_dir)]
))
cmd = ['ansible-container', '--project-path', project_dir]
if os.path.exists(vars_dir):
group_dirs = os.listdir(vars_dir)
# NOTE: Ansible variables {{ }} declared in files are not expanded!
for group in group_dirs:
filename = os.path.abspath(os.path.join(vars_dir, group, 'vars.yml'))
cmd.extend(['--var-file', filename])
else:
group_dirs = []
# NOTE: Ansible variables {{ }} declared in files are not expanded!
for group in group_dirs:
filename = os.path.abspath(os.path.join(vars_dir, group, 'vars.yml'))
cmd.extend(['--var-file', filename])
if verbosity > 3:
cmd.append('--debug')
cmd.extend(action_command)
Expand Down Expand Up @@ -140,8 +144,10 @@ def _build_ansible_vm_command(verbosity, playbook, variables=dict()):
return cmd


def _run_command(command, environment):
process = subprocess.Popen(command, stdout=subprocess.PIPE, env=environment)
def _run_command(command, environment, working_dir=None):
process = subprocess.Popen(
command, stdout=subprocess.PIPE, env=environment, cwd=working_dir
)
while True:
line = process.stdout.readline()
if line != b'':
Expand All @@ -155,9 +161,13 @@ def _run_container_commands(commands):
env = dict(os.environ)
env['DOCKER_CLIENT_TIMEOUT'] = str(600)
env['COMPOSE_HTTP_TIMEOUT'] = str(600)
# FIXME: Workaround bug in ansible-container 0.9.1
working_dir = os.path.abspath(os.path.join(
_get_playbooks_dir('tissuemaps'), '../../container/projects/tissuemaps'
))
for cmd in commands:
logger.debug('command: %s', ' '.join(cmd))
_run_command(cmd, env)
_run_command(cmd, env, working_dir)


def _run_vm_commands(commands, setup_file):
Expand Down Expand Up @@ -240,10 +250,12 @@ def show_vm_setup(args):
def build_container(args):
logger.info('build container images')
roles_dir, vars_dir = _get_roles_and_variables_directories('tissuemaps')
cmd = [
'build', '--from-scratch',
'--roles-path', os.path.abspath(roles_dir)
]
cmd = ['build', '--roles-path', os.path.abspath(roles_dir)]
if args.no_cache:
cmd.append('--no-cache')
# Workaround ansible-container issue that doesn't install dependencies
# correctly in conductor container.
# cmd.append('--use-local-python')
# The following options are parsed to the "ansible-playbooks" command.
cmd.append('--')
verbosity = args.verbosity
Expand Down Expand Up @@ -372,6 +384,10 @@ if __name__ == '__main__':
description='Build container images.'
)
container_build_subparser.set_defaults(function='build_container')
container_build_subparser.add_argument(
'--from-scratch', dest='no_cache', action='store_true',
help='rerun the entire build process without using cache'
)

container_start_subparser = container_subparsers.add_parser(
'start', help='create and run containers',
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ def get_version():
include_package_data=True,
install_requires=[
'ansible>=2.2.1',
'ansible-container>=0.3.0,<=0.4',
'ansible-container>=0.9.0',
'apache-libcloud>=1.3.0',
'boto3>=1.4.1',
'docker>=2.2',
'docker-py>=1.10.6',
'PyYAML>=3.11',
'psycopg2>=2.6.1',
'shade>=1.12.1',
'whichcraft>=0.4.0'
]
)

1 change: 1 addition & 0 deletions tmdeploy/share/container/images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM ubuntu:xenial
RUN apt-get update && apt-get -y install \
aptitude \
build-essential \
sudo \
man \
git \
libssl-dev \
Expand Down
3 changes: 1 addition & 2 deletions tmdeploy/share/container/images/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ TissueMAPS base image

Extends the official "ubuntu:xenial" image with
- Essential apt packages (built-essential, wget, ...)
- Python 2.7.12
- Python 2.7
- Essential Python packages (pip, setuptools, ...)
- "tissuemaps" user with sudo permissions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are the python requirements for your Ansible Container builder.
# You do not need to include Ansible itself in this file.
psycopg2==2.7.1
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
[defaults]
ansible_user = root
become_method = dockerexec
roles_path = ../../../playbooks/tissuemaps/roles
93 changes: 0 additions & 93 deletions tmdeploy/share/container/projects/tissuemaps/ansible/main.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,51 @@
---
version: '2'

# NOTE: ansible-container doesn't support the "network" directive yet and the
# "volume" directive also has issues. Therefore, we handle this in the
# NOTE: ansible-container doesn't support the "networks" directive yet and the
# "volumes" directive also has issues. Therefore, we handle this in the
# docker-compose.yml file.

settings:

conductor_base: tissuemaps/base
project_name: tissuemaps

services:

db_master:
from: tissuemaps/base
user: postgres
expose:
- '5043'
depends_on:
- db_worker
command:
- 'dumb-init'
- '/usr/lib/postgresql/9.6/bin/postgres'
- '-D'
- '/storage/postgresql/data/9.6/master'
- '-c'
- 'config_file=/etc/postgresql/9.6/master/postgresql.conf'
roles:
- role: database-server-master

db_worker:
from: tissuemaps/base
user: postgres
expose:
- '9700'
command:
- 'dumb-init'
- '/usr/lib/postgresql/9.6/bin/postgres'
- '-D'
- '/storage/postgresql/data/9.6/worker'
- '-c'
- 'config_file=/etc/postgresql/9.6/worker/postgresql.conf'
roles:
- role: database-server-worker

web:
image: tissuemaps/base
from: tissuemaps/base
user: tissuemaps
working_dir: /home/tissuemaps
ports:
Expand All @@ -41,9 +78,15 @@ services:
- '/usr/bin/gulp'
- '--gulpfile'
- '/home/tissuemaps/tmui/src/gulpfile.js'
roles:
- role: web-server
web_user: tissuemaps
web_port: 8002
app_host: app
app_port: 5002

app:
image: tissuemaps/base
from: tissuemaps/base
user: tissuemaps
working_dir: /home/tissuemaps
expose:
Expand All @@ -58,35 +101,12 @@ services:
- 'dumb-init'
- '/home/tissuemaps/.tmaps/tm_server.sh'
- '-vv'

db_master:
image: tissuemaps/base
user: postgres
expose:
- '5432'
depends_on:
- db_worker
command:
- 'dumb-init'
- '/usr/lib/postgresql/9.6/bin/postgres'
- '-p'
- '5432'
- '-D'
- '/storage/database/master'
- '-c'
- 'config_file=/storage/database/master/postgresql.conf'

db_worker:
image: tissuemaps/base
user: postgres
expose:
- '9700'
command:
- 'dumb-init'
- '/usr/lib/postgresql/9.6/bin/postgres'
- '-p'
- '9700'
- '-D'
- '/storage/database/worker'
- '-c'
- 'config_file=/storage/database/worker/postgresql.conf'
roles:
- role: app-server
app_host: app
app_port: 5002
uwsgi_processes: 1
- role: database-client
db_host_master: db_master
db_hosts_workers:
- db_worker
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
---
dependencies:
- compute
- role: compute
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
with_items:
- start_server.sh
- stop_server.sh
when: ansible_env.ANSIBLE_CONTAINER is undefined
when: ansible_connection != 'docker'
tags:
- web

Loading