1
0
mirror of https://github.com/1C-Company/docker_fresh.git synced 2024-12-04 10:24:48 +02:00

add site sittings and other things

This commit is contained in:
WizaXxX 2020-04-09 19:31:00 +03:00
parent a6a3b8bdeb
commit a90f103af5
18 changed files with 366 additions and 139 deletions

4
.gitignore vendored
View File

@ -3,4 +3,6 @@ __pycache__/
**/.DS_Store **/.DS_Store
artifacts/ artifacts/
workdir workdir
workdir/ workdir/
test.py
.vscode/launch.json

16
.vscode/launch.json vendored
View File

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

View File

@ -1,10 +1,9 @@
server { server {
listen 443; listen 443 ssl;
server_name hosthosthost; server_name hosthosthost;
proxy_intercept_errors on; proxy_intercept_errors on;
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers RC4:HIGH:!aNULL:!MD5:!kEDH; ssl_ciphers RC4:HIGH:!aNULL:!MD5:!kEDH;
ssl_prefer_server_ciphers on; ssl_prefer_server_ciphers on;

View File

@ -1,5 +1,5 @@
user nginx; user nginx;
worker_processes worker_processes_ENV; worker_processes 2;
worker_rlimit_nofile 10240; worker_rlimit_nofile 10240;
error_log /var/log/nginx/error.log warn; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid; pid /var/run/nginx.pid;

View File

@ -9,9 +9,11 @@ services:
volumes: volumes:
- ./artifacts/db/data:/var/lib/1c/pgdata - ./artifacts/db/data:/var/lib/1c/pgdata
- ./mnt:/mnt - ./mnt:/mnt
- ../images/site/create_db.psql:/create_db_site.psql
- ../images/forum/create_db.psql:/create_db_forum.psql
nginx: nginx:
image: fresh/nginx image: nginx:stable-alpine
hostname: nginx.HOSTNAMEREPLACE hostname: nginx.HOSTNAMEREPLACE
container_name: nginx.HOSTNAMEREPLACE container_name: nginx.HOSTNAMEREPLACE
networks: networks:
@ -37,6 +39,7 @@ services:
- ./artifacts/nginx/conf/nginx.conf:/etc/nginx/nginx.conf - ./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-ssl.conf:/etc/nginx/conf.d/local-ssl.conf
- ./artifacts/nginx/conf/conf.d/local.conf://etc/nginx/conf.d/local.conf - ./artifacts/nginx/conf/conf.d/local.conf://etc/nginx/conf.d/local.conf
- ./artifacts/nginx/log:/var/log/nginx
- ./mnt:/mnt - ./mnt:/mnt
- ../certs/fullchain.pem:/etc/pki-custom/fullchain.crt - ../certs/fullchain.pem:/etc/pki-custom/fullchain.crt
- ../certs/privkey.pem:/etc/pki-custom/privkey.key - ../certs/privkey.pem:/etc/pki-custom/privkey.key

View File

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

View File

@ -1,13 +1,13 @@
FROM tomcat:7.0-jre8-alpine FROM tomcat:7.0-jre8-alpine
ENV JAVA_OPTS "${JAVA_OPTS} -Xms512m -Xmx1024m -XX:+UseParallelGC -server " ENV JAVA_OPTS "${JAVA_OPTS} -Xms512m -Xmx1024m -XX:+UseParallelGC -server "
RUN rm -rf /usr/local/tomcat/webapps/* && \ RUN rm -rf /usr/local/tomcat/webapps/* && \
mkdir -p /var/www/content/searchIndex \ mkdir -p /var/www/content/searchIndex \
mkdir -p /var/www/content/site_files mkdir -p /var/www/content/site_files
COPY ./distr/site/ROOT.war /usr/local/tomcat/webapps/ COPY ./distr/site/ROOT.war /usr/local/tomcat/webapps/
EXPOSE 8080 EXPOSE 8080
CMD ["catalina.sh", "run"] CMD ["catalina.sh", "run"]

View File

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

View File

@ -1,4 +1,6 @@
import subprocess import subprocess
import sys
from datetime import datetime
import modules.site as site import modules.site as site
import modules.centos as centos import modules.centos as centos
@ -6,30 +8,48 @@ import modules.db as db
import modules.forum as forum import modules.forum as forum
import modules.core as core import modules.core as core
import modules.gate as gate import modules.gate as gate
import modules.nginx as nginx
class colors:
GREEN = '\033[92m'
WHITE = '\033[97m'
images = [] images = []
images.append(centos.New()) # images.append(centos.New())
images.append(db.New()) # images.append(db.New())
images.append(site.New()) images.append(site.New())
images.append(forum.New()) # images.append(forum.New())
images.append(core.New()) # images.append(core.New())
images.append(gate.New()) # images.append(gate.New())
images.append(nginx.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 image in images:
for command in image.commands_before: print('Building', image.name, '...', end='\r')
print(command)
subprocess.call(' '.join(command), shell=True)
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: for command in image.commands_after:
print(command) if debug: print(command)
subprocess.call(' '.join(command), shell=True) 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)

View File

@ -7,14 +7,12 @@ def download_postgresql_connector():
command.append('-O') command.append('-O')
command.append('/out_files/postgresql.jar') command.append('/out_files/postgresql.jar')
command.append('https://jdbc.postgresql.org/download/postgresql-42.2.4.jar') command.append('https://jdbc.postgresql.org/download/postgresql-42.2.4.jar')
return command return command
def add_all_before_commands(): def add_all_before_commands():
commands = [] commands = []
commands.append(download_postgresql_connector()) commands.append(download_postgresql_connector())
return commands return commands
class New(): class New():

View File

@ -7,7 +7,6 @@ def download_onescript():
command.append('-O') command.append('-O')
command.append('/out_files/onescript.rpm') command.append('/out_files/onescript.rpm')
command.append('http://oscript.io/downloads/1_1_1/onescript-engine-1.1.1-1.fc26.noarch.rpm') command.append('http://oscript.io/downloads/1_1_1/onescript-engine-1.1.1-1.fc26.noarch.rpm')
return command return command
def unzip_platform_distr(): def unzip_platform_distr():
@ -17,7 +16,6 @@ def unzip_platform_distr():
command.append('alpine') command.append('alpine')
command.append('sh') command.append('sh')
command.append('/main_dir/get_platform.sh') command.append('/main_dir/get_platform.sh')
return command return command
@ -25,28 +23,24 @@ def add_all_before_commands():
commands = [] commands = []
commands.append(download_onescript()) commands.append(download_onescript())
commands.append(unzip_platform_distr()) commands.append(unzip_platform_distr())
return commands return commands
def delete_core_distr_files(): def delete_core_distr_files():
command = helper.new_docker_command('images/core/distr/') command = helper.new_docker_command('images/core/distr/')
command.append('alpine') command.append('alpine')
command.append('sh -c "rm -rf /out_files/*.rpm"') command.append('sh -c "rm -rf /out_files/*.rpm"')
return command return command
def delete_license_tools_files(): def delete_license_tools_files():
command = helper.new_docker_command('images/core/distr/') command = helper.new_docker_command('images/core/distr/')
command.append('alpine') command.append('alpine')
command.append('sh -c "rm -rf /out_files/license-tools"') command.append('sh -c "rm -rf /out_files/license-tools"')
return command return command
def add_all_after_commands(): def add_all_after_commands():
commands = [] commands = []
commands.append(delete_core_distr_files()) commands.append(delete_core_distr_files())
commands.append(delete_license_tools_files()) commands.append(delete_license_tools_files())
return commands return commands
class New(): class New():

View File

@ -10,7 +10,6 @@ def delete_forum_dir():
command.append('sh') command.append('sh')
command.append('-c') command.append('-c')
command.append('"rm -rf /out_files/forum"') command.append('"rm -rf /out_files/forum"')
return command return command
def unzip_forum_dir(): def unzip_forum_dir():
@ -21,7 +20,6 @@ def unzip_forum_dir():
command.append('/out_files/forum_*.zip') command.append('/out_files/forum_*.zip')
command.append('-d') command.append('-d')
command.append('/main_dir/distr/forum') command.append('/main_dir/distr/forum')
return command return command
def rename_forum_file(): def rename_forum_file():
@ -30,20 +28,17 @@ def rename_forum_file():
command.append('sh') command.append('sh')
command.append('-c') command.append('-c')
command.append('"mv /out_files/forum/forum*.war /out_files/forum/ROOT.war"') command.append('"mv /out_files/forum/forum*.war /out_files/forum/ROOT.war"')
return command return command
def add_all_before_commands(): def add_all_before_commands():
commands = [] commands = []
commands.append(unzip_forum_dir()) commands.append(unzip_forum_dir())
commands.append(rename_forum_file()) commands.append(rename_forum_file())
return commands return commands
def add_all_after_commands(): def add_all_after_commands():
commands = [] commands = []
commands.append(delete_forum_dir()) commands.append(delete_forum_dir())
return commands return commands
class New(): class New():

View File

@ -7,26 +7,22 @@ def copy_distrib_file():
command.append('alpine') command.append('alpine')
command.append('sh -c') command.append('sh -c')
command.append('"cp /out_files/appgate*.deb /main_dir/distr/appgate.deb"') command.append('"cp /out_files/appgate*.deb /main_dir/distr/appgate.deb"')
return command return command
def delete_distrib_file(): def delete_distrib_file():
command = helper.new_docker_command('images/gate/distr') command = helper.new_docker_command('images/gate/distr')
command.append('alpine') command.append('alpine')
command.append('sh -c "rm -rf /out_files/*.deb"') command.append('sh -c "rm -rf /out_files/*.deb"')
return command return command
def add_all_before_commands(): def add_all_before_commands():
commands = [] commands = []
commands.append(copy_distrib_file()) commands.append(copy_distrib_file())
return commands return commands
def add_all_after_commands(): def add_all_after_commands():
commands = [] commands = []
commands.append(delete_distrib_file()) commands.append(delete_distrib_file())
return commands return commands
class New(): class New():

View File

@ -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('\'/etc/httpd/conf/httpd.conf\'')
command.append('-descriptor') command.append('-descriptor')
command.append('\'/mnt/other-files/vrd/{}.vrd\''.format(descriptor)) command.append('\'/mnt/other-files/vrd/{}.vrd\''.format(descriptor))
return command return command
def create_ib_command(host_name, ib_name, conf_ver=''): 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('/mnt/' + ib_name + '_' + conf_ver.replace('.', '_') + '.cf')
command.append('/Out "/mnt/create_ib_' + ib_name + '.out"') command.append('/Out "/mnt/create_ib_' + ib_name + '.out"')
command.append('/DumpResult "/mnt/create_ib_' + ib_name + '.result"') command.append('/DumpResult "/mnt/create_ib_' + ib_name + '.result"')
return command return command
def install_control_ext_command(host_name, ib_name): 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('/UpdateDBCfg')
command.append('/Out "/mnt/install_control_ext_{}.out"'.format(ib_name)) command.append('/Out "/mnt/install_control_ext_{}.out"'.format(ib_name))
command.append('/DumpResult "/mnt/install_control_ext_{}.result"'.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 return command
def install_ext_command(host_name, ib_name): 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('/UpdateDBCfg')
command.append('/Out "/mnt/install_ext_{}.out"'.format(ib_name)) command.append('/Out "/mnt/install_ext_{}.out"'.format(ib_name))
command.append('/DumpResult "/mnt/install_ext_{}.result"'.format(ib_name)) command.append('/DumpResult "/mnt/install_ext_{}.result"'.format(ib_name))
return command return command
def disable_safe_mode(host_name, ib_name): 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('"/mnt/other-files/cfe/disable.epf"')
command.append('/Out "/mnt/disable_safe_mode_{}.out"'.format(ib_name)) command.append('/Out "/mnt/disable_safe_mode_{}.out"'.format(ib_name))
command.append('/DumpResult "/mnt/disable_safe_mode_{}.result"'.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 return command
def get_host_name(argv): def get_host_name(argv):

View File

@ -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 = []

View File

@ -6,7 +6,6 @@ def delete_site_dir():
command.append('rm') command.append('rm')
command.append('-rf') command.append('-rf')
command.append('/out_files/site') command.append('/out_files/site')
return command return command
def unzip_site_dir(): def unzip_site_dir():
@ -17,8 +16,7 @@ def unzip_site_dir():
command.append('unzip') command.append('unzip')
command.append('/out_files/site_*.zip') command.append('/out_files/site_*.zip')
command.append('-d') command.append('-d')
command.append('/main_dir/distr/site') command.append('/main_dir/distr/site')
return command return command
def rename_site_file(): def rename_site_file():
@ -27,20 +25,17 @@ def rename_site_file():
command.append('sh') command.append('sh')
command.append('-c') command.append('-c')
command.append('"mv /out_files/site/site*.war /out_files/site/ROOT.war"') command.append('"mv /out_files/site/site*.war /out_files/site/ROOT.war"')
return command return command
def add_all_before_commands(): def add_all_before_commands():
commands = [] commands = []
commands.append(unzip_site_dir()) commands.append(unzip_site_dir())
commands.append(rename_site_file()) commands.append(rename_site_file())
return commands return commands
def add_all_after_commands(): def add_all_after_commands():
commands = [] commands = []
commands.append(delete_site_dir()) commands.append(delete_site_dir())
return commands return commands
class New(): class New():

249
start.py
View File

@ -10,68 +10,117 @@ new_server = False
global_debug = False global_debug = False
configurations = {} configurations = {}
docker_run_str = 'docker run --rm -v {}:/out_files alpine'.format(
docker_run_str = 'docker run --rm -v {}:/out_files alpine'.format(helper.this_path) helper.this_path)
docker_compose_str = 'docker-compose -f workdir/docker-compose.yml ' docker_compose_str = 'docker-compose -f workdir/docker-compose.yml '
work_dir = '/out_files/workdir/' work_dir = '/out_files/workdir/'
work_dir_other = work_dir + 'mnt/other-files/' work_dir_other = work_dir + 'mnt/other-files/'
local_work_dir = helper.replace_sep(helper.this_path + '/workdir/') 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 = [] commands = []
if remote: commands.append(docker_run_str) if remote:
commands.append(docker_run_str)
commands.append(command) commands.append(command)
if action != '': print(action) if action != '':
if debug or global_debug: print(' '.join(commands)) 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() 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 end_time = datetime.now() - start_time
if action != '': if action != '':
print(action, 'is fihish.', 'Duration:{}'.format(end_time) if measure_duration else '') print(action, 'is fihish.', 'Duration:{}'.format(
end_time) if measure_duration else '')
@print_description
def get_configurations_data(): def get_configurations_data():
"""Get configuration data"""
# r=root, d=directories, files = files # r=root, d=directories, files = files
for r, d, files in os.walk(helper.replace_sep(local_work_dir + 'mnt')): for r, d, files in os.walk(helper.replace_sep(local_work_dir + 'mnt')):
for file in files: for file in files:
conf_key = file.split('.')[0].split('_')[0] 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=''): def prepare_new_ib(key, post_data=''):
call(' '.join(helper.create_ib_command(host_name, key, configurations[key])), call(' '.join(helper.create_ib_command(host_name, key, configurations[key])),
remote=False, remote=False,
action='creating ' + key, action='Creating ' + key,
measure_duration=True) measure_duration=True)
call(' '.join(helper.install_control_ext_command(host_name, key)), call(' '.join(helper.install_control_ext_command(host_name, key)),
remote=False, remote=False,
action='installing control extension', action='Installing control extension',
measure_duration=True) measure_duration=True)
ext_name = helper.replace_sep(local_work_dir + 'mnt/' + key + '.cfe') ext_name = helper.replace_sep(local_work_dir + 'mnt/' + key + '.cfe')
if os.path.isfile(ext_name): if os.path.isfile(ext_name):
call(' '.join(helper.install_ext_command(host_name, key)), call(' '.join(helper.install_ext_command(host_name, key)),
remote=False, remote=False,
action='installing extension', action='Installing extension',
measure_duration=True) 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 '' 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), call('docker exec web.{} curl {} -X POST http://localhost/int/{}/hs/api.1cfresh/init'.format(host_name, str_post, key),
remote=False, remote=False,
action='initialization', action='Initialization',
measure_duration=True) measure_duration=True)
@print_description
def renew_nginx_files(): def renew_nginx_files():
"""Renew nginx files"""
conf_catalog = work_dir + 'artifacts/nginx/conf/' conf_catalog = work_dir + 'artifacts/nginx/conf/'
call('mkdir -p {}'.format(conf_catalog)) call('mkdir -p {}'.format(conf_catalog))
call('sh -c \'cp -r /out_files/conf/nginx/* {}'.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/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)) call('sh -c \'sed -i \'s/hosthosthost/{}/g\' {}conf.d/*.conf\''.format(host_name, conf_catalog))
@print_description
def renew_workdir(): def renew_workdir():
"""Renew wordir"""
call('rm -rf /out_files/workdir') call('rm -rf /out_files/workdir')
call('mkdir -p {}mnt'.format(work_dir)) call('mkdir -p {}mnt'.format(work_dir))
call('mkdir -p {}artifacts'.format(work_dir)) call('mkdir -p {}artifacts'.format(work_dir))
call('sh -c "cp /out_files/distr/*.cf {}mnt/"'.format(work_dir)) call('sh -c "cp /out_files/distr/*.cf {}mnt/"'.format(work_dir))
@print_description
def renew_docker_compose(): def renew_docker_compose():
"""Renew docker-compose file"""
call('cp /out_files/docker-compose.yml /out_files/workdir/docker-compose.yml') 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)) call('sh -c "sed -i \'s/HOSTNAMEREPLACE/{}/\' {}/*.yml"'.format(host_name, work_dir))
@print_description
def renew_other_files(): def renew_other_files():
"""Renew other-files"""
call('rm -rf ' + work_dir_other) call('rm -rf ' + work_dir_other)
call('cp -r /out_files/other_files/ ' + 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/{}/\' {}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(): def publish_sevises():
"""Publish services"""
# publish a services # publish a services
call(' '.join(helper.web_publish_command(host_name, 'adm', False, 'zoneless', 'sm')), remote=False) call(' '.join(helper.web_publish_command(
call(' '.join(helper.web_publish_command(host_name, 'smtl', False, 'withzone')), remote=False) host_name, 'adm', False, 'zoneless', 'sm')), remote=False)
call(' '.join(helper.web_publish_command(host_name, 'sa', False, 'zoneless')), remote=False) call(' '.join(helper.web_publish_command(
call(' '.join(helper.web_publish_command(host_name, 'openid', False, 'openid', 'sm')), remote=False) 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 # publish int services
call(' '.join(helper.web_publish_command(host_name, 'sm', True, 'zoneless')), remote=False) call(' '.join(helper.web_publish_command(
call(' '.join(helper.web_publish_command(host_name, 'smtl', True, 'zoneless')), remote=False) host_name, 'sm', True, 'zoneless')), remote=False)
call(' '.join(helper.web_publish_command(host_name, 'sa', True, 'zoneless')), remote=False) call(' '.join(helper.web_publish_command(
call(' '.join(helper.web_publish_command(host_name, 'am', True, 'zoneless')), remote=False) host_name, 'smtl', 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(
call(' '.join(helper.web_publish_command(host_name, 'extreg', True, 'extreg', 'sm;Usr=ExtReg;Pwd=' + sup_password)), remote=False) 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 # 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) call('docker exec web.' + host_name + ' httpd -k graceful', remote=False)
@print_description
def set_full_host_name(is_new): def set_full_host_name(is_new):
"""Set full hostname"""
global host_name global host_name
if is_new: if is_new:
part_host_name = helper.get_host_name(sys.argv) 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.write(part_host_name)
f.close() f.close()
else: else:
@ -135,33 +215,96 @@ def set_full_host_name(is_new):
print('host name is', host_name) print('host name is', host_name)
# Destroy exist conteiners and network @print_description
call(docker_compose_str + 'down', False) 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 new_server = '-new' in sys.argv
global_debug = '-debug' in sys.argv global_debug = '-debug' in sys.argv
new_server = True
if new_server: if new_server:
renew_workdir() renew_workdir()
get_configurations_data() get_configurations_data()
set_full_host_name(new_server) set_full_host_name(new_server)
if new_server: if new_server:
renew_nginx_files() renew_nginx_files()
renew_docker_compose() renew_docker_compose()
renew_other_files() renew_other_files()
# start db srv ras web gate conteiners # 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: if new_server:
create_db_site()
create_db_forum()
publish_sevises() publish_sevises()
prepare_new_ib('smtl') prepare_new_ib('smtl')
prepare_new_ib('sa') prepare_new_ib('sa')
prepare_new_ib('am') 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)