From 8597adc5d42f515662521a6fd489e4137742d4d6 Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Wed, 16 Jul 2025 22:16:39 -0400 Subject: [PATCH 1/3] Add support for container specific poststart events - organize script and logfiles in container specific directories - create container specific poststart command paths in script_configmap_appender - create helper class for poststart commands - update specs EE: true Changelog: changed --- .../devfile_resource_appender.rb | 8 +- .../kubernetes_poststart_hook_command.sh | 22 +- .../kubernetes_poststart_hook_inserter.rb | 40 ++-- .../poststart_commands_helper.rb | 44 ++++ .../scripts_configmap_appender.rb | 85 ++++---- .../desired_config/scripts_volume_inserter.rb | 73 ++++++- ...ernal_poststart_command_clone_unshallow.sh | 3 +- .../internal_poststart_command_start_sshd.sh | 5 +- ...internal_poststart_command_start_vscode.sh | 9 +- .../internal_poststart_commands_inserter.rb | 14 +- .../example.desired_config.json | 2 +- ...kubernetes_poststart_hook_inserter_spec.rb | 6 +- .../desired_config/main_integeration_spec.rb | 130 +++++++++-- .../poststart_commands_helper_spec.rb | 202 ++++++++++++++++++ .../scripts_configmap_appender_spec.rb | 57 +++-- .../scripts_volume_inserter_spec.rb | 7 +- ...ponent_updater_start_vscode_script_spec.rb | 13 +- .../reconcile/main_integration_spec.rb | 4 +- .../fixture_file_helpers.rb | 8 +- .../remote_development_shared_contexts.rb | 192 +++++++++++++---- 20 files changed, 746 insertions(+), 178 deletions(-) create mode 100644 ee/spec/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper_spec.rb diff --git a/ee/lib/remote_development/workspace_operations/create/desired_config/devfile_resource_appender.rb b/ee/lib/remote_development/workspace_operations/create/desired_config/devfile_resource_appender.rb index e9e12630495bb4..84de63d427557c 100644 --- a/ee/lib/remote_development/workspace_operations/create/desired_config/devfile_resource_appender.rb +++ b/ee/lib/remote_development/workspace_operations/create/desired_config/devfile_resource_appender.rb @@ -332,13 +332,17 @@ def self.append_scripts_resources( ScriptsVolumeInserter.insert( configmap_name: name, containers: containers, - volumes: volumes + volumes: volumes, + devfile_commands: devfile_commands, + devfile_events: devfile_events, + processed_devfile: processed_devfile ) KubernetesPoststartHookInserter.insert( containers: containers, devfile_commands: devfile_commands, - devfile_events: devfile_events + devfile_events: devfile_events, + processed_devfile: processed_devfile ) nil diff --git a/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh b/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh index 792e1cad5d3a53..3ba18943e7710d 100644 --- a/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh +++ b/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh @@ -1,21 +1,29 @@ #!/bin/sh -mkdir -p "${GL_WORKSPACE_LOGS_DIR}" +component_name="%s" +main_component_name="%s" + +mkdir -p "${GL_WORKSPACE_LOGS_DIR}/${component_name}" ln -sf "${GL_WORKSPACE_LOGS_DIR}" /tmp { echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running poststart commands for workspace..." +}>> "${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" - echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running internal blocking poststart commands script..." -} >> "${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log" -"%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log" +if [ "${component_name}" = "${main_component_name}" ]; then + { + echo "$(date -Iseconds): ----------------------------------------" + echo "$(date -Iseconds): Running internal blocking poststart commands script..." + } >> "${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" + + "%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log" +fi { echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running non-blocking poststart commands script..." -} >> "${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log" +} >> "${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" -"%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log" & +"%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log" & diff --git a/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter.rb b/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter.rb index ee73cd16d0d1ac..b7b88541ec9a28 100644 --- a/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter.rb @@ -10,32 +10,36 @@ module DesiredConfig class KubernetesPoststartHookInserter include Files include CreateConstants + extend PoststartCommandsHelper # @param [Array] containers # @param [Array] devfile_commands # @param [Hash] devfile_events + # @param [Hash] processed_devfile # @return [void] - def self.insert(containers:, devfile_commands:, devfile_events:) - internal_blocking_command_label_present = devfile_commands.any? do |command| - command.dig(:exec, :label) == INTERNAL_BLOCKING_COMMAND_LABEL - end + def self.insert(containers:, devfile_commands:, devfile_events:, processed_devfile:) + poststart_commands = extract_poststart_commands( + devfile_commands: devfile_commands, + devfile_events: devfile_events + ) - devfile_events => { postStart: Array => poststart_command_ids } + main_component_name = extract_main_component_name( + processed_devfile: processed_devfile + ) - containers_with_devfile_poststart_commands = - poststart_command_ids.each_with_object([]) do |poststart_command_id, accumulator| - command = devfile_commands.find { |command| command.fetch(:id) == poststart_command_id } - command => { - exec: { - component: String => container_name - } - } - accumulator << container_name - end.uniq + internal_blocking_command_label_present = internal_blocking_command_label_present?( + poststart_commands: poststart_commands + ) + + containers_with_devfile_poststart_commands = get_container_names_with_poststart_commands( + poststart_commands: poststart_commands + ) containers.each do |container| container_name = container.fetch(:name) + container_script_path = "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{container_name}/" + next unless containers_with_devfile_poststart_commands.include?(container_name) if internal_blocking_command_label_present @@ -47,9 +51,11 @@ def self.insert(containers:, devfile_commands:, devfile_events:) format( KUBERNETES_POSTSTART_HOOK_COMMAND, run_internal_blocking_poststart_commands_script_file_path: - "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", + container_script_path + RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME, run_non_blocking_poststart_commands_script_file_path: - "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" + container_script_path + RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME, + component_name: container_name, + main_component_name: main_component_name ) else # SECURITY REVIEWED: Shell interpolation using format() with system-controlled path diff --git a/ee/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper.rb b/ee/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper.rb index bc7dae0a6f3cc6..9fee5e2ffe229a 100644 --- a/ee/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper.rb +++ b/ee/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper.rb @@ -6,6 +6,20 @@ module Create module DesiredConfig module PoststartCommandsHelper include RemoteDevelopmentConstants + include WorkspaceOperationsConstants + + # @param [Array] devfile_commands + # @param [Hash] devfile_events + # @return [Array] + def extract_poststart_commands(devfile_commands:, devfile_events:) + return [] unless devfile_events[:postStart].present? + + poststart_command_ids = devfile_events.fetch(:postStart) + + poststart_command_ids.filter_map do |id| + devfile_commands.find { |cmd| cmd[:id] == id } + end + end # @param [Hash] processed_devfile # @return [String] @@ -18,6 +32,36 @@ def extract_main_component_name(processed_devfile:) main_component.fetch(:name) end + + # @param [Array] poststart_commands + # @return [Array] + def get_container_names_with_poststart_commands(poststart_commands:) + poststart_commands.map { |cmd| cmd[:exec][:component] }.uniq + end + + # @param [Array] poststart_commands + # @return [Boolean] + def internal_blocking_command_label_present?(poststart_commands:) + poststart_commands.any? do |command| + command.dig(:exec, :label) == INTERNAL_BLOCKING_COMMAND_LABEL + end + end + + # @param [Array] poststart_commands + # @return [Array, Array>] + def partition_poststart_commands(poststart_commands:) + poststart_commands.partition do |poststart_cmd| + poststart_cmd&.dig(:exec, :label) == INTERNAL_BLOCKING_COMMAND_LABEL + end + end + + # @param [Array] non_blocking_commands + # @return [Hash] + def group_commands_by_component(non_blocking_commands:) + non_blocking_commands.group_by do |cmd| + cmd[:exec][:component] + end + end end end end diff --git a/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender.rb b/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender.rb index 22d1d6c64daae4..b145bc6d40f9a4 100644 --- a/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender.rb +++ b/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender.rb @@ -10,7 +10,7 @@ class ScriptsConfigmapAppender extend PoststartCommandsHelper # rubocop:disable Metrics/ParameterLists -- all arguments needed - # @param [Array] desired_config + # @param [Array] desired_config_array # @param [String] name # @param [String] namespace # @param [String] project_path @@ -74,10 +74,13 @@ def self.append( # @param [Hash] devfile_events # @return [void] def self.add_devfile_command_scripts_to_configmap_data(configmap_data:, devfile_commands:, devfile_events:) - devfile_events => { postStart: Array => poststart_command_ids } + poststart_commands = extract_poststart_commands( + devfile_commands: devfile_commands, + devfile_events: devfile_events + ) - poststart_command_ids.each do |poststart_command_id| - command = devfile_commands.find { |command| command.fetch(:id) == poststart_command_id } + poststart_commands.each do |command| + poststart_command_id = command.fetch(:id) command => { exec: { commandLine: String => command_line @@ -103,17 +106,12 @@ def self.add_run_poststart_commands_script_to_configmap_data( devfile_events:, project_path: ) - devfile_events => { postStart: Array => poststart_command_ids } - - internal_blocking_command_label_present = devfile_commands.find do |command| - command.dig(:exec, :label) == INTERNAL_BLOCKING_COMMAND_LABEL - end - - main_component_name = extract_main_component_name( - processed_devfile: processed_devfile + poststart_commands = extract_poststart_commands( + devfile_commands: devfile_commands, + devfile_events: devfile_events ) - unless internal_blocking_command_label_present + unless internal_blocking_command_label_present?(poststart_commands: poststart_commands) # SAST IGNORE: String interpolation in shell context is safe here # The interpolated method call returns validated script content # Future SAST alerts on this heredoc can be safely ignored @@ -121,56 +119,62 @@ def self.add_run_poststart_commands_script_to_configmap_data( configmap_data[LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym] = <<~SH.chomp #!/bin/sh - #{get_poststart_command_script_content(poststart_command_ids: poststart_command_ids, devfile_commands: devfile_commands, project_path: project_path, main_component_name: main_component_name, is_legacy_poststart_command: true)} + #{get_poststart_command_script_content(poststart_commands: poststart_commands, is_legacy_poststart_command: true)} SH return end # Segregate internal commands and user provided commands. # Before any non-blocking post start command is executed, we wait for the workspace to be marked ready. - internal_blocking_poststart_command_ids, non_blocking_poststart_command_ids = - poststart_command_ids.partition do |id| - command = devfile_commands.find { |cmd| cmd[:id] == id } - command && command.dig(:exec, :label) == INTERNAL_BLOCKING_COMMAND_LABEL - end + internal_blocking_poststart_commands, non_blocking_poststart_commands = partition_poststart_commands( + poststart_commands: poststart_commands + ) + + main_component_name = extract_main_component_name( + processed_devfile: processed_devfile + ) # SAST IGNORE: String interpolation in shell context is safe here # The interpolated method call returns validated internal script content # Future SAST alerts on this heredoc can be safely ignored. # Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/547719 - configmap_data[RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym] = + configmap_data[:"#{main_component_name}-#{RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}"] = <<~SH.chomp #!/bin/sh - #{get_poststart_command_script_content(poststart_command_ids: internal_blocking_poststart_command_ids, devfile_commands: devfile_commands, project_path: project_path, main_component_name: main_component_name)} + #{get_poststart_command_script_content(poststart_commands: internal_blocking_poststart_commands, project_path: project_path, main_component_name: main_component_name)} SH + grouped_non_blocking_poststart_commands = group_commands_by_component( + non_blocking_commands: non_blocking_poststart_commands + ) + # SAST IGNORE: String interpolation in shell context is safe here # The interpolated method call returns validated script content # Future SAST alerts on this heredoc can be safely ignored. # Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/547719 - configmap_data[RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym] = - <<~SH.chomp - #!/bin/sh - #{get_poststart_command_script_content(poststart_command_ids: non_blocking_poststart_command_ids, devfile_commands: devfile_commands, project_path: project_path, main_component_name: main_component_name)} - SH + grouped_non_blocking_poststart_commands.each do |component, commands| + configmap_data[:"#{component}-#{RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}"] = + <<~SH.chomp + #!/bin/sh + #{get_poststart_command_script_content(poststart_commands: commands, project_path: project_path, main_component_name: main_component_name)} + SH + end nil end - # @param [Array] poststart_command_ids - # @param [Array] devfile_commands + # @param [Array] poststart_commands # @param [String] project_path # @param [String] main_component_name # @param [Boolean] is_legacy_poststart_command # @return [String] def self.get_poststart_command_script_content( - poststart_command_ids:, - devfile_commands:, - project_path:, - main_component_name:, + poststart_commands:, + project_path: "", + main_component_name: "", is_legacy_poststart_command: false ) - poststart_command_ids.map do |poststart_command_id| + poststart_commands.map do |poststart_command| # NOTE: We force all the poststart scripts to exit successfully with `|| true`, to # prevent the Kubernetes poststart hook from failing, and thus prevent the # container from exiting. Then users can view logs to debug failures. @@ -182,13 +186,14 @@ def self.get_poststart_command_script_content( # Additional validation in ee/lib/remote_development/devfile_operations/restrictions_enforcer.rb # Future SAST alerts on this heredoc can be safely ignored. # Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/547719 + component_name = poststart_command.dig(:exec, :component) + component_path = is_legacy_poststart_command ? "" : "#{component_name}/" - script_execution = "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{poststart_command_id}" - command = devfile_commands.find { |cmd| cmd[:id] == poststart_command_id } + poststart_command_path = "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{component_path}#{poststart_command[:id]}" + script_execution = poststart_command_path unless is_legacy_poststart_command - working_dir = command.dig(:exec, :workingDir) - component_name = command.dig(:exec, :component) + working_dir = poststart_command.dig(:exec, :workingDir) effective_working_dir = if working_dir.present? Shellwords.shellescape(working_dir) @@ -198,15 +203,15 @@ def self.get_poststart_command_script_content( end if effective_working_dir.present? - script_execution = "(cd #{effective_working_dir} && #{script_execution})" + script_execution = "(cd #{effective_working_dir} && #{poststart_command_path})" end end <<~SH echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running #{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{poststart_command_id}..." + echo "$(date -Iseconds): Running #{poststart_command_path}..." #{script_execution} || true - echo "$(date -Iseconds): Finished running #{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{poststart_command_id}." + echo "$(date -Iseconds): Finished running #{poststart_command_path}." SH end.join end diff --git a/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter.rb b/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter.rb index 3a4d2b46fd57f3..55b522166edbf8 100644 --- a/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter.rb @@ -6,24 +6,44 @@ module Create module DesiredConfig class ScriptsVolumeInserter include CreateConstants + extend PoststartCommandsHelper # @param [String] configmap_name # @param [Array] containers # @param [Array] volumes + # @param [Array] devfile_commands + # @param [Hash] devfile_events + # @param [Hash] processed_devfile # @return [void] - def self.insert(configmap_name:, containers:, volumes:) + def self.insert( + configmap_name:, + containers:, + volumes:, + devfile_commands:, + devfile_events:, + processed_devfile: + ) + poststart_commands = extract_poststart_commands( + devfile_commands: devfile_commands, + devfile_events: devfile_events + ) + + configmap_source = { configMap: { name: configmap_name } } + + if internal_blocking_command_label_present?(poststart_commands: poststart_commands) + configmap_items = build_poststart_script_configmap_items( + poststart_commands: poststart_commands, + processed_devfile: processed_devfile + ) + configmap_source[:configMap][:items] = configmap_items + end + volume = { name: WORKSPACE_SCRIPTS_VOLUME_NAME, projected: { defaultMode: WORKSPACE_SCRIPTS_VOLUME_DEFAULT_MODE, - sources: [ - { - configMap: { - name: configmap_name - } - } - ] + sources: [configmap_source] } } volume_mount = @@ -33,12 +53,49 @@ def self.insert(configmap_name:, containers:, volumes:) } volumes << volume + containers.each do |container| container.fetch(:volumeMounts) << volume_mount end nil end + + # @param [Array] poststart_commands + # @param [Hash] processed_devfile + # @return [Array] + def self.build_poststart_script_configmap_items(poststart_commands:, processed_devfile:) + containers_with_devfile_poststart_commands = get_container_names_with_poststart_commands( + poststart_commands: poststart_commands + ) + + main_component_name = extract_main_component_name( + processed_devfile: processed_devfile + ) + + configmap_items = poststart_commands.map do |cmd| + { + key: cmd[:id].to_s, + path: "#{cmd.dig(:exec, :component)}/#{cmd[:id]}" + } + end + + configmap_items << { + key: "#{main_component_name}-#{RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", + path: "#{main_component_name}/#{RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" + } + + containers_with_devfile_poststart_commands.each do |container_name| + configmap_items << { + key: "#{container_name}-#{RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", + path: "#{container_name}/#{RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" + } + end + + configmap_items + end + + private_class_method :build_poststart_script_configmap_items end end end diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_unshallow.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_unshallow.sh index 4f8d7c1db61a0f..61cc8d7a0464fb 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_unshallow.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_unshallow.sh @@ -19,7 +19,8 @@ if [ "$(git rev-parse --is-shallow-repository)" != "true" ]; then fi echo "$(date -Iseconds): Repository is shallow, proceeding with unshallow" -UNSHALLOW_LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/clone-unshallow.log" +main_component_name="%s" +UNSHALLOW_LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/%s/clone-unshallow.log" echo "$(date -Iseconds): Starting unshallow in background, with output written to ${UNSHALLOW_LOG_FILE}" { diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_sshd.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_sshd.sh index ba3b2b30ff4b92..876aff5437ef30 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_sshd.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_sshd.sh @@ -1,10 +1,11 @@ #!/bin/sh echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Starting sshd in background if it is found..." +main_component_name="%s" sshd_path=$(which sshd) if [ -x "${sshd_path}" ]; then - echo "$(date -Iseconds): Starting ${sshd_path} in background on port ${GL_SSH_PORT} with output written to ${GL_WORKSPACE_LOGS_DIR}/start-sshd.log" - "${sshd_path}" -D -p "${GL_SSH_PORT}" >> "${GL_WORKSPACE_LOGS_DIR}/start-sshd.log" 2>&1 & + echo "$(date -Iseconds): Starting ${sshd_path} in background on port ${GL_SSH_PORT} with output written to ${GL_WORKSPACE_LOGS_DIR}/${main_component_name}/start-sshd.log" + "${sshd_path}" -D -p "${GL_SSH_PORT}" >> "${GL_WORKSPACE_LOGS_DIR}/${main_component_name}/start-sshd.log" 2>&1 & echo "$(date -Iseconds): Finished starting sshd in background if it is found." else echo "$(date -Iseconds): 'sshd' not found in path. Not starting SSH server." >&2 diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh index 75d68ac2c18642..a79697af0e80f4 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh @@ -1,10 +1,11 @@ #!/bin/sh - -echo "$(date -Iseconds): ----------------------------------------" -echo "$(date -Iseconds): Starting GitLab Fork of VS Code server in background with output written to ${GL_WORKSPACE_LOGS_DIR}/start-vscode.log..." +main_component_name="%s" # Define log file path -LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/start-vscode.log" +LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/${main_component_name}/start-vscode.log" + +echo "$(date -Iseconds): ----------------------------------------" +echo "$(date -Iseconds): Starting GitLab Fork of VS Code server in background with output written to ${LOG_FILE}..." mkdir -p "$(dirname "${LOG_FILE}")" diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb b/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb index e4602b60d5cbdc..d49450555e5a86 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb @@ -115,10 +115,15 @@ def self.insert(context) # Add the start_sshd event start_sshd_command_id = "gl-start-sshd-command" + start_sshd_script = + format( + INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT, + main_component_name: Shellwords.shellescape(main_component_name) + ) commands << { id: start_sshd_command_id, exec: { - commandLine: INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT, + commandLine: start_sshd_script, component: main_component_name, label: INTERNAL_BLOCKING_COMMAND_LABEL, workingDir: WORKSPACE_DATA_VOLUME_PATH @@ -127,10 +132,15 @@ def self.insert(context) # Add the start_vscode event start_vscode_command_id = "gl-init-tools-command" + start_vscode_script = + format( + INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, + main_component_name: Shellwords.shellescape(main_component_name) + ) commands << { id: start_vscode_command_id, exec: { - commandLine: INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, + commandLine: start_vscode_script, component: main_component_name, label: INTERNAL_BLOCKING_COMMAND_LABEL, workingDir: WORKSPACE_DATA_VOLUME_PATH diff --git a/ee/spec/fixtures/remote_development/example.desired_config.json b/ee/spec/fixtures/remote_development/example.desired_config.json index 70cbf6f9b6d087..1fb1e20797d880 100644 --- a/ee/spec/fixtures/remote_development/example.desired_config.json +++ b/ee/spec/fixtures/remote_development/example.desired_config.json @@ -149,7 +149,7 @@ "command": [ "/bin/sh", "-c", - "#!/bin/sh\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\"\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/tooling-container\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}/tooling-container\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/tooling-container/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/tooling-container/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/tooling-container/poststart-stderr.log\"\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/tooling-container/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/tooling-container/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/tooling-container/poststart-stderr.log\" &\n" ] } } diff --git a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter_spec.rb index 63426672da0229..ee59b54adb530f 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_inserter_spec.rb @@ -48,7 +48,8 @@ # pass input containers without resources for scripts added, then assert they get added by the described_class containers: input_containers, devfile_commands: devfile_commands, - devfile_events: devfile_events + devfile_events: devfile_events, + processed_devfile: processed_devfile ) end @@ -86,7 +87,8 @@ let(:legacy_poststart_container_command) { true } let(:processed_devfile) do yaml_safe_load_symbolized( - read_devfile_yaml("example.legacy-poststart-in-container-command-processed-devfile.yaml.erb") + read_devfile_yaml("example.legacy-poststart-in-container-command-processed-devfile.yaml.erb", + is_legacy_poststart: true) ) end diff --git a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integeration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integeration_spec.rb index febb547bc5bb95..0e9a668216a955 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integeration_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integeration_spec.rb @@ -580,7 +580,7 @@ def expected_desired_config_array_with_desired_state_running command: [ "/bin/sh", "-c", - "#!/bin/sh\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\"\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -683,7 +683,25 @@ def expected_desired_config_array_with_desired_state_running sources: [ { configMap: { - name: "workspace-991-990-fedcba-scripts-configmap" + name: "workspace-991-990-fedcba-scripts-configmap", + items: [ + { + key: "gl-internal-example-command-1", + path: "tooling-container/gl-internal-example-command-1" + }, + { + key: "gl-internal-example-command-2", + path: "tooling-container/gl-internal-example-command-2" + }, + { + key: "tooling-container-gl-run-internal-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-internal-blocking-poststart-commands.sh" + }, + { + key: "tooling-container-gl-run-non-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-non-blocking-poststart-commands.sh" + } + ] } } ] @@ -903,8 +921,8 @@ def expected_desired_config_array_with_desired_state_running namespace: "gl-rd-ns-991-990-fedcba" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-1.\"\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-2.\"\n", + "tooling-container-gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-1.\"\n", + "tooling-container-gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-2.\"\n", "gl-internal-example-command-1": "echo 'gl-internal-example-command-1'", "gl-internal-example-command-2": "echo 'gl-internal-example-command-2'" } @@ -1164,7 +1182,7 @@ def expected_desired_config_array_with_desired_state_running_with_use_kubernetes command: [ "/bin/sh", "-c", - "#!/bin/sh\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\"\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -1268,7 +1286,25 @@ def expected_desired_config_array_with_desired_state_running_with_use_kubernetes sources: [ { configMap: { - name: "workspace-991-990-fedcba-scripts-configmap" + name: "workspace-991-990-fedcba-scripts-configmap", + items: [ + { + key: "gl-internal-example-command-1", + path: "tooling-container/gl-internal-example-command-1" + }, + { + key: "gl-internal-example-command-2", + path: "tooling-container/gl-internal-example-command-2" + }, + { + key: "tooling-container-gl-run-internal-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-internal-blocking-poststart-commands.sh" + }, + { + key: "tooling-container-gl-run-non-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-non-blocking-poststart-commands.sh" + } + ] } } ] @@ -1488,8 +1524,8 @@ def expected_desired_config_array_with_desired_state_running_with_use_kubernetes namespace: "gl-rd-ns-991-990-fedcba" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-1.\"\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-2.\"\n", + "tooling-container-gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-1.\"\n", + "tooling-container-gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-2.\"\n", "gl-internal-example-command-1": "echo 'gl-internal-example-command-1'", "gl-internal-example-command-2": "echo 'gl-internal-example-command-2'" } @@ -1748,7 +1784,7 @@ def expected_desired_config_array_with_desired_state_stopped command: [ "/bin/sh", "-c", - "#!/bin/sh\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\"\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -1851,7 +1887,25 @@ def expected_desired_config_array_with_desired_state_stopped sources: [ { configMap: { - name: "workspace-991-990-fedcba-scripts-configmap" + name: "workspace-991-990-fedcba-scripts-configmap", + items: [ + { + key: "gl-internal-example-command-1", + path: "tooling-container/gl-internal-example-command-1" + }, + { + key: "gl-internal-example-command-2", + path: "tooling-container/gl-internal-example-command-2" + }, + { + key: "tooling-container-gl-run-internal-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-internal-blocking-poststart-commands.sh" + }, + { + key: "tooling-container-gl-run-non-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-non-blocking-poststart-commands.sh" + } + ] } } ] @@ -2071,8 +2125,8 @@ def expected_desired_config_array_with_desired_state_stopped namespace: "gl-rd-ns-991-990-fedcba" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-1.\"\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-2.\"\n", + "tooling-container-gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-1.\"\n", + "tooling-container-gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-2.\"\n", "gl-internal-example-command-1": "echo 'gl-internal-example-command-1'", "gl-internal-example-command-2": "echo 'gl-internal-example-command-2'" } @@ -3440,7 +3494,7 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_runnin command: [ "/bin/sh", "-c", - "#!/bin/sh\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\"\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -3543,7 +3597,25 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_runnin sources: [ { configMap: { - name: "workspace-991-990-fedcba-scripts-configmap" + name: "workspace-991-990-fedcba-scripts-configmap", + items: [ + { + key: "gl-internal-example-command-1", + path: "tooling-container/gl-internal-example-command-1" + }, + { + key: "gl-internal-example-command-2", + path: "tooling-container/gl-internal-example-command-2" + }, + { + key: "tooling-container-gl-run-internal-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-internal-blocking-poststart-commands.sh" + }, + { + key: "tooling-container-gl-run-non-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-non-blocking-poststart-commands.sh" + } + ] } } ] @@ -3773,8 +3845,8 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_runnin namespace: "default" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-1.\"\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-2.\"\n", + "tooling-container-gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-1.\"\n", + "tooling-container-gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-2.\"\n", "gl-internal-example-command-1": "echo 'gl-internal-example-command-1'", "gl-internal-example-command-2": "echo 'gl-internal-example-command-2'" } @@ -4011,7 +4083,7 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_stoppe command: [ "/bin/sh", "-c", - "#!/bin/sh\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\"\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n\n\"/workspace-scripts/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -4114,7 +4186,25 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_stoppe sources: [ { configMap: { - name: "workspace-991-990-fedcba-scripts-configmap" + name: "workspace-991-990-fedcba-scripts-configmap", + items: [ + { + key: "gl-internal-example-command-1", + path: "tooling-container/gl-internal-example-command-1" + }, + { + key: "gl-internal-example-command-2", + path: "tooling-container/gl-internal-example-command-2" + }, + { + key: "tooling-container-gl-run-internal-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-internal-blocking-poststart-commands.sh" + }, + { + key: "tooling-container-gl-run-non-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-non-blocking-poststart-commands.sh" + } + ] } } ] @@ -4344,8 +4434,8 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_stoppe namespace: "default" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-1.\"\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-2.\"\n", + "tooling-container-gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-1...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-1) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-1.\"\n", + "tooling-container-gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/tooling-container/gl-internal-example-command-2...\"\n(cd /projects && /workspace-scripts/tooling-container/gl-internal-example-command-2) || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/tooling-container/gl-internal-example-command-2.\"\n", "gl-internal-example-command-1": "echo 'gl-internal-example-command-1'", "gl-internal-example-command-2": "echo 'gl-internal-example-command-2'" } diff --git a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper_spec.rb new file mode 100644 index 00000000000000..df2724f27f79a4 --- /dev/null +++ b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/poststart_commands_helper_spec.rb @@ -0,0 +1,202 @@ +# frozen_string_literal: true + +require "fast_spec_helper" + +RSpec.describe RemoteDevelopment::WorkspaceOperations::Create::DesiredConfig::PoststartCommandsHelper, feature_category: :workspaces do + let(:described_class) do + Class.new do + extend RemoteDevelopment::WorkspaceOperations::Create::DesiredConfig::PoststartCommandsHelper + end + end + + describe '.extract_poststart_commands' do + let(:devfile_commands) do + [ + { id: 'cmd1', exec: { component: 'container1', commandLine: 'echo test1' } }, + { id: 'cmd2', exec: { component: 'container2', commandLine: 'echo test2' } }, + { id: 'cmd3', exec: { component: 'container1', commandLine: 'echo test3' } } + ] + end + + context 'when postStart events are present' do + let(:devfile_events) { { postStart: %w[cmd1 cmd3] } } + + it 'returns matching commands' do + result = described_class.extract_poststart_commands( + devfile_commands: devfile_commands, + devfile_events: devfile_events + ) + + expect(result).to eq([ + { id: 'cmd1', exec: { component: 'container1', commandLine: 'echo test1' } }, + { id: 'cmd3', exec: { component: 'container1', commandLine: 'echo test3' } } + ]) + end + end + + context 'when postStart events are empty' do + let(:devfile_events) { { postStart: [] } } + + it 'returns empty array' do + result = described_class.extract_poststart_commands( + devfile_commands: devfile_commands, + devfile_events: devfile_events + ) + + expect(result).to eq([]) + end + end + + context 'when command ID does not exist' do + let(:devfile_events) { { postStart: %w[cmd1 nonexistent cmd3] } } + + it 'filters out non-existent commands' do + result = described_class.extract_poststart_commands( + devfile_commands: devfile_commands, + devfile_events: devfile_events + ) + + expect(result).to eq([ + { id: 'cmd1', exec: { component: 'container1', commandLine: 'echo test1' } }, + { id: 'cmd3', exec: { component: 'container1', commandLine: 'echo test3' } } + ]) + end + end + end + + describe '.extract_main_component_name' do + context 'when main component exists' do + let(:processed_devfile) do + { + components: [ + { name: 'secondary-container', attributes: {} }, + { name: 'main-container', attributes: { 'gl/inject-editor': true } }, + { name: 'another-container', attributes: {} } + ] + } + end + + it 'returns the main component name' do + result = described_class.extract_main_component_name(processed_devfile: processed_devfile) + expect(result).to eq('main-container') + end + end + end + + describe '.get_container_names_with_poststart_commands' do + let(:poststart_commands) do + [ + { id: 'cmd1', exec: { component: 'container1', commandLine: 'echo test1' } }, + { id: 'cmd2', exec: { component: 'container2', commandLine: 'echo test2' } }, + { id: 'cmd3', exec: { component: 'container1', commandLine: 'echo test3' } }, + { id: 'cmd4', exec: { component: 'container3', commandLine: 'echo test4' } } + ] + end + + it 'returns unique container names' do + result = described_class.get_container_names_with_poststart_commands( + poststart_commands: poststart_commands + ) + + expect(result).to match_array(%w[container1 container2 container3]) + end + end + + describe '.internal_blocking_command_label_present?' do + context 'when internal blocking commands are present' do + let(:poststart_commands) do + [ + { id: 'user-cmd', exec: { component: 'container1', commandLine: 'echo user' } }, + { id: 'internal-cmd', + exec: { component: 'container1', commandLine: 'echo internal', label: 'gl-internal-blocking' } } + ] + end + + it 'returns true' do + result = described_class.internal_blocking_command_label_present?( + poststart_commands: poststart_commands + ) + + expect(result).to be true + end + end + + context 'when no internal blocking commands are present' do + let(:poststart_commands) do + [ + { id: 'user-cmd1', exec: { component: 'container1', commandLine: 'echo user1' } }, + { id: 'user-cmd2', exec: { component: 'container2', commandLine: 'echo user2' } } + ] + end + + it 'returns false' do + result = described_class.internal_blocking_command_label_present?( + poststart_commands: poststart_commands + ) + + expect(result).to be false + end + end + end + + describe '.partition_poststart_commands' do + let(:poststart_commands) do + [ + { id: 'user-cmd1', exec: { component: 'container1', commandLine: 'echo user1' } }, + { id: 'internal-cmd1', + exec: { component: 'container1', commandLine: 'echo internal1', label: 'gl-internal-blocking' } }, + { id: 'user-cmd2', exec: { component: 'container2', commandLine: 'echo user2' } }, + { id: 'internal-cmd2', + exec: { component: 'container1', commandLine: 'echo internal2', label: 'gl-internal-blocking' } } + ] + end + + it 'partitions commands correctly' do + internal_commands, non_blocking_commands = described_class.partition_poststart_commands( + poststart_commands: poststart_commands + ) + + expect(internal_commands).to eq([ + { id: 'internal-cmd1', + exec: { component: 'container1', commandLine: 'echo internal1', label: 'gl-internal-blocking' } }, + { id: 'internal-cmd2', + exec: { component: 'container1', commandLine: 'echo internal2', label: 'gl-internal-blocking' } } + ]) + + expect(non_blocking_commands).to eq([ + { id: 'user-cmd1', exec: { component: 'container1', commandLine: 'echo user1' } }, + { id: 'user-cmd2', exec: { component: 'container2', commandLine: 'echo user2' } } + ]) + end + end + + describe '.group_commands_by_component' do + let(:non_blocking_commands) do + [ + { id: 'cmd1', exec: { component: 'container1', commandLine: 'echo test1' } }, + { id: 'cmd2', exec: { component: 'container2', commandLine: 'echo test2' } }, + { id: 'cmd3', exec: { component: 'container1', commandLine: 'echo test3' } }, + { id: 'cmd4', exec: { component: 'container3', commandLine: 'echo test4' } } + ] + end + + it 'groups commands by component' do + result = described_class.group_commands_by_component( + non_blocking_commands: non_blocking_commands + ) + + expect(result).to eq({ + 'container1' => [ + { id: 'cmd1', exec: { component: 'container1', commandLine: 'echo test1' } }, + { id: 'cmd3', exec: { component: 'container1', commandLine: 'echo test3' } } + ], + 'container2' => [ + { id: 'cmd2', exec: { component: 'container2', commandLine: 'echo test2' } } + ], + 'container3' => [ + { id: 'cmd4', exec: { component: 'container3', commandLine: 'echo test4' } } + ] + }) + end + end +end diff --git a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender_spec.rb index 6cf93598551863..65358961165455 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_configmap_appender_spec.rb @@ -13,6 +13,9 @@ let(:processed_devfile) { example_processed_devfile } let(:devfile_commands) { processed_devfile.fetch(:commands) } let(:devfile_events) { processed_devfile.fetch(:events) } + let(:user_defined_poststart_commands) do + extract_user_defined_poststart_commands(devfile_commands: devfile_commands, devfile_events: devfile_events) + end subject(:updated_desired_config) do # Make a fake desired config with one existing fake element, to prove we are appending @@ -49,27 +52,34 @@ }, ] + db_container_non_blocking_script_name = + "database-container-#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" + + main_container_non_blocking_script_name = + "tooling-container-#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" + expect(api_version).to eq("v1") expect(configmap_name).to eq(name) expect(data).to eq( "gl-clone-project-command": clone_project_script, "gl-clone-unshallow-command": clone_unshallow_script, - "gl-init-tools-command": files::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, - create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym => + "gl-init-tools-command": format(files::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, + main_component_name: Shellwords.shellescape("tooling-container")), + "gl-start-sshd-command": format(files::INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT, + main_component_name: Shellwords.shellescape("tooling-container")), + "tooling-container-#{create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}": internal_blocking_poststart_commands_script, - create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym => + main_container_non_blocking_script_name.to_sym => non_blocking_poststart_commands_script( - user_command_ids: %w[ - db-component-command-with-working-dir - db-component-command-without-working-dir - main-component-command-without-working-dir - user-defined-command - ], - devfile_commands: devfile_commands + poststart_commands: user_defined_poststart_commands + ), + db_container_non_blocking_script_name.to_sym => + non_blocking_poststart_commands_script( + poststart_commands: user_defined_poststart_commands, + component_name: "database-container" ), "gl-sleep-until-container-is-running-command": sleep_until_container_is_running_script, - "gl-start-sshd-command": files::INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT, "db-component-command-with-working-dir": "echo 'executes postStart command in the specified workingDir'", "db-component-command-without-working-dir": "echo 'executes postStart command in the the container's default WORKDIR'", @@ -78,23 +88,30 @@ "user-defined-command": "echo 'executes postStart command in the specified workingDir'" ) - non_blocking_script = data[create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym] - expect(non_blocking_script).to include( - '(cd test-dir && /workspace-scripts/db-component-command-with-working-dir) || true' + db_non_blocking_script = data[db_container_non_blocking_script_name.to_sym] + main_non_blocking_script = data[main_container_non_blocking_script_name.to_sym] + + expect(db_non_blocking_script).to include( + '(cd test-dir && /workspace-scripts/database-container/db-component-command-with-working-dir) || true' + ) + expect(db_non_blocking_script).to include( + '/workspace-scripts/database-container/db-component-command-without-working-dir || true' ) - expect(non_blocking_script).to include( - '/workspace-scripts/db-component-command-without-working-dir || true' + expect(main_non_blocking_script).to include( + '(cd ${PROJECT_SOURCE}/test-project && ' \ + '/workspace-scripts/tooling-container/main-component-command-without-working-dir) || true' ) - expect(non_blocking_script).to include( - '(cd ${PROJECT_SOURCE}/test-project && /workspace-scripts/main-component-command-without-working-dir) || true' + expect(main_non_blocking_script).to include( + '(cd test-dir && /workspace-scripts/tooling-container/user-defined-command) || true' ) - expect(non_blocking_script).to include('(cd test-dir && /workspace-scripts/user-defined-command) || true') end context "when legacy poststart scripts are used" do let(:processed_devfile) do yaml_safe_load_symbolized( - read_devfile_yaml("example.legacy-poststart-in-container-command-processed-devfile.yaml.erb") + read_devfile_yaml("example.legacy-poststart-in-container-command-processed-devfile.yaml.erb", + is_legacy_poststart: true + ) ) end diff --git a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter_spec.rb index ac656bb6839dee..4c529b23a13184 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/scripts_volume_inserter_spec.rb @@ -7,6 +7,8 @@ let(:name) { "workspacename-scripts-configmap" } let(:processed_devfile) { example_processed_devfile } + let(:devfile_commands) { processed_devfile.fetch(:commands) } + let(:devfile_events) { processed_devfile.fetch(:events) } let(:input_containers) do [ { volumeMounts: [{}] }, @@ -20,7 +22,10 @@ described_class.insert( configmap_name: name, containers: input_containers, - volumes: input_volumes + volumes: input_volumes, + devfile_commands: devfile_commands, + devfile_events: devfile_events, + processed_devfile: processed_devfile ) end diff --git a/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_start_vscode_script_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_start_vscode_script_spec.rb index 5952e9a8529292..f5110654799f1e 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_start_vscode_script_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_start_vscode_script_spec.rb @@ -3,16 +3,24 @@ require "fast_spec_helper" require "tempfile" require "fileutils" +require "shellwords" RSpec.describe "Remote Development VSCode Startup Script", feature_category: :workspaces do include_context "with constant modules" - let(:script_content) { RemoteDevelopment::Files::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT } + let(:main_component_name) { "tooling-container" } + let(:script_content) do + format( + RemoteDevelopment::Files::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, + main_component_name: Shellwords.shellescape(main_component_name) + ) + end + let(:script_file) { Tempfile.new(%w[start_vscode .sh]) } let(:log_dir) { Dir.mktmpdir } let(:tools_dir) { Dir.mktmpdir } let(:product_json_path) { File.join(tools_dir, "vscode-reh-web/product.json") } - let(:log_file_path) { File.join(log_dir, "start-vscode.log") } + let(:log_file_path) { File.join(log_dir, main_component_name, "start-vscode.log") } let(:extension_marketplace_service_url) { "https://marketplace.example.com" } let(:extension_marketplace_item_url) { "https://item.example.com" } let(:extension_marketplace_resource_url_template) { "https://resource.example.com/{path}" } @@ -52,6 +60,7 @@ def run_script(custom_env = nil) before do # Create the directory structure FileUtils.mkdir_p(File.join(tools_dir, "vscode-reh-web")) + FileUtils.mkdir_p(File.join(log_dir, main_component_name)) # Create a mock product.json file FileUtils.mkdir_p(File.dirname(product_json_path)) diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb index efadbca16eaa7f..e47431f94ba5f7 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb @@ -326,9 +326,9 @@ # Verify the poststart script includes the user-defined command poststart_script = scripts_configmap[:data][ - create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym + :"tooling-container-#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" ] - expect(poststart_script).to include("Running /workspace-scripts/user-defined-command") + expect(poststart_script).to include("Running /workspace-scripts/tooling-container/user-defined-command") end end end diff --git a/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb b/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb index c9a86e84d916f8..fcd5d70e097e70 100644 --- a/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb +++ b/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb @@ -13,13 +13,19 @@ module FixtureFileHelpers # @param [String] project_name # @param [String] namespace_path # @return [String] - def read_devfile_yaml(filename, project_name: "test-project", namespace_path: "test-group") + def read_devfile_yaml( + filename, project_name: "test-project", + namespace_path: "test-group", + main_component_name: "tooling-container", + is_legacy_poststart: false + ) erb_devfile_contents = read_fixture_file(filename) fixture_file_binding = FixtureFileErbBinding.new.get_fixture_file_binding devfile_contents = ERB.new(erb_devfile_contents).result(fixture_file_binding) devfile_contents.gsub!('http://localhost/', root_url) devfile_contents.gsub!('test-project', project_name) devfile_contents.gsub!('test-group', namespace_path) + devfile_contents.gsub!('%s', main_component_name) unless is_legacy_poststart format_clone_project_script!(devfile_contents, project_name: project_name, namespace_path: namespace_path) diff --git a/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb b/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb index e4d5c8ed6ccfa4..1ac74c434653a1 100644 --- a/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb +++ b/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb @@ -752,11 +752,13 @@ def workspace_deployment( format( files_module::KUBERNETES_POSTSTART_HOOK_COMMAND, run_internal_blocking_poststart_commands_script_file_path: - "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/" \ + "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/" \ "#{create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", # rubocop:disable Layout/LineEndStringConcatenationIndentation -- Match default RubyMine formatting run_non_blocking_poststart_commands_script_file_path: - "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/" \ - "#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" # rubocop:disable Layout/LineEndStringConcatenationIndentation -- Match default RubyMine formatting + "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/" \ + "#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", # rubocop:disable Layout/LineEndStringConcatenationIndentation -- Match default RubyMine formatting + component_name: "tooling-container", + main_component_name: "tooling-container" ) ] } @@ -813,11 +815,13 @@ def workspace_deployment( format( files_module::KUBERNETES_POSTSTART_HOOK_COMMAND, run_internal_blocking_poststart_commands_script_file_path: - "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/" \ + "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/database-container/" \ "#{create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", # rubocop:disable Layout/LineEndStringConcatenationIndentation -- Match default RubyMine formatting run_non_blocking_poststart_commands_script_file_path: - "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/" \ - "#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" # rubocop:disable Layout/LineEndStringConcatenationIndentation -- Match default RubyMine formatting + "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/database-container/" \ + "#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", # rubocop:disable Layout/LineEndStringConcatenationIndentation -- Match default RubyMine formatting + component_name: "database-container", + main_component_name: "tooling-container" ) ] } @@ -943,7 +947,57 @@ def workspace_deployment( sources: [ { configMap: { - name: "#{workspace_name}-scripts-configmap" + name: "#{workspace_name}-scripts-configmap", + items: [ + { + key: "gl-clone-project-command", + path: "tooling-container/gl-clone-project-command" + }, + { + key: "gl-clone-unshallow-command", + path: "tooling-container/gl-clone-unshallow-command" + }, + { + key: "gl-start-sshd-command", + path: "tooling-container/gl-start-sshd-command" + }, + { + key: "gl-init-tools-command", + path: "tooling-container/gl-init-tools-command" + }, + { + key: "gl-sleep-until-container-is-running-command", + path: "tooling-container/gl-sleep-until-container-is-running-command" + }, + { + key: "db-component-command-with-working-dir", + path: "database-container/db-component-command-with-working-dir" + }, + { + key: "db-component-command-without-working-dir", + path: "database-container/db-component-command-without-working-dir" + }, + { + key: "main-component-command-without-working-dir", + path: "tooling-container/main-component-command-without-working-dir" + }, + { + key: "user-defined-command", + path: "tooling-container/user-defined-command" + }, + { + key: "tooling-container-gl-run-internal-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-internal-blocking-poststart-commands.sh" + }, + { + key: "tooling-container-gl-run-non-blocking-poststart-commands.sh", + path: "tooling-container/gl-run-non-blocking-poststart-commands.sh" + }, + { + key: "database-container-gl-run-non-blocking-poststart-commands.sh", + path: "database-container/gl-run-non-blocking-poststart-commands.sh" + } + ] } } ] @@ -996,6 +1050,12 @@ def workspace_deployment( } } deployment[:spec][:template][:spec][:containers][1][:lifecycle] + + scripts_volume = deployment[:spec][:template][:spec][:volumes].find do |volume| + volume[:name] == create_constants_module::WORKSPACE_SCRIPTS_VOLUME_NAME + end + + scripts_volume[:projected][:sources][0][:configMap].delete(:items) if scripts_volume end if legacy_no_poststart_container_command @@ -1256,27 +1316,44 @@ def workspace_network_policy( } end + # @param [Array] devfile_commands + # @param [Hash] devfile_events + # @return [Array] + def extract_user_defined_poststart_commands(devfile_commands:, devfile_events:) + poststart_command_ids = devfile_events.fetch(:postStart) + + poststart_commands = poststart_command_ids.filter_map do |id| + devfile_commands.find { |cmd| cmd[:id] == id } + end + + _, non_blocking_commands = poststart_commands.partition do |poststart_cmd| + poststart_cmd&.dig(:exec, :label)&.starts_with?(workspace_operations_constants_module::INTERNAL_COMMAND_LABEL) + end + + non_blocking_commands + end + # @return [String] def internal_blocking_poststart_commands_script data_volume_path = workspace_operations_constants_module::WORKSPACE_DATA_VOLUME_PATH <<~SCRIPT #!/bin/sh echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-project-command..." - (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-project-command) || true - echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-project-command." + echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-clone-project-command..." + (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-clone-project-command) || true + echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-clone-project-command." echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-unshallow-command..." - (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-unshallow-command) || true - echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-unshallow-command." + echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-clone-unshallow-command..." + (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-clone-unshallow-command) || true + echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-clone-unshallow-command." echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-start-sshd-command..." - (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-start-sshd-command) || true - echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-start-sshd-command." + echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-start-sshd-command..." + (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-start-sshd-command) || true + echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-start-sshd-command." echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-init-tools-command..." - (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-init-tools-command) || true - echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-init-tools-command." + echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-init-tools-command..." + (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-init-tools-command) || true + echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-init-tools-command." SCRIPT end @@ -1286,27 +1363,36 @@ def internal_blocking_poststart_commands_script # @param [String] main_component_name # @return [String] def non_blocking_poststart_commands_script( - user_command_ids:, - devfile_commands:, + poststart_commands:, project_path: "test-project", + component_name: "tooling-container", main_component_name: "tooling-container" ) data_volume_path = workspace_operations_constants_module::WORKSPACE_DATA_VOLUME_PATH + script = <<~SCRIPT - #!/bin/sh - echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-sleep-until-container-is-running-command..." - (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-sleep-until-container-is-running-command) || true - echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-sleep-until-container-is-running-command." + #!/bin/sh SCRIPT - # Add user-defined commands if any - user_command_ids.each do |command_id| - command = devfile_commands.find { |cmd| cmd[:id] == command_id } - script_execution = "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/#{command_id}" + if component_name == main_component_name + script += <<~SCRIPT + echo "$(date -Iseconds): ----------------------------------------" + echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-sleep-until-container-is-running-command..." + (cd #{data_volume_path} && #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-sleep-until-container-is-running-command) || true + echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/tooling-container/gl-sleep-until-container-is-running-command." + SCRIPT + end + # Add user-defined commands if any + poststart_commands.each do |command| working_dir = command.dig(:exec, :workingDir) - component_name = command.dig(:exec, :component) + command_component_name = command.dig(:exec, :component) + + next unless command_component_name == component_name + + poststart_command_path = "#{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/" \ + "#{component_name}/#{command[:id]}" + script_execution = poststart_command_path effective_working_dir = if working_dir.present? working_dir @@ -1314,13 +1400,13 @@ def non_blocking_poststart_commands_script( "${PROJECT_SOURCE}/#{Shellwords.shellescape(project_path)}" end - script_execution = "(cd #{effective_working_dir} && #{script_execution})" if effective_working_dir.present? + script_execution = "(cd #{effective_working_dir} && #{poststart_command_path})" if effective_working_dir.present? script += <<~SCRIPT echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/#{command_id}..." + echo "$(date -Iseconds): Running #{poststart_command_path}..." #{script_execution} || true - echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/#{command_id}." + echo "$(date -Iseconds): Finished running #{poststart_command_path}." SCRIPT end @@ -1375,7 +1461,8 @@ def clone_unshallow_script format( RemoteDevelopment::Files::INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT, project_cloning_successful_file: Shellwords.shellescape(project_cloning_successful_file), - clone_dir: Shellwords.shellescape(clone_dir) + clone_dir: Shellwords.shellescape(clone_dir), + main_component_name: Shellwords.shellescape("tooling-container") ) end @@ -1405,30 +1492,43 @@ def scripts_configmap( gitlab_workspaces_proxy_http_enabled:, user_defined_commands: ) - user_command_ids = user_defined_commands.pluck(:id) - data = { "gl-start-agentw-command": files_module::INTERNAL_POSTSTART_COMMAND_START_AGENTW_SCRIPT, "gl-clone-project-command": clone_project_script, "gl-clone-unshallow-command": clone_unshallow_script, - "gl-init-tools-command": files_module::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, - create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym => + "gl-init-tools-command": format(files_module::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, + main_component_name: Shellwords.shellescape("tooling-container")), + "gl-start-sshd-command": format(files_module::INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT, + main_component_name: Shellwords.shellescape("tooling-container")), + "tooling-container-#{create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}": internal_blocking_poststart_commands_script, - create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym => + "tooling-container-#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}": non_blocking_poststart_commands_script( - user_command_ids: user_command_ids, - devfile_commands: user_defined_commands + poststart_commands: user_defined_commands ), - "gl-sleep-until-container-is-running-command": sleep_until_container_is_running_script, - "gl-start-sshd-command": files_module::INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT + "gl-sleep-until-container-is-running-command": sleep_until_container_is_running_script } if legacy_poststart_container_command - data.delete(create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym) - data.delete(create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym) + data.delete(:"tooling-container-#{create_constants_module::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}") + data.delete(:"tooling-container-#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}") data.delete(:"gl-clone-unshallow-command") data[create_constants_module::LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym] = legacy_poststart_commands_script + data[:"gl-init-tools-command"] = files_module::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT + data[:"gl-start-sshd-command"] = files_module::INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT + end + + container_names_with_poststart_commands = user_defined_commands.map { |cmd| cmd[:exec][:component] }.uniq + + container_names_with_poststart_commands.each do |container| + next if container == "tooling-container" + + data[:"#{container}-#{create_constants_module::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}"] = + non_blocking_poststart_commands_script( + poststart_commands: user_defined_commands, + component_name: container + ) end data.delete(:"gl-start-agentw-command") if gitlab_workspaces_proxy_http_enabled -- GitLab From 7db9740b1a6f7579e23e3328f418481964cd9c3c Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Fri, 12 Sep 2025 21:42:19 -0400 Subject: [PATCH 2/3] cleanup incorrect indenting and filename typo --- .../kubernetes_poststart_hook_command.sh | 18 +++--- ...internal_poststart_command_start_vscode.sh | 56 +++++++++---------- ...ation_spec.rb => main_integration_spec.rb} | 0 3 files changed, 37 insertions(+), 37 deletions(-) rename ee/spec/lib/remote_development/workspace_operations/create/desired_config/{main_integeration_spec.rb => main_integration_spec.rb} (100%) diff --git a/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh b/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh index 3ba18943e7710d..44e59c7800bba2 100644 --- a/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh +++ b/ee/lib/remote_development/workspace_operations/create/desired_config/kubernetes_poststart_hook_command.sh @@ -7,23 +7,23 @@ mkdir -p "${GL_WORKSPACE_LOGS_DIR}/${component_name}" ln -sf "${GL_WORKSPACE_LOGS_DIR}" /tmp { - echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running poststart commands for workspace..." + echo "$(date -Iseconds): ----------------------------------------" + echo "$(date -Iseconds): Running poststart commands for workspace..." }>> "${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" if [ "${component_name}" = "${main_component_name}" ]; then - { - echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running internal blocking poststart commands script..." - } >> "${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" + { + echo "$(date -Iseconds): ----------------------------------------" + echo "$(date -Iseconds): Running internal blocking poststart commands script..." + } >> "${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" - "%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log" + "%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log" fi { - echo "$(date -Iseconds): ----------------------------------------" - echo "$(date -Iseconds): Running non-blocking poststart commands script..." + echo "$(date -Iseconds): ----------------------------------------" + echo "$(date -Iseconds): Running non-blocking poststart commands script..." } >> "${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" "%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log" & diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh index a79697af0e80f4..db291f7eef9885 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_start_vscode.sh @@ -29,52 +29,52 @@ exec 1>>"${LOG_FILE}" 2>&1 # # $GITLAB_WORKFLOW_TOKEN_FILE - the contents of this file populate GITLAB_WORKFLOW_TOKEN if it is not set. if [ -z "${GL_TOOLS_DIR}" ]; then - echo "$(date -Iseconds): \$GL_TOOLS_DIR is not set" - exit 1 + echo "$(date -Iseconds): \$GL_TOOLS_DIR is not set" + exit 1 fi if [ -z "${GL_VSCODE_LOG_LEVEL}" ]; then - GL_VSCODE_LOG_LEVEL="info" - echo "$(date -Iseconds): Setting default GL_VSCODE_LOG_LEVEL=${GL_VSCODE_LOG_LEVEL}" + GL_VSCODE_LOG_LEVEL="info" + echo "$(date -Iseconds): Setting default GL_VSCODE_LOG_LEVEL=${GL_VSCODE_LOG_LEVEL}" fi if [ -z "${GL_VSCODE_PORT}" ]; then - GL_VSCODE_PORT="60001" - echo "$(date -Iseconds): Setting default GL_VSCODE_PORT=${GL_VSCODE_PORT}" + GL_VSCODE_PORT="60001" + echo "$(date -Iseconds): Setting default GL_VSCODE_PORT=${GL_VSCODE_PORT}" fi if [ -z "${GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL}" ]; then - GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL="https://open-vsx.org/vscode/gallery" - echo "$(date -Iseconds): Setting default GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL=${GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL}" + GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL="https://open-vsx.org/vscode/gallery" + echo "$(date -Iseconds): Setting default GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL=${GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL}" fi if [ -z "${GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL}" ]; then - GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL="https://open-vsx.org/vscode/item" - echo "$(date -Iseconds): Setting default GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL=${GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL}" + GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL="https://open-vsx.org/vscode/item" + echo "$(date -Iseconds): Setting default GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL=${GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL}" fi if [ -z "${GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE}" ]; then - GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE="https://open-vsx.org/api/{publisher}/{name}/{version}/file/{path}" - echo "$(date -Iseconds): Setting default GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE=${GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE}" + GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE="https://open-vsx.org/api/{publisher}/{name}/{version}/file/{path}" + echo "$(date -Iseconds): Setting default GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE=${GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE}" fi PRODUCT_JSON_FILE="${GL_TOOLS_DIR}/vscode-reh-web/product.json" if [ "$GL_VSCODE_IGNORE_VERSION_MISMATCH" = true ]; then - # TODO: remove this section once issue is fixed - https://gitlab.com/gitlab-org/gitlab/-/issues/373669 - # remove "commit" key from product.json to avoid client-server mismatch - # TODO: remove this once we are not worried about version mismatch - # https://gitlab.com/gitlab-org/gitlab/-/issues/373669 - echo "$(date -Iseconds): Ignoring VS Code client-server version mismatch" - sed -i.bak '/"commit"/d' "${PRODUCT_JSON_FILE}" && rm "${PRODUCT_JSON_FILE}.bak" - echo "$(date -Iseconds): Removed 'commit' key from ${PRODUCT_JSON_FILE}" + # TODO: remove this section once issue is fixed - https://gitlab.com/gitlab-org/gitlab/-/issues/373669 + # remove "commit" key from product.json to avoid client-server mismatch + # TODO: remove this once we are not worried about version mismatch + # https://gitlab.com/gitlab-org/gitlab/-/issues/373669 + echo "$(date -Iseconds): Ignoring VS Code client-server version mismatch" + sed -i.bak '/"commit"/d' "${PRODUCT_JSON_FILE}" && rm "${PRODUCT_JSON_FILE}.bak" + echo "$(date -Iseconds): Removed 'commit' key from ${PRODUCT_JSON_FILE}" fi if [ "$GL_VSCODE_ENABLE_MARKETPLACE" = true ]; then - EXTENSIONS_GALLERY_KEY="{\\n\\t\"extensionsGallery\": {\\n\\t\\t\"serviceUrl\": \"${GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL}\",\\n\\t\\t\"itemUrl\": \"${GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL}\",\\n\\t\\t\"resourceUrlTemplate\": \"${GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE}\"\\n\\t}," - echo "$(date -Iseconds): '${EXTENSIONS_GALLERY_KEY}' in '${PRODUCT_JSON_FILE}' at the beginning of the file" - sed -i.bak "1s|.*|$EXTENSIONS_GALLERY_KEY|" "${PRODUCT_JSON_FILE}" && rm "${PRODUCT_JSON_FILE}.bak" - echo "$(date -Iseconds): Extensions gallery configuration added" + EXTENSIONS_GALLERY_KEY="{\\n\\t\"extensionsGallery\": {\\n\\t\\t\"serviceUrl\": \"${GL_VSCODE_EXTENSION_MARKETPLACE_SERVICE_URL}\",\\n\\t\\t\"itemUrl\": \"${GL_VSCODE_EXTENSION_MARKETPLACE_ITEM_URL}\",\\n\\t\\t\"resourceUrlTemplate\": \"${GL_VSCODE_EXTENSION_MARKETPLACE_RESOURCE_URL_TEMPLATE}\"\\n\\t}," + echo "$(date -Iseconds): '${EXTENSIONS_GALLERY_KEY}' in '${PRODUCT_JSON_FILE}' at the beginning of the file" + sed -i.bak "1s|.*|$EXTENSIONS_GALLERY_KEY|" "${PRODUCT_JSON_FILE}" && rm "${PRODUCT_JSON_FILE}.bak" + echo "$(date -Iseconds): Extensions gallery configuration added" fi echo "$(date -Iseconds): Contents of ${PRODUCT_JSON_FILE} are: " @@ -92,11 +92,11 @@ echo "$(date -Iseconds): - Workspace trust disabled: yes" # The server execution is backgrounded to allow for the rest of the internal init scripts to execute. "${GL_TOOLS_DIR}/vscode-reh-web/bin/gitlab-webide-server" \ - --host "${GL_VSCODE_HOST}" \ - --port "${GL_VSCODE_PORT}" \ - --log "${GL_VSCODE_LOG_LEVEL}" \ - --without-connection-token \ - --disable-workspace-trust & + --host "${GL_VSCODE_HOST}" \ + --port "${GL_VSCODE_PORT}" \ + --log "${GL_VSCODE_LOG_LEVEL}" \ + --without-connection-token \ + --disable-workspace-trust & echo "$(date -Iseconds): Finished starting GitLab Fork of VS Code server in background" echo "$(date -Iseconds): ----------------------------------------" diff --git a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integeration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integration_spec.rb similarity index 100% rename from ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integeration_spec.rb rename to ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integration_spec.rb -- GitLab From d3f0c05b64c1f6a320dc670d2766055eb05b6b22 Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Mon, 15 Sep 2025 15:20:23 -0400 Subject: [PATCH 3/3] update specs to have 2-space indentation script --- .../create/internal_poststart_commands_inserter.rb | 3 ++- .../create/desired_config/main_integration_spec.rb | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb b/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb index d49450555e5a86..3fa64d93aa5530 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter.rb @@ -100,7 +100,8 @@ def self.insert(context) format( INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT, project_cloning_successful_file: Shellwords.shellescape(project_cloning_successful_file), - clone_dir: Shellwords.shellescape(clone_dir) + clone_dir: Shellwords.shellescape(clone_dir), + main_component_name: Shellwords.shellescape(main_component_name) ) commands << { diff --git a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integration_spec.rb index 0e9a668216a955..fbfaede702689e 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integration_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/desired_config/main_integration_spec.rb @@ -580,7 +580,7 @@ def expected_desired_config_array_with_desired_state_running command: [ "/bin/sh", "-c", - "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -1182,7 +1182,7 @@ def expected_desired_config_array_with_desired_state_running_with_use_kubernetes command: [ "/bin/sh", "-c", - "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -1784,7 +1784,7 @@ def expected_desired_config_array_with_desired_state_stopped command: [ "/bin/sh", "-c", - "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -3494,7 +3494,7 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_runnin command: [ "/bin/sh", "-c", - "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } @@ -4083,7 +4083,7 @@ def expected_desired_config_array_for_shared_namespace_with_desired_state_stoppe command: [ "/bin/sh", "-c", - "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" + "#!/bin/sh\n\ncomponent_name=\"tooling-container\"\nmain_component_name=\"tooling-container\"\n\nmkdir -p \"${GL_WORKSPACE_LOGS_DIR}/${component_name}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running poststart commands for workspace...\"\n}>> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\nif [ \"${component_name}\" = \"${main_component_name}\" ]; then\n {\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running internal blocking poststart commands script...\"\n } >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n \"/workspace-scripts/tooling-container/gl-run-internal-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\"\nfi\n\n{\n echo \"$(date -Iseconds): ----------------------------------------\"\n echo \"$(date -Iseconds): Running non-blocking poststart commands script...\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\"\n\n\"/workspace-scripts/tooling-container/gl-run-non-blocking-poststart-commands.sh\" 1>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stdout.log\" 2>>\"${GL_WORKSPACE_LOGS_DIR}/${component_name}/poststart-stderr.log\" &\n" ] } } -- GitLab