From 81199f336502eb914aa26ffa8c9142d15dff520e Mon Sep 17 00:00:00 2001 From: WizaXxX Date: Fri, 12 Mar 2021 22:11:58 +0300 Subject: [PATCH] =?UTF-8?q?=20=D0=90=D0=B4=D0=B0=D0=BF=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B9=20=D0=BF=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20fix=20#14=20(#15)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update from https://github.com/1C-Company/docker_fresh (#21) * renew sert * renew sert * renew sert * renew sert * Исправил опечатки в Readme * renew sert * renew sert Co-authored-by: Юрий * Адаптировал скрипты для новых версий платформы (#22) Co-authored-by: Юрий --- docker-compose_pattern.yml | 6 +++--- images/core/dumper.py | 20 +++++++++++++++++--- images/core/entrypoint.sh | 10 ++++++---- images/core/get_platform.sh | 14 ++------------ modules/helper.py | 21 ++++++++++++++------- start.py | 16 +++++++++++++++- 6 files changed, 57 insertions(+), 30 deletions(-) diff --git a/docker-compose_pattern.yml b/docker-compose_pattern.yml index 545b54a..e5b9787 100644 --- a/docker-compose_pattern.yml +++ b/docker-compose_pattern.yml @@ -77,7 +77,7 @@ services: - ./mnt:/mnt - /tmp/.aksusb:/tmp/.aksusb - ../licenses_1c:/var/1C/licenses - - ../conf/core:/opt/1C/v8.3/x86_64/conf + - ../conf/core:PATH_TO_1C_REPLACEconf ports: - 1540-1541:1540-1541 @@ -92,11 +92,11 @@ services: image: fresh/core hostname: ras.HOSTNAMEREPLACE container_name: ras.HOSTNAMEREPLACE - command: /opt/1C/v8.3/x86_64/ras cluster --port=1545 srv:1540 + command: PATH_TO_1C_REPLACEras cluster --port=1545 srv:1540 volumes: - ./artifacts/ras/log:/var/log/1c - ./mnt:/mnt - - ../images/core/conf/logcfg.xml:/opt/1C/v8.3/x86_64/conf/logcfg.xml + - ../images/core/conf/logcfg.xml:PATH_TO_1C_REPLACEconf/logcfg.xml ports: - 1545:1545 diff --git a/images/core/dumper.py b/images/core/dumper.py index 6ae5570..6fd83c4 100644 --- a/images/core/dumper.py +++ b/images/core/dumper.py @@ -12,6 +12,8 @@ import time import uuid +path_to_1c = '' + # define regexps regex_process_pid = re.compile(r'/([^/.]+?)\.(\d+?)\.(\d+?)\.core') regex_offset = re.compile(r'#0\s+?([\dxa-f]+?)\s') @@ -31,6 +33,10 @@ def run_shell(cmd): p = subprocess.Popen(cmd, shell=True, stdin=pipe, stdout=pipe, stderr=pipe, close_fds=True, cwd='/') return p.stdout.read(), p.stderr.read() +def run_shell_get_stdout(cmd): + pipe = subprocess.PIPE + p = subprocess.Popen(cmd, shell=True, stdin=pipe, stdout=pipe, stderr=pipe, close_fds=True, cwd='/') + return p.stdout.read() def run_shell_get_result(cmd): result = subprocess.call(cmd, shell=True) @@ -43,6 +49,14 @@ def check_size_static(core_file): size_2 = os.path.getsize(core_file) return size_1 == size_2 +def get_path_to_1c(): + global path_to_1c + if path_to_1c == '': + result = run_shell_get_stdout("find / -name '1cv8c' | sed 's/1cv8c//g' | sed 's/\.\/opt/\/opt/g'") + path_to_1c = result.decode('utf-8').strip() + return path_to_1c + + # END helper functions-------------------------------------------------------------------------------------------------- # BEGIN prepare date---------------------------------------------------------------------------------------------------- @@ -58,7 +72,7 @@ def get_pid_process_ctime(core_file): def get_platform_offset(core_file, process): # run gdb for getting offset of core - cmd = 'echo -e "bt\nexit" | gdb /opt/1C/v8.3/x86_64/' + process + ' ' + core_file + cmd = 'echo -e "bt\nexit" | gdb ' + get_path_to_1c() + process + ' ' + core_file (gdb_result, gdb_error) = run_shell(cmd) if not gdb_result: @@ -73,7 +87,7 @@ def get_platform_offset(core_file, process): offset = rez.groups()[0] offset = offset[6:-1] # getting platform version - cmd = 'strings /opt/1C/v8.3/x86_64/' + process + """ | grep -oP '[8-9]\.[3-90]\.\d\d?\.\d{2,4}' """ + cmd = 'strings ' + get_path_to_1c() + process + """ | grep -oP '[8-9]\.[3-90]\.\d\d?\.\d{2,4}' """ (ver_result, ver_error) = run_shell(cmd) if ver_result: platform = ver_result.strip() @@ -105,7 +119,7 @@ def make_libs_tar(core_file, process): if os.path.exists(libs_file): os.remove(libs_file) cmd = """echo -e "info shared\nq" | """ - cmd += """ gdb /opt/1C/v8.3/x86_64/""" + process + " " + core_file + """ 2>/dev/null | """ + cmd += """ gdb """ + get_path_to_1c() + process + " " + core_file + """ 2>/dev/null | """ cmd += """ grep 0x0000 | grep -v /opt/1C/v8.3 | grep -v ?? | perl -alne 'print $F[-1]' | """ cmd += """ while read file; do tar --dereference --append -f """ + libs_file + """ $file 2> /dev/null ; done""" stdout, stderr = run_shell(cmd) diff --git a/images/core/entrypoint.sh b/images/core/entrypoint.sh index 681c2e5..35179d5 100644 --- a/images/core/entrypoint.sh +++ b/images/core/entrypoint.sh @@ -2,15 +2,17 @@ set -e +platform_path=$(find / -name "1cv8c" | sed 's/1cv8c//g' | sed 's/\.\/opt/\/opt/g') + if [ "$1" = 'srv' ] then chown -R usr1cv8:grp1cv8 ${COREDATA} ${CORELOGS} - exec gosu usr1cv8 /opt/1C/v8.3/x86_64/ragent -debug -http /d ${COREDATA} + exec gosu usr1cv8 ${platform_path}ragent -debug -http /d ${COREDATA} elif [ "$1" = 'srv+cli' ] then ulimit -c unlimited chown -R usr1cv8:grp1cv8 ${COREDATA} ${CORELOGS} - exec gosu usr1cv8 /opt/1C/v8.3/x86_64/ragent -debug -http /d ${COREDATA} & + exec gosu usr1cv8 ${platform_path}ragent -debug -http /d ${COREDATA} & status=$? if [ $status -ne 0 ]; then echo "Failed to start ragent: $status" @@ -37,7 +39,7 @@ then elif [ "$1" = 'ras' ] then chown -R usr1cv8:grp1cv8 ${CORELOGS} - exec gosu usr1cv8 /opt/1C/v8.3/x86_64/ras cluster + exec gosu usr1cv8 ${platform_path}ras cluster elif [ "$1" = 'cli' ] then chown -R usr1cv8:grp1cv8 ${CORELOGS} @@ -54,7 +56,7 @@ elif [ "$1" = 'agent' ] then chown -R usr1cv8:grp1cv8 ${COREDATA} ${CORELOGS} ${AGENTBASEDIR} exec /usr/bin/Xvfb :99 -screen 0 1680x1050x24 -shmem & - exec /opt/1C/v8.3/x86_64/1cv8 DESIGNER /AgentMode /IBConnectionString "${INFOBASECONNECTIONSTRING}" /AgentBaseDir "${AGENTBASEDIR}" /AgentSSHHostKey "/id_rsa.key" /Visible /AgentListenAddress 0.0.0.0 + exec ${platform_path}1cv8 DESIGNER /AgentMode /IBConnectionString "${INFOBASECONNECTIONSTRING}" /AgentBaseDir "${AGENTBASEDIR}" /AgentSSHHostKey "/id_rsa.key" /Visible /AgentListenAddress 0.0.0.0 fi exec "$@" \ No newline at end of file diff --git a/images/core/get_platform.sh b/images/core/get_platform.sh index cffe8b8..9b3c5fd 100644 --- a/images/core/get_platform.sh +++ b/images/core/get_platform.sh @@ -1,15 +1,5 @@ cd /out_files -DISTR_FILE_VERSION=$(ls | grep "client" | grep -Eo "[0-9]+\_[0-9]+\_[0-9]+\_[0-9]+") -DISTR_VERSION=$(ls | grep "client" | grep -Eo "[0-9]+\_[0-9]+\_[0-9]+\_[0-9]+" | sed 's/_/./g') -DISTR_VER1=$(echo $DISTR_VERSION | cut -d '.' -f 1-3) -DISTR_VER2=$(echo $DISTR_VERSION | cut -d '.' -f 4) -common_file_name=1C_Enterprise83-common-$DISTR_VER1-$DISTR_VER2.x86_64.rpm -server_file_name=1C_Enterprise83-server-$DISTR_VER1-$DISTR_VER2.x86_64.rpm -ws_file_name=1C_Enterprise83-ws-$DISTR_VER1-$DISTR_VER2.x86_64.rpm -client_file_name=1C_Enterprise83-client-$DISTR_VER1-$DISTR_VER2.x86_64.rpm + tar -xvf client*.rpm64.tar.gz --exclude "*thin*.rpm" --exclude "*nls*.rpm" --exclude "license-tools" -C /main_dir/distr + tar -xvf rpm64_*.tar.gz --exclude "*crs*.rpm" --exclude "*nls*.rpm" -C /main_dir/distr -tar -xvf client_$DISTR_FILE_VERSION.rpm64.tar.gz $client_file_name -C /main_dir/distr -tar -xvf rpm64_$DISTR_FILE_VERSION.tar.gz $common_file_name $server_file_name $ws_file_name -C /main_dir/distr - -tar -xvf rpm64_$DISTR_FILE_VERSION.tar.gz "license-tools" -C /main_dir/distr/ diff --git a/modules/helper.py b/modules/helper.py index 82130d6..39defb4 100644 --- a/modules/helper.py +++ b/modules/helper.py @@ -1,10 +1,12 @@ import pathlib import os +path_to_1c = '' sep = str(os.path.sep) this_path = str(pathlib.Path().absolute()) + sep distr_path = this_path + 'distr' + sep + def replace_sep(path): return path.replace('/', sep) @@ -35,7 +37,7 @@ def web_publish_command(host_name, conf_name, internal, descriptor, base_name='' command.append('docker') command.append('exec') command.append('web.' + host_name) - command.append('/opt/1C/v8.3/x86_64/webinst') + command.append('{}webinst'.format(path_to_1c)) command.append('-apache24') command.append('-wsdir') command.append(prefix + '/' + conf_name) @@ -62,7 +64,7 @@ def create_ib_command(host_name, ib_name, file_name, job_block, action): command.append('exec') command.append('-t') command.append('srv.' + host_name) - command.append('/opt/1C/v8.3/x86_64/1cv8') + command.append('{}1cv8'.format(path_to_1c)) command.append('CREATEINFOBASE') command.append('"Srvr=srv;Ref={0};DBMS=PostgreSQL;DBSrvr=/tmp/postgresql/socket;DB={0};DBUID=postgres;LicDstr=Y;Locale=ru_RU;CrSQLDB=Y;SchJobDn={1};"'.format( ib_name, job_block)) @@ -77,7 +79,7 @@ def install_control_ext_command(host_name, ib_name, action): command.append('exec') command.append('-t') command.append('srv.' + host_name) - command.append('/opt/1C/v8.3/x86_64/1cv8') + command.append('{}1cv8'.format(path_to_1c)) command.append('DESIGNER') command.append('/S') command.append('"srv\\{}"'.format(ib_name)) @@ -95,7 +97,7 @@ def install_sm_ext_command(host_name, ib_name, action): command.append('exec') command.append('-t') command.append('srv.' + host_name) - command.append('/opt/1C/v8.3/x86_64/1cv8') + command.append('{}1cv8'.format(path_to_1c)) command.append('DESIGNER') command.append('/S') command.append('"srv\\{}"'.format(ib_name)) @@ -113,7 +115,7 @@ def install_ext_command(host_name, ib_name, action): command.append('exec') command.append('-t') command.append('srv.' + host_name) - command.append('/opt/1C/v8.3/x86_64/1cv8') + command.append('{}1cv8'.format(path_to_1c)) command.append('DESIGNER') command.append('/S') command.append('"srv\\{}"'.format(ib_name)) @@ -131,7 +133,7 @@ def disable_safe_mode(host_name, ib_name, action): command.append('exec') command.append('-t') command.append('srv.' + host_name) - command.append('/opt/1C/v8.3/x86_64/1cv8') + command.append('{}1cv8'.format(path_to_1c)) command.append('ENTERPRICE') command.append('/S') command.append('"srv\\{}"'.format(ib_name)) @@ -233,4 +235,9 @@ def get_host_name(argv): print('parameter -р not specified') exit(1) host_index = argv.index('-h') - return argv[host_index + 1] \ No newline at end of file + return argv[host_index + 1] + + +def init(path): + global path_to_1c + path_to_1c = path \ No newline at end of file diff --git a/start.py b/start.py index e2efd50..4763eb2 100644 --- a/start.py +++ b/start.py @@ -21,6 +21,7 @@ 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/') +path_to_1c = '' class colors: @@ -91,7 +92,7 @@ def print_description(function_to_decorate): task.join() progress_thread.stop() - while progress_thread.isAlive(): + while progress_thread.is_alive(): time.sleep(0.2) if not task.is_good: exit(1) @@ -272,6 +273,7 @@ def renew_docker_compose(): call('cp /out_files/docker-compose_pattern.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/PATH_TO_1C_REPLACE/{}/\' {}/*.yml"'.format(path_to_1c.replace('/','\/'), work_dir)) @print_description @@ -425,6 +427,16 @@ def down_containers(): call(docker_compose_str + 'down', remote=False) +@print_description +def get_path_to_1c(): + """Getting path to 1C""" + + global path_to_1c + cmd = "docker run --rm fresh/core sh -c \"find / -name '1cv8c' | sed 's/1cv8c//g'\"" + pipe = subprocess.PIPE + p = subprocess.Popen(cmd, shell=True, stdin=pipe, stdout=pipe, stderr=pipe, close_fds=True) + path_to_1c = p.stdout.read().decode('utf-8').strip() + print('path to 1C: ' + path_to_1c) global_start_time = datetime.now() print('{}Fresh is starting{} at {}'.format(colors.GREEN, colors.WHITE, global_start_time)) @@ -434,6 +446,8 @@ new_server = '-new' in sys.argv global_debug = '-debug' in sys.argv set_full_host_name(new_server) +get_path_to_1c() +helper.init(path_to_1c) if new_server: renew_workdir()