diff --git a/.gitignore b/.gitignore index b1e4641..d8013b6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ __pycache__/ **/.DS_Store artifacts/ workdir -workdir/ \ No newline at end of file +workdir/ +test.py +.vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 942bdfb..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Текущий файл", - "type": "python", - "args": ["-h", "test-ikoz"], - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - } - ] -} \ No newline at end of file diff --git a/conf/nginx/conf.d/local-ssl.conf b/conf/nginx/conf.d/local-ssl.conf index 69e7629..164e70c 100644 --- a/conf/nginx/conf.d/local-ssl.conf +++ b/conf/nginx/conf.d/local-ssl.conf @@ -1,10 +1,9 @@ server { - listen 443; + listen 443 ssl; server_name hosthosthost; proxy_intercept_errors on; - ssl on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers RC4:HIGH:!aNULL:!MD5:!kEDH; ssl_prefer_server_ciphers on; diff --git a/conf/nginx/nginx.conf b/conf/nginx/nginx.conf index 3ecd3de..f9a2eb4 100644 --- a/conf/nginx/nginx.conf +++ b/conf/nginx/nginx.conf @@ -1,5 +1,5 @@ user nginx; -worker_processes worker_processes_ENV; +worker_processes 2; worker_rlimit_nofile 10240; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; diff --git a/docker-compose.yml b/docker-compose.yml index fdd34a3..8484d7a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,9 +9,11 @@ services: volumes: - ./artifacts/db/data:/var/lib/1c/pgdata - ./mnt:/mnt + - ../images/site/create_db.psql:/create_db_site.psql + - ../images/forum/create_db.psql:/create_db_forum.psql nginx: - image: fresh/nginx + image: nginx:stable-alpine hostname: nginx.HOSTNAMEREPLACE container_name: nginx.HOSTNAMEREPLACE networks: @@ -37,6 +39,7 @@ services: - ./artifacts/nginx/conf/nginx.conf:/etc/nginx/nginx.conf - ./artifacts/nginx/conf/conf.d/local-ssl.conf:/etc/nginx/conf.d/local-ssl.conf - ./artifacts/nginx/conf/conf.d/local.conf://etc/nginx/conf.d/local.conf + - ./artifacts/nginx/log:/var/log/nginx - ./mnt:/mnt - ../certs/fullchain.pem:/etc/pki-custom/fullchain.crt - ../certs/privkey.pem:/etc/pki-custom/privkey.key diff --git a/images/forum/create_db.psql b/images/forum/create_db.psql new file mode 100644 index 0000000..126ee32 --- /dev/null +++ b/images/forum/create_db.psql @@ -0,0 +1,4 @@ +CREATE DATABASE forum ENCODING='UTF8' LC_CTYPE='ru_RU.utf8'; +CREATE USER forum WITH PASSWORD '12345Qwerty'; +ALTER DATABASE forum OWNER TO forum; +GRANT ALL PRIVILEGES ON DATABASE forum TO forum; diff --git a/images/site/Dockerfile b/images/site/Dockerfile index 4363f5a..e3d7640 100644 --- a/images/site/Dockerfile +++ b/images/site/Dockerfile @@ -1,13 +1,13 @@ -FROM tomcat:7.0-jre8-alpine - -ENV JAVA_OPTS "${JAVA_OPTS} -Xms512m -Xmx1024m -XX:+UseParallelGC -server " - -RUN rm -rf /usr/local/tomcat/webapps/* && \ - mkdir -p /var/www/content/searchIndex \ - mkdir -p /var/www/content/site_files - -COPY ./distr/site/ROOT.war /usr/local/tomcat/webapps/ - -EXPOSE 8080 - +FROM tomcat:7.0-jre8-alpine + +ENV JAVA_OPTS "${JAVA_OPTS} -Xms512m -Xmx1024m -XX:+UseParallelGC -server " + +RUN rm -rf /usr/local/tomcat/webapps/* && \ + mkdir -p /var/www/content/searchIndex \ + mkdir -p /var/www/content/site_files + +COPY ./distr/site/ROOT.war /usr/local/tomcat/webapps/ + +EXPOSE 8080 + CMD ["catalina.sh", "run"] \ No newline at end of file diff --git a/images/site/create_db.psql b/images/site/create_db.psql new file mode 100644 index 0000000..bfcb62e --- /dev/null +++ b/images/site/create_db.psql @@ -0,0 +1,4 @@ +CREATE DATABASE site ENCODING='UTF8' LC_CTYPE='ru_RU.utf8'; +CREATE USER site WITH PASSWORD '12345Qwerty'; +ALTER DATABASE site OWNER TO site; +GRANT ALL PRIVILEGES ON DATABASE site TO site; diff --git a/install.py b/install.py index b2ca4e3..09af3d4 100644 --- a/install.py +++ b/install.py @@ -1,4 +1,6 @@ import subprocess +import sys +from datetime import datetime import modules.site as site import modules.centos as centos @@ -6,30 +8,48 @@ import modules.db as db import modules.forum as forum import modules.core as core import modules.gate as gate -import modules.nginx as nginx + +class colors: + GREEN = '\033[92m' + WHITE = '\033[97m' images = [] -images.append(centos.New()) -images.append(db.New()) +# images.append(centos.New()) +# images.append(db.New()) images.append(site.New()) -images.append(forum.New()) -images.append(core.New()) -images.append(gate.New()) -images.append(nginx.New()) +# images.append(forum.New()) +# images.append(core.New()) +# images.append(gate.New()) +# images.append(nginx.New()) + +debug = '-debug' in sys.argv +start_time = datetime.now() +print('{}Build is starting{}'.format(colors.GREEN, colors.WHITE)) + +if debug: + stdout = None + stderr = None +else: + stdout = subprocess.PIPE + stderr = subprocess.PIPE -print('Building start') for image in images: - for command in image.commands_before: - print(command) - subprocess.call(' '.join(command), shell=True) + print('Building', image.name, '...', end='\r') - subprocess.run(['docker', 'build', '-t', 'fresh/' + image.name, 'images/' + image.name]) + for command in image.commands_before: + if debug: print(command) + subprocess.call(' '.join(command), shell=True, stdout=stdout, stderr=stderr) + + + subprocess.run(['docker', 'build', '-t', 'fresh/' + image.name, 'images/' + image.name], + stdout=stdout, stderr=stderr) for command in image.commands_after: - print(command) - subprocess.call(' '.join(command), shell=True) + if debug: print(command) + subprocess.call(' '.join(command), shell=True, stdout=stdout, stderr=stderr) - print('Building', image.name, 'is fihish') + print('Building', image.name , '...', '{}done'.format(colors.GREEN), colors.WHITE) -print('Building finish') +end_time = datetime.now() - start_time +print('{}Build finished{}'.format(colors.GREEN, colors.WHITE), 'Duration:', end_time) diff --git a/modules/centos.py b/modules/centos.py index 91529cf..26d6151 100644 --- a/modules/centos.py +++ b/modules/centos.py @@ -7,14 +7,12 @@ def download_postgresql_connector(): command.append('-O') command.append('/out_files/postgresql.jar') command.append('https://jdbc.postgresql.org/download/postgresql-42.2.4.jar') - return command def add_all_before_commands(): commands = [] commands.append(download_postgresql_connector()) - return commands class New(): diff --git a/modules/core.py b/modules/core.py index 188eceb..4f64183 100644 --- a/modules/core.py +++ b/modules/core.py @@ -7,7 +7,6 @@ def download_onescript(): command.append('-O') command.append('/out_files/onescript.rpm') command.append('http://oscript.io/downloads/1_1_1/onescript-engine-1.1.1-1.fc26.noarch.rpm') - return command def unzip_platform_distr(): @@ -17,7 +16,6 @@ def unzip_platform_distr(): command.append('alpine') command.append('sh') command.append('/main_dir/get_platform.sh') - return command @@ -25,28 +23,24 @@ def add_all_before_commands(): commands = [] commands.append(download_onescript()) commands.append(unzip_platform_distr()) - return commands def delete_core_distr_files(): command = helper.new_docker_command('images/core/distr/') command.append('alpine') command.append('sh -c "rm -rf /out_files/*.rpm"') - return command def delete_license_tools_files(): command = helper.new_docker_command('images/core/distr/') command.append('alpine') command.append('sh -c "rm -rf /out_files/license-tools"') - return command def add_all_after_commands(): commands = [] commands.append(delete_core_distr_files()) commands.append(delete_license_tools_files()) - return commands class New(): diff --git a/modules/forum.py b/modules/forum.py index 3d8a276..c45f21a 100644 --- a/modules/forum.py +++ b/modules/forum.py @@ -10,7 +10,6 @@ def delete_forum_dir(): command.append('sh') command.append('-c') command.append('"rm -rf /out_files/forum"') - return command def unzip_forum_dir(): @@ -21,7 +20,6 @@ def unzip_forum_dir(): command.append('/out_files/forum_*.zip') command.append('-d') command.append('/main_dir/distr/forum') - return command def rename_forum_file(): @@ -30,20 +28,17 @@ def rename_forum_file(): command.append('sh') command.append('-c') command.append('"mv /out_files/forum/forum*.war /out_files/forum/ROOT.war"') - return command def add_all_before_commands(): commands = [] commands.append(unzip_forum_dir()) commands.append(rename_forum_file()) - return commands def add_all_after_commands(): commands = [] commands.append(delete_forum_dir()) - return commands class New(): diff --git a/modules/gate.py b/modules/gate.py index fb7f60f..2e146fb 100644 --- a/modules/gate.py +++ b/modules/gate.py @@ -7,26 +7,22 @@ def copy_distrib_file(): command.append('alpine') command.append('sh -c') command.append('"cp /out_files/appgate*.deb /main_dir/distr/appgate.deb"') - return command def delete_distrib_file(): command = helper.new_docker_command('images/gate/distr') command.append('alpine') command.append('sh -c "rm -rf /out_files/*.deb"') - return command def add_all_before_commands(): commands = [] commands.append(copy_distrib_file()) - return commands def add_all_after_commands(): commands = [] commands.append(delete_distrib_file()) - return commands class New(): diff --git a/modules/helper.py b/modules/helper.py index 6779eba..585e4f0 100644 --- a/modules/helper.py +++ b/modules/helper.py @@ -51,7 +51,6 @@ def web_publish_command(host_name, conf_name, internal, descriptor, base_name='' command.append('\'/etc/httpd/conf/httpd.conf\'') command.append('-descriptor') command.append('\'/mnt/other-files/vrd/{}.vrd\''.format(descriptor)) - return command def create_ib_command(host_name, ib_name, conf_ver=''): @@ -68,7 +67,6 @@ def create_ib_command(host_name, ib_name, conf_ver=''): command.append('/mnt/' + ib_name + '_' + conf_ver.replace('.', '_') + '.cf') command.append('/Out "/mnt/create_ib_' + ib_name + '.out"') command.append('/DumpResult "/mnt/create_ib_' + ib_name + '.result"') - return command def install_control_ext_command(host_name, ib_name): @@ -88,7 +86,25 @@ def install_control_ext_command(host_name, ib_name): command.append('/UpdateDBCfg') command.append('/Out "/mnt/install_control_ext_{}.out"'.format(ib_name)) command.append('/DumpResult "/mnt/install_control_ext_{}.result"'.format(ib_name)) + return command +def install_sm_ext_command(host_name, ib_name): + command = [] + command.append('docker') + command.append('exec') + command.append('-t') + command.append('srv.' + host_name) + command.append('/opt/1C/v8.3/x86_64/1cv8') + command.append('DESIGNER') + command.append('/S') + command.append('"srv\\{}"'.format(ib_name)) + command.append('/LoadCfg') + command.append('"/mnt/other-files/cfe/УправлениеМС.cfe"') + command.append('-Extension') + command.append('"УправлениеМС"') + command.append('/UpdateDBCfg') + command.append('/Out "/mnt/install_sm_ext_{}.out"'.format(ib_name)) + command.append('/DumpResult "/mnt/install_sm_ext_{}.result"'.format(ib_name)) return command def install_ext_command(host_name, ib_name): @@ -108,7 +124,6 @@ def install_ext_command(host_name, ib_name): command.append('/UpdateDBCfg') command.append('/Out "/mnt/install_ext_{}.out"'.format(ib_name)) command.append('/DumpResult "/mnt/install_ext_{}.result"'.format(ib_name)) - return command def disable_safe_mode(host_name, ib_name): @@ -125,7 +140,93 @@ def disable_safe_mode(host_name, ib_name): command.append('"/mnt/other-files/cfe/disable.epf"') command.append('/Out "/mnt/disable_safe_mode_{}.out"'.format(ib_name)) command.append('/DumpResult "/mnt/disable_safe_mode_{}.result"'.format(ib_name)) + return command +def delete_control_extension(ib_name, host_name, user): + command = [] + command.append('docker') + command.append('exec') + command.append('-t') + command.append('web.{}'.format(host_name)) + command.append('curl') + if user != None: command.append('--user {}:'.format(user)) + command.append('-X POST') + command.append('http://localhost/int/{}/hs/api.1cfresh/delete'.format(ib_name)) + return command + +def edit_site_settings(host_name, sup_pass): + command = [] + command.append('docker exec -t web.{}'.format(host_name)) + command.append("curl") + command.append('-F propertiesMap[\'site.url\']=https://{}'.format(host_name)) + command.append('-F propertiesMap[\'site.locale\']=ru') + command.append('-F propertiesMap[\'site.media_directory\']=/var/www/content/site_files/') + command.append('-F propertiesMap[\'search.indexDir\']=/var/www/content/searchIndex/') + command.append('-F propertiesMap[\'ws.endpoint\']=http://web/int/sm/ws/Subscriber') + command.append('-F propertiesMap[\'ws.endpoint.rest\']=""') + command.append('-F propertiesMap[\'ws.endpoint.rest.timeout\']=5000') + command.append('-F propertiesMap[\'ws.publicUserName\']=Anonymous') + command.append('-F propertiesMap[\'ws.publicUserPassword\']=') + command.append('-F propertiesMap[\'ws.protectUserName\']=ProtectedUser') + command.append('-F propertiesMap[\'ws.protectUserPassword\']=') + command.append('-F propertiesMap[\'ws.am.endpoint\']=http://web/int/am/ws/Availability') + command.append('-F propertiesMap[\'ws.am.username\']=Reader') + command.append('-F propertiesMap[\'ws.am.password\']=' + sup_pass) + command.append('-F propertiesMap[\'openid.oipEndpointUrl\']=https://{}/a/openid/e1cib/oid2op'.format(host_name)) + command.append('-F propertiesMap[\'viewsProperties.forumUrl\']=https://1cfresh.sample/forum/') + command.append('-F propertiesMap[\'viewsProperties.adminApplicationUrl\']=https://{}/a/adm/'.format(host_name)) + command.append('-F propertiesMap[\'viewsProperties.mailto\']=info@1cfresh.sample') + command.append('-F propertiesMap[\'viewsProperties.supportMailto\']=support@1cfresh.sample') + command.append('-F propertiesMap[\'open.registration.ws.endpoint\']=http://web/int/sm/ws/ExternalRegistration_1_0_0_1') + command.append('-F propertiesMap[\'open.registration.user\']=ExternalRegistration') + command.append('-F propertiesMap[\'open.registration.password\']=' + sup_pass) + command.append('-F propertiesMap[\'open.registration.siteId\']=1') + command.append('-F propertiesMap[\'open.registration.sourceId\']=1') + command.append('-F submit=') + command.append('https://{}/settings/edit_settings'.format(host_name)) + return command + +def enable_manual_registration(host_name): + command = [] + command.append('docker exec -t web.{}'.format(host_name)) + command.append('curl') + command.append('-F id=25') + command.append('-F key=ManualRegistration') + command.append('-F description="Включение регистрации на сайте без выбора партнера (код приглашения высылается автоматически)"') + command.append('-F enabled=true') + command.append('-F _enabled=on') + command.append('https://{}/admin/features/25/edit'.format(host_name)) + return command + +def enable_openid(host_name): + command = [] + command.append('docker exec -t web.{}'.format(host_name)) + command.append('curl') + command.append('-F id=2') + command.append('-F key=openid') + command.append('-F description="Включение работы OpenID на сайте"') + command.append('-F enabled=true') + command.append('-F _enabled=on') + command.append('https://{}/admin/features/2/edit'.format(host_name)) + return command + +def add_solution(host_name, brief_desc, full_desc, display_order, id, possibilities, title): + command = [] + command.append('docker exec -t web.{}'.format(host_name)) + command.append('curl') + command.append('-F _enableDemo=on') + command.append('-F _showVideo=on') + command.append('-F _userVisible=on') + command.append('-F briefDescription={}'.format(brief_desc)) + command.append('-F displayOrder={}'.format(display_order)) + command.append('-F fullDescription={}'.format(full_desc)) + command.append('-F id={}'.format(id)) + command.append('-F possibilities={}'.format(possibilities)) + command.append('-F screenshotCount=0') + command.append('-F title={}'.format(title)) + command.append('-F userVisible=true') + command.append('-F videosPageTitle={}'.format(possibilities)) + command.append('https://{}/admin/solutions/add'.format(host_name)) return command def get_host_name(argv): diff --git a/modules/nginx.py b/modules/nginx.py deleted file mode 100644 index 05d9309..0000000 --- a/modules/nginx.py +++ /dev/null @@ -1,11 +0,0 @@ -import modules.helper as helper - -class New(): - - name = '' - commands_before = [] - commands_after = [] - - def __init__(self): - self.name = 'nginx' - self.commands_before = [] \ No newline at end of file diff --git a/modules/site.py b/modules/site.py index b67def4..e28e761 100644 --- a/modules/site.py +++ b/modules/site.py @@ -6,7 +6,6 @@ def delete_site_dir(): command.append('rm') command.append('-rf') command.append('/out_files/site') - return command def unzip_site_dir(): @@ -17,8 +16,7 @@ def unzip_site_dir(): command.append('unzip') command.append('/out_files/site_*.zip') command.append('-d') - command.append('/main_dir/distr/site') - + command.append('/main_dir/distr/site') return command def rename_site_file(): @@ -27,20 +25,17 @@ def rename_site_file(): command.append('sh') command.append('-c') command.append('"mv /out_files/site/site*.war /out_files/site/ROOT.war"') - return command def add_all_before_commands(): commands = [] commands.append(unzip_site_dir()) commands.append(rename_site_file()) - return commands def add_all_after_commands(): commands = [] commands.append(delete_site_dir()) - return commands class New(): diff --git a/other_files/cfe/params.json b/other_files/params.json similarity index 100% rename from other_files/cfe/params.json rename to other_files/params.json diff --git a/start.py b/start.py index 95449ad..6272c27 100644 --- a/start.py +++ b/start.py @@ -10,68 +10,117 @@ new_server = False global_debug = False configurations = {} - -docker_run_str = 'docker run --rm -v {}:/out_files alpine'.format(helper.this_path) +docker_run_str = 'docker run --rm -v {}:/out_files alpine'.format( + helper.this_path) docker_compose_str = 'docker-compose -f workdir/docker-compose.yml ' work_dir = '/out_files/workdir/' work_dir_other = work_dir + 'mnt/other-files/' local_work_dir = helper.replace_sep(helper.this_path + '/workdir/') -def call(command, remote=True, debug=False, action='', measure_duration=False): + +class colors: + GREEN = '\033[92m' + WHITE = '\033[97m' + + +def print_description(function_to_decorate): + + def wrapper(*args, **kwargs): + + if 'desc' in kwargs: + desc = kwargs['desc'] + else: + desc = '' + + print(function_to_decorate.__doc__, desc, '...', end='\r') + function_to_decorate(*args, **kwargs) + print(function_to_decorate.__doc__, + desc, '...', '{}done'.format(colors.GREEN), colors.WHITE) + return wrapper + + +def call(command, remote=True, debug=False, action='', measure_duration=False, silent=True): commands = [] - if remote: commands.append(docker_run_str) + if remote: + commands.append(docker_run_str) commands.append(command) - if action != '': print(action) - if debug or global_debug: print(' '.join(commands)) + if action != '': + print(action, end='\r') + if debug or global_debug: + print(' '.join(commands)) + + if not silent or global_debug: + stdout = None + stderr = None + else: + stdout = subprocess.PIPE + stderr = subprocess.PIPE start_time = datetime.now() - subprocess.call(' '.join(commands), shell=True) + subprocess.call(' '.join(commands), shell=True, + stdout=stdout, stderr=stderr) end_time = datetime.now() - start_time - if action != '': - print(action, 'is fihish.', 'Duration:{}'.format(end_time) if measure_duration else '') + if action != '': + print(action, 'is fihish.', 'Duration:{}'.format( + end_time) if measure_duration else '') + +@print_description def get_configurations_data(): + """Get configuration data""" # r=root, d=directories, files = files for r, d, files in os.walk(helper.replace_sep(local_work_dir + 'mnt')): for file in files: conf_key = file.split('.')[0].split('_')[0] - configurations[conf_key] = '.'.join(file.split('.')[0].split('_')).replace(conf_key + '.', '') + configurations[conf_key] = '.'.join(file.split( + '.')[0].split('_')).replace(conf_key + '.', '') + def prepare_new_ib(key, post_data=''): - call(' '.join(helper.create_ib_command(host_name, key, configurations[key])), - remote=False, - action='creating ' + key, - measure_duration=True) + call(' '.join(helper.create_ib_command(host_name, key, configurations[key])), + remote=False, + action='Creating ' + key, + measure_duration=True) - call(' '.join(helper.install_control_ext_command(host_name, key)), - remote=False, - action='installing control extension', - measure_duration=True) + call(' '.join(helper.install_control_ext_command(host_name, key)), + remote=False, + action='Installing control extension', + measure_duration=True) ext_name = helper.replace_sep(local_work_dir + 'mnt/' + key + '.cfe') if os.path.isfile(ext_name): - call(' '.join(helper.install_ext_command(host_name, key)), - remote=False, - action='installing extension', - measure_duration=True) + call(' '.join(helper.install_ext_command(host_name, key)), + remote=False, + action='Installing extension', + measure_duration=True) + + if key == 'sm': + call(' '.join(helper.install_sm_ext_command(host_name, key)), + remote=False, + action='Installing gate control extension', + measure_duration=True) + + call(' '.join(helper.disable_safe_mode(host_name, key)), + remote=False, + action='Disabling safe mode for extensions', + measure_duration=True) - call(' '.join(helper.disable_safe_mode(host_name, key)), - remote=False, - action='disabling safe mode for extensions', - measure_duration=True) - str_post = '-d @{}'.format(post_data) if post_data != '' else '' - call('docker exec web.{} curl {} -X POST http://localhost/int/{}/hs/api.1cfresh/init'.format(host_name, str_post, key), - remote=False, - action='initialization', - measure_duration=True) + call('docker exec web.{} curl {} -X POST http://localhost/int/{}/hs/api.1cfresh/init'.format(host_name, str_post, key), + remote=False, + action='Initialization', + measure_duration=True) + +@print_description def renew_nginx_files(): + """Renew nginx files""" + conf_catalog = work_dir + 'artifacts/nginx/conf/' call('mkdir -p {}'.format(conf_catalog)) call('sh -c \'cp -r /out_files/conf/nginx/* {}'.format(conf_catalog) + '\'') @@ -84,46 +133,77 @@ def renew_nginx_files(): call('sh -c \'sed -i \'s/sitesitesite/site.{}/g\' {}conf.d/*.conf\''.format(host_name, conf_catalog)) call('sh -c \'sed -i \'s/hosthosthost/{}/g\' {}conf.d/*.conf\''.format(host_name, conf_catalog)) + +@print_description def renew_workdir(): + """Renew wordir""" + call('rm -rf /out_files/workdir') call('mkdir -p {}mnt'.format(work_dir)) call('mkdir -p {}artifacts'.format(work_dir)) call('sh -c "cp /out_files/distr/*.cf {}mnt/"'.format(work_dir)) + +@print_description def renew_docker_compose(): + """Renew docker-compose file""" + call('cp /out_files/docker-compose.yml /out_files/workdir/docker-compose.yml') call('sh -c "sed -i \'s/HOSTNAMEREPLACE/{}/\' {}/*.yml"'.format(host_name, work_dir)) + +@print_description def renew_other_files(): + """Renew other-files""" + call('rm -rf ' + work_dir_other) call('cp -r /out_files/other_files/ ' + work_dir_other) call('sh -c "sed -i \'s/HOSTNAMEREPLACE/{}/\' {}vrd/*.vrd"'.format(host_name, work_dir_other)) - call('sh -c "sed -i \'s/HOSTNAMEREPLACE/{}/\' {}cfe/params.json"'.format(host_name, work_dir_other)) + call('sh -c "sed -i \'s/HOSTNAMEREPLACE/{}/\' {}params.json"'.format(host_name, work_dir_other)) + +@print_description def publish_sevises(): + """Publish services""" + # publish a services - call(' '.join(helper.web_publish_command(host_name, 'adm', False, 'zoneless', 'sm')), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'smtl', False, 'withzone')), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'sa', False, 'zoneless')), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'openid', False, 'openid', 'sm')), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'adm', False, 'zoneless', 'sm')), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'smtl', False, 'withzone')), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'sa', False, 'zoneless')), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'openid', False, 'openid', 'sm')), remote=False) # publish int services - call(' '.join(helper.web_publish_command(host_name, 'sm', True, 'zoneless')), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'smtl', True, 'zoneless')), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'sa', True, 'zoneless')), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'am', True, 'zoneless')), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'sc', True, 'sessioncontrol', 'sm;Usr=SessionControl;Pwd=' + sup_password)), remote=False) - call(' '.join(helper.web_publish_command(host_name, 'extreg', True, 'extreg', 'sm;Usr=ExtReg;Pwd=' + sup_password)), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'sm', True, 'zoneless')), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'smtl', True, 'zoneless')), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'sa', True, 'zoneless')), remote=False) + call(' '.join(helper.web_publish_command( + host_name, 'am', True, 'zoneless')), remote=False) + call(' '.join(helper.web_publish_command(host_name, 'sc', True, + 'sessioncontrol', 'sm;Usr=SessionControl;Pwd=' + sup_password)), remote=False) + call(' '.join(helper.web_publish_command(host_name, 'extreg', True, + 'extreg', 'sm;Usr=ExtReg;Pwd=' + sup_password)), remote=False) # restart Apache - call('docker exec web.' + host_name + ' chown -R usr1cv8:grp1cv8 /var/www', remote=False) + call('docker exec web.' + host_name + + ' chown -R usr1cv8:grp1cv8 /var/www', remote=False) call('docker exec web.' + host_name + ' httpd -k graceful', remote=False) + +@print_description def set_full_host_name(is_new): + """Set full hostname""" + global host_name if is_new: part_host_name = helper.get_host_name(sys.argv) - f = open(local_work_dir + 'hostname', 'x+') + f = open(local_work_dir + 'hostname', 'x+') f.write(part_host_name) f.close() else: @@ -135,33 +215,96 @@ def set_full_host_name(is_new): print('host name is', host_name) -# Destroy exist conteiners and network -call(docker_compose_str + 'down', False) +@print_description +def create_db_site(): + """Create db for site""" + + call('docker exec -t db.{} sh -c \'/usr/bin/psql -U postgres -f {}'.format(host_name, '/create_db_site.psql\''), + remote=False) + + +@print_description +def create_db_forum(): + """Create db for forum""" + + call('docker exec -t db.{} sh -c \'/usr/bin/psql -U postgres -f {}'.format(host_name, '/create_db_forum.psql\''), + remote=False) + + +@print_description +def delete_control_extension(ib_name, user, desc): + """Delete control extension""" + + call(' '.join(helper.delete_control_extension(ib_name, host_name, user)), remote=False) + + +@print_description +def configurate_site(): + """Configurate site settings""" + + call(' '.join(helper.edit_site_settings(host_name, sup_password)), remote=False) + call('curl https://{}/settings/finish_configuration'.format(host_name), remote=False) + call(' '.join(helper.enable_manual_registration(host_name)), remote=False) + call(' '.join(helper.enable_openid(host_name)), remote=False) + call(' '.join(helper.add_solution( + host_name=host_name, + brief_desc='БТС', + full_desc='БТС', + display_order=0, + id='smtl', + possibilities='БТС', + title='Библиотека технологии сервиса' + )), remote=False) + + +@print_description +def init_gate(): + """Initialization gate""" + + call('docker exec -t web.{0} curl --user Администратор: https://{0}/a/adm/hs/docker_control/update_appgate'.format(host_name), + remote=False) + +global_start_time = datetime.now() +print('{}Fresh is starting{}'.format(colors.GREEN, colors.WHITE)) +# destroy exist conteiners and network +call(docker_compose_str + 'down', remote=False, silent=False) new_server = '-new' in sys.argv global_debug = '-debug' in sys.argv -new_server = True + if new_server: renew_workdir() get_configurations_data() - + set_full_host_name(new_server) -if new_server: +if new_server: renew_nginx_files() renew_docker_compose() renew_other_files() - + # start db srv ras web gate conteiners -call(docker_compose_str + 'up -d db srv ras web gate', remote=False) +call(docker_compose_str + 'up -d db srv ras web gate', remote=False, silent=False) if new_server: + create_db_site() + create_db_forum() publish_sevises() prepare_new_ib('smtl') prepare_new_ib('sa') prepare_new_ib('am') - prepare_new_ib('sm', post_data='/mnt/other-files/cfe/params.json') - + prepare_new_ib('sm', post_data='/mnt/other-files/params.json') +# start site forum nginx conteiners +call(docker_compose_str + 'up -d site forum nginx', remote=False, silent=False) +if new_server: + delete_control_extension('smtl', 'Admin', 'smtl') + delete_control_extension('am', 'Администратор', 'am') + delete_control_extension('sm', 'Администратор', 'sm') + delete_control_extension('sa', None, 'sa') + configurate_site() + init_gate() +global_end_time = datetime.now() - global_start_time +print('{}Fresh started{}'.format(colors.GREEN, colors.WHITE), 'Duration:', global_end_time)