diff options
Diffstat (limited to 'hot/software-config/elements/heat-config-docker-compose')
5 files changed, 0 insertions, 284 deletions
diff --git a/hot/software-config/elements/heat-config-docker-compose/README.rst b/hot/software-config/elements/heat-config-docker-compose/README.rst deleted file mode 100644 index 1aab252..0000000 --- a/hot/software-config/elements/heat-config-docker-compose/README.rst +++ /dev/null @@ -1,18 +0,0 @@ -A hook which uses `docker-compose` to deploy containers. - -A special input 'env_files' can be used with SoftwareConfig and -StructuredConfig for docker-compose `env_file` key(s). - -if env_file keys specified in the `docker-compose.yml`, do not -exist in input_values supplied, docker-compose will throw an -error, as it can't find these files. - -Also, `--parameter-file` option can be used to pass env files from client. - -Example: - -$ openstack stack create test_stack -t example-docker-compose-template.yaml \ - --parameter-file env_file_0=./common.env \ - --parameter-file env_file_1=./apps/web.env \ - --parameter-file env_file_2=./test.env \ - --parameter-file env_file_3=./busybox.env
\ No newline at end of file diff --git a/hot/software-config/elements/heat-config-docker-compose/element-deps b/hot/software-config/elements/heat-config-docker-compose/element-deps deleted file mode 100644 index 1294080..0000000 --- a/hot/software-config/elements/heat-config-docker-compose/element-deps +++ /dev/null @@ -1,2 +0,0 @@ -os-apply-config -os-refresh-config
\ No newline at end of file diff --git a/hot/software-config/elements/heat-config-docker-compose/install.d/50-heat-config-hook-docker-compose b/hot/software-config/elements/heat-config-docker-compose/install.d/50-heat-config-hook-docker-compose deleted file mode 100755 index 69b4c8e..0000000 --- a/hot/software-config/elements/heat-config-docker-compose/install.d/50-heat-config-hook-docker-compose +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -x - -SCRIPTDIR=$(dirname $0) - -if [ -f /etc/debian_version ]; then - install-packages docker.io - update-rc.d docker.io defaults - -elif [ -f /etc/redhat-release ]; then - yum -y install docker-io - systemctl enable docker.service -fi - -pip install -U dpath docker-compose==1.4.0 - -install -D -g root -o root -m 0755 ${SCRIPTDIR}/hook-docker-compose.py /var/lib/heat-config/hooks/docker-compose
\ No newline at end of file diff --git a/hot/software-config/elements/heat-config-docker-compose/install.d/hook-docker-compose.py b/hot/software-config/elements/heat-config-docker-compose/install.d/hook-docker-compose.py deleted file mode 100755 index 9afefda..0000000 --- a/hot/software-config/elements/heat-config-docker-compose/install.d/hook-docker-compose.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env python -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import ast -import dpath -import json -import logging -import os -import six -import subprocess -import sys -import warnings -import yaml - - -WORKING_DIR = os.environ.get('HEAT_DOCKER_COMPOSE_WORKING', - '/var/lib/heat-config/heat-config-docker-compose') - -DOCKER_COMPOSE_CMD = os.environ.get('HEAT_DOCKER_COMPOSE_CMD', - 'docker-compose') - - -def prepare_dir(path): - if not os.path.isdir(path): - os.makedirs(path, 0o700) - - -def write_input_file(file_path, content): - prepare_dir(os.path.dirname(file_path)) - with os.fdopen(os.open( - file_path, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f: - f.write(content.encode('utf-8')) - - -def build_response(deploy_stdout, deploy_stderr, deploy_status_code): - return { - 'deploy_stdout': deploy_stdout, - 'deploy_stderr': deploy_stderr, - 'deploy_status_code': deploy_status_code, - } - - -def main(argv=sys.argv): - warnings.warn('This hook is deprecated, please use hooks from heat-agents ' - 'repository instead.', DeprecationWarning) - log = logging.getLogger('heat-config') - handler = logging.StreamHandler(sys.stderr) - handler.setFormatter( - logging.Formatter( - '[%(asctime)s] (%(name)s) [%(levelname)s] %(message)s')) - log.addHandler(handler) - log.setLevel('DEBUG') - - c = json.load(sys.stdin) - - input_values = dict((i['name'], i['value']) for i in c['inputs']) - - proj = os.path.join(WORKING_DIR, c.get('name')) - prepare_dir(proj) - - stdout, stderr = {}, {} - - if input_values.get('deploy_action') == 'DELETE': - json.dump(build_response(stdout, stderr, 0), sys.stdout) - return - - config = c.get('config', '') - if not config: - log.debug("No 'config' input found, nothing to do.") - json.dump(build_response(stdout, stderr, 0), sys.stdout) - return - - # convert config to dict - if not isinstance(config, dict): - config = ast.literal_eval(json.dumps(yaml.safe_load(config))) - - os.chdir(proj) - - compose_env_files = [] - for value in dpath.util.values(config, '*/env_file'): - if isinstance(value, list): - compose_env_files.extend(value) - elif isinstance(value, six.string_types): - compose_env_files.extend([value]) - - input_env_files = {} - if input_values.get('env_files'): - input_env_files = dict( - (i['file_name'], i['content']) - for i in ast.literal_eval(input_values.get('env_files'))) - - for file in compose_env_files: - if file in input_env_files.keys(): - write_input_file(file, input_env_files.get(file)) - - cmd = [ - DOCKER_COMPOSE_CMD, - 'up', - '-d', - '--no-build', - ] - - log.debug('Running %s' % cmd) - - subproc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = subproc.communicate() - - log.debug(stdout) - log.debug(stderr) - - if subproc.returncode: - log.error("Error running %s. [%s]\n" % (cmd, subproc.returncode)) - else: - log.debug('Completed %s' % cmd) - - json.dump(build_response(stdout, stderr, subproc.returncode), sys.stdout) - -if __name__ == '__main__': - sys.exit(main(sys.argv)) diff --git a/hot/software-config/elements/heat-config-docker-compose/os-refresh-config/configure.d/50-heat-config-docker-compose b/hot/software-config/elements/heat-config-docker-compose/os-refresh-config/configure.d/50-heat-config-docker-compose deleted file mode 100755 index 017c08e..0000000 --- a/hot/software-config/elements/heat-config-docker-compose/os-refresh-config/configure.d/50-heat-config-docker-compose +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import json -import logging -import os -import subprocess -import sys - -import yaml - - -CONF_FILE = os.environ.get('HEAT_SHELL_CONFIG', - '/var/run/heat-config/heat-config') - -DOCKER_COMPOSE_DIR = os.environ.get( - 'HEAT_DOCKER_COMPOSE_WORKING', - '/var/lib/heat-config/heat-config-docker-compose') - -DOCKER_COMPOSE_CMD = os.environ.get('HEAT_DOCKER_COMPOSE_CMD', - 'docker-compose') - - -def main(argv=sys.argv): - log = logging.getLogger('heat-config') - handler = logging.StreamHandler(sys.stderr) - handler.setFormatter( - logging.Formatter( - '[%(asctime)s] (%(name)s) [%(levelname)s] %(message)s')) - log.addHandler(handler) - log.setLevel('DEBUG') - - if not os.path.exists(CONF_FILE): - log.error('No config file %s' % CONF_FILE) - return 1 - - if not os.path.isdir(DOCKER_COMPOSE_DIR): - os.makedirs(DOCKER_COMPOSE_DIR, 0o700) - - try: - configs = json.load(open(CONF_FILE)) - except ValueError: - pass - - try: - cleanup_stale_projects(configs) - for c in configs: - write_compose_config(c) - except Exception as e: - log.exception(e) - - -def cleanup_stale_projects(configs): - def deployments(configs): - for c in configs: - yield c['name'] - - def compose_projects(compose_dir): - for proj in os.listdir(compose_dir): - if os.path.isfile( - os.path.join(DOCKER_COMPOSE_DIR, - '%s/docker-compose.yml' % proj)): - yield proj - - def cleanup_containers(project): - cmd = [ - DOCKER_COMPOSE_CMD, - 'kill' - ] - subproc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = subproc.communicate() - - for proj in compose_projects(DOCKER_COMPOSE_DIR): - if proj not in deployments(configs): - proj_dir = os.path.join(DOCKER_COMPOSE_DIR, proj) - os.chdir(proj_dir) - cleanup_containers(proj) - os.remove('%s/docker-compose.yml' % proj_dir) - - -def write_compose_config(c): - group = c.get('group') - if group != 'docker-compose': - return - - def prepare_dir(path): - if not os.path.isdir(path): - os.makedirs(path, 0o700) - - compose_conf = c.get('config', '') - if isinstance(compose_conf, dict): - yaml_config = yaml.safe_dump(compose_conf, default_flow_style=False) - else: - yaml_config = compose_conf - proj_dir = os.path.join(DOCKER_COMPOSE_DIR, c['name']) - prepare_dir(proj_dir) - fn = os.path.join(proj_dir, 'docker-compose.yml') - with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600), - 'w') as f: - f.write(yaml_config.encode('utf-8')) - - -if __name__ == '__main__': - sys.exit(main(sys.argv)) |