From 18a416a49bf73ce7cfe131bccea371ebe5286b14 Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Wed, 18 Jun 2025 13:01:42 -0400 Subject: [PATCH 1/5] Add feature flag for shallow cloning EE: true --- .../beta/workspaces_shallow_clone_project.yml | 9 ++++ .../create/create_constants.rb | 1 + ...nternal_poststart_command_clone_project.sh | 26 +++++++++- ...internal_poststart_command_start_vscode.sh | 7 ++- .../internal_poststart_commands_inserter.rb | 5 +- ...ternal_poststart_commands_inserter_spec.rb | 51 ++++++++++++++++--- ...ponent_updater_start_vscode_script_spec.rb | 2 +- .../fixture_file_helpers.rb | 1 + .../remote_development_shared_contexts.rb | 3 +- 9 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 ee/config/feature_flags/beta/workspaces_shallow_clone_project.yml diff --git a/ee/config/feature_flags/beta/workspaces_shallow_clone_project.yml b/ee/config/feature_flags/beta/workspaces_shallow_clone_project.yml new file mode 100644 index 00000000000000..d8e96cb15d02c5 --- /dev/null +++ b/ee/config/feature_flags/beta/workspaces_shallow_clone_project.yml @@ -0,0 +1,9 @@ +--- +name: workspaces_shallow_clone_project +feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/543982 +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/194906 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/550330 +milestone: '18.2' +group: group::remote development +type: beta +default_enabled: false diff --git a/ee/lib/remote_development/workspace_operations/create/create_constants.rb b/ee/lib/remote_development/workspace_operations/create/create_constants.rb index f271cd6a3fe6de..300688c47a3676 100644 --- a/ee/lib/remote_development/workspace_operations/create/create_constants.rb +++ b/ee/lib/remote_development/workspace_operations/create/create_constants.rb @@ -19,6 +19,7 @@ module CreateConstants LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-poststart-commands.sh" NAMESPACE_PREFIX = "gl-rd-ns" PROJECT_CLONING_SUCCESSFUL_FILE_NAME = ".gl_project_cloning_successful" + PROJECT_CLONING_DEPTH_FLAG = "--depth 15" RUN_AS_USER = 5001 RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-internal-blocking-poststart-commands.sh" RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-non-blocking-poststart-commands.sh" diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh index fe61c361fd28c5..bf7d925610cdb3 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh @@ -21,7 +21,7 @@ then fi echo "$(date -Iseconds): Cloning project" -git clone --branch "%s" "%s" "%s" +git clone --branch "%s" "%s" "%s" %s exit_code=$? # Once cloning is successful, create the file which is used in the check above. @@ -31,9 +31,33 @@ then echo "$(date -Iseconds): Project cloning successful" touch "%s" echo "$(date -Iseconds): Updated file to indicate successful project cloning" + + if [ -n "%s" ]; then + # Define log file path + UNSHALLOW_LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/project-unshallow.log" + + mkdir -p "$(dirname "${UNSHALLOW_LOG_FILE}")" + + echo "$(date -Iseconds): Starting unshallow in background, logging to ${UNSHALLOW_LOG_FILE}" + { + cd "%s" || { echo "$(date -Iseconds): Failed to cd to clone directory"; exit 1; } + + if [ -f .git/shallow ]; then + echo "$(date -Iseconds): Repository is shallow, proceeding with unshallow" + if git fetch --unshallow --progress 2>&1; then + echo "$(date -Iseconds): Unshallow completed successfully" + else + echo "$(date -Iseconds): Unshallow failed with exit code $?" + fi + else + echo "$(date -Iseconds): Repository is not shallow, skipping unshallow" + fi + } >> "${UNSHALLOW_LOG_FILE}" & + fi else echo "$(date -Iseconds): Project cloning failed with exit code: ${exit_code}" >&2 fi echo "$(date -Iseconds): Finished cloning project if necessary." +echo "$(date -Iseconds): ----------------------------------------" exit "${exit_code}" 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 d585b4d5dc25aa..deb62c5b33e2fe 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,10 @@ #!/bin/sh echo "$(date -Iseconds): ----------------------------------------" -echo "$(date -Iseconds): Running main_component_updater_start_vscode.sh with output written to ${GL_WORKSPACE_LOGS_DIR}/start_vscode.log..." +echo "$(date -Iseconds): Running main_component_updater_start_vscode.sh with output written to ${GL_WORKSPACE_LOGS_DIR}/start-vscode.log..." # Define log file path -LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/start_vscode.log" +LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/start-vscode.log" mkdir -p "$(dirname "${LOG_FILE}")" @@ -89,8 +89,7 @@ echo "$(date -Iseconds): - Log level: ${GL_VSCODE_LOG_LEVEL}" echo "$(date -Iseconds): - Without connection token: yes" echo "$(date -Iseconds): - Workspace trust disabled: yes" -# For the actual server execution, we need to make sure it doesn't get backgrounded -# and its output continues going to the log file +# 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}" \ 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 5016c9924ca65a..9a66cb9ae0cabf 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 @@ -37,6 +37,8 @@ def self.insert(context) clone_dir = "#{volume_path}/#{project.path}" project_url = project.http_url_to_repo + clone_depth = Feature.enabled?(:workspaces_shallow_clone_project, project) ? PROJECT_CLONING_DEPTH_FLAG : "" + # Add the clone_project event clone_project_command_id = "gl-clone-project-command" clone_project_script = @@ -45,7 +47,8 @@ def self.insert(context) project_cloning_successful_file: Shellwords.shellescape(project_cloning_successful_file), clone_dir: Shellwords.shellescape(clone_dir), project_ref: Shellwords.shellescape(project_ref), - project_url: Shellwords.shellescape(project_url) + project_url: Shellwords.shellescape(project_url), + clone_depth: clone_depth ) # NOTE: We will always have exactly one main_component found, because we have already diff --git a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb index 2d60c336a9d8fe..11f9359a700ece 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require "fast_spec_helper" +require "spec_helper" RSpec.describe RemoteDevelopment::WorkspaceOperations::Create::InternalPoststartCommandsInserter, feature_category: :workspaces do - include_context 'with remote development shared fixtures' + include_context "with remote development shared fixtures" let(:input_processed_devfile) do read_devfile("example.main-container-updated-devfile.yaml.erb") @@ -12,11 +12,10 @@ let(:expected_processed_devfile_name) { "example.internal-poststart-commands-inserted-devfile.yaml.erb" } let(:expected_processed_devfile) { read_devfile(expected_processed_devfile_name) } - let(:project_path) { "test-project" } - let(:project) do - http_url_to_repo = "#{root_url}test-group/#{project_path}.git" - instance_double("Project", path: project_path, http_url_to_repo: http_url_to_repo) # rubocop:disable RSpec/VerifiedDoubleReference -- We're using the quoted version so we can use fast_spec_helper - end + let_it_be(:project_path) { "test-project" } + + let_it_be(:group) { create(:group, name: "test-group") } + let_it_be(:project) { create(:project, group: group, path: project_path) } let(:context) do { @@ -35,11 +34,47 @@ } end + let(:clone_command) do + returned_value[:processed_devfile][:commands].find do |cmd| + cmd[:id] == "gl-clone-project-command" + end + end + subject(:returned_value) do described_class.insert(context) end - it 'updates the devfile' do + it "updates the devfile" do expect(returned_value[:processed_devfile]).to eq(expected_processed_devfile) end + + context "when workspaces_shallow_clone_project feature flag is enabled" do + before do + stub_feature_flags(workspaces_shallow_clone_project: project) + end + + it "includes depth flag in clone command" do + expect(clone_command).not_to be_nil + expect(clone_command[:exec][:commandLine]).to include("--depth 15") + end + + it "includes unshallow logic in clone command" do + command_line = clone_command[:exec][:commandLine] + + expect(command_line).to include("git fetch --unshallow") + expect(command_line).to include("project-unshallow.log") + expect(command_line).to include("if [ -f .git/shallow ]") + end + end + + context "when workspaces_shallow_clone_project feature flag is disabled" do + before do + stub_feature_flags(workspaces_shallow_clone_project: false) + end + + it "does not include depth flag in clone command" do + expect(clone_command).not_to be_nil + expect(clone_command[:exec][:commandLine]).not_to include("--depth") + end + end 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 411fd14f7af5c0..5952e9a8529292 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 @@ -12,7 +12,7 @@ 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, "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}" } 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 e27999c2a1fbf9..b9c6664d45447e 100644 --- a/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb +++ b/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb @@ -59,6 +59,7 @@ def format_clone_project_script!( "%s", Shellwords.shellescape("#{WORKSPACE_DATA_VOLUME_PATH}/#{project_name}") ) + content.gsub!("%s", PROJECT_CLONING_DEPTH_FLAG) nil end 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 81fb3b9102636e..7bbef81b68cb42 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 @@ -1221,7 +1221,8 @@ def clone_project_script project_cloning_successful_file: Shellwords.shellescape(project_cloning_successful_file), clone_dir: Shellwords.shellescape(clone_dir), project_ref: Shellwords.shellescape(project_ref), - project_url: Shellwords.shellescape(project_url) + project_url: Shellwords.shellescape(project_url), + clone_depth: create_constants_module::PROJECT_CLONING_DEPTH_FLAG ) end -- GitLab From 0a930820a09558ac437f8fb4658ab8ff95050135 Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Fri, 20 Jun 2025 13:09:08 -0400 Subject: [PATCH 2/5] Update depth to 10 --- .../workspace_operations/create/create_constants.rb | 2 +- .../create/internal_poststart_commands_inserter_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/lib/remote_development/workspace_operations/create/create_constants.rb b/ee/lib/remote_development/workspace_operations/create/create_constants.rb index 300688c47a3676..f2361466a4da9c 100644 --- a/ee/lib/remote_development/workspace_operations/create/create_constants.rb +++ b/ee/lib/remote_development/workspace_operations/create/create_constants.rb @@ -19,7 +19,7 @@ module CreateConstants LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-poststart-commands.sh" NAMESPACE_PREFIX = "gl-rd-ns" PROJECT_CLONING_SUCCESSFUL_FILE_NAME = ".gl_project_cloning_successful" - PROJECT_CLONING_DEPTH_FLAG = "--depth 15" + PROJECT_CLONING_DEPTH_FLAG = "--depth 10" RUN_AS_USER = 5001 RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-internal-blocking-poststart-commands.sh" RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-non-blocking-poststart-commands.sh" diff --git a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb index 11f9359a700ece..8433829b787a03 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb @@ -55,7 +55,7 @@ it "includes depth flag in clone command" do expect(clone_command).not_to be_nil - expect(clone_command[:exec][:commandLine]).to include("--depth 15") + expect(clone_command[:exec][:commandLine]).to include("--depth 10") end it "includes unshallow logic in clone command" do -- GitLab From 5b126a7e2079bcf84cbbf08073f0c4f4b6e919ca Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Mon, 23 Jun 2025 13:50:27 -0400 Subject: [PATCH 3/5] Address maintainer review --- ee/lib/remote_development/files.rb | 9 ++++- .../create/create_constants.rb | 2 +- ...nternal_poststart_command_clone_project.sh | 30 +++------------- ...ernal_poststart_command_clone_unshallow.sh | 29 +++++++++++++++ .../internal_poststart_commands_inserter.rb | 35 ++++++++++++++++--- ...ststart-commands-inserted-devfile.yaml.erb | 10 ++++++ .../example.processed-devfile.yaml.erb | 10 ++++++ .../scripts_configmap_appender_spec.rb | 1 + ...ternal_poststart_commands_inserter_spec.rb | 22 ++++++++---- .../fixture_file_helpers.rb | 2 +- .../remote_development_shared_contexts.rb | 18 +++++++++- 11 files changed, 128 insertions(+), 40 deletions(-) create mode 100644 ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_unshallow.sh diff --git a/ee/lib/remote_development/files.rb b/ee/lib/remote_development/files.rb index e36ca2cd7d638c..f53acd1233a7fb 100644 --- a/ee/lib/remote_development/files.rb +++ b/ee/lib/remote_development/files.rb @@ -65,6 +65,11 @@ def self.internal_poststart_command_clone_project_script read_file("workspace_operations/create/internal_poststart_command_clone_project.sh") end + # @return [String] content of the file + def self.internal_poststart_command_clone_unshallow_script + read_file("workspace_operations/create/internal_poststart_command_clone_unshallow.sh") + end + #################################### # Please keep this list alphabetized #################################### @@ -75,6 +80,7 @@ def self.internal_poststart_command_clone_project_script DEFAULT_DEVFILE_YAML = default_devfile_yaml GIT_CREDENTIAL_STORE_SCRIPT = git_credential_store_script INTERNAL_POSTSTART_COMMAND_CLONE_PROJECT_SCRIPT = internal_poststart_command_clone_project_script + INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT = internal_poststart_command_clone_unshallow_script INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT = internal_poststart_command_start_vscode_script INTERNAL_POSTSTART_COMMAND_SLEEP_UNTIL_WORKSPACE_IS_RUNNING_SCRIPT = internal_poststart_command_sleep_until_workspace_is_running_script @@ -91,6 +97,7 @@ def self.all_expected_file_constants :DEFAULT_DEVFILE_YAML, :GIT_CREDENTIAL_STORE_SCRIPT, :INTERNAL_POSTSTART_COMMAND_CLONE_PROJECT_SCRIPT, + :INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT, :INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, :INTERNAL_POSTSTART_COMMAND_SLEEP_UNTIL_WORKSPACE_IS_RUNNING_SCRIPT, :INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT, @@ -102,7 +109,7 @@ def self.all_expected_file_constants # @return [void] def self.reload_constants! - expected_count = 9 # Update this count if you add/remove constants + expected_count = 10 # Update this count if you add/remove constants raise "File constants count mismatch!" unless all_expected_file_constants.count == expected_count all_expected_file_constants.each do |const_name| diff --git a/ee/lib/remote_development/workspace_operations/create/create_constants.rb b/ee/lib/remote_development/workspace_operations/create/create_constants.rb index f2361466a4da9c..74f58ac1e4c80e 100644 --- a/ee/lib/remote_development/workspace_operations/create/create_constants.rb +++ b/ee/lib/remote_development/workspace_operations/create/create_constants.rb @@ -19,7 +19,7 @@ module CreateConstants LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-poststart-commands.sh" NAMESPACE_PREFIX = "gl-rd-ns" PROJECT_CLONING_SUCCESSFUL_FILE_NAME = ".gl_project_cloning_successful" - PROJECT_CLONING_DEPTH_FLAG = "--depth 10" + CLONE_DEPTH_OPTION = "--depth 10" RUN_AS_USER = 5001 RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-internal-blocking-poststart-commands.sh" RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME = "gl-run-non-blocking-poststart-commands.sh" diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh index bf7d925610cdb3..90c9305cfd742f 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh @@ -20,8 +20,11 @@ then rm -rf "%s" fi -echo "$(date -Iseconds): Cloning project" -git clone --branch "%s" "%s" "%s" %s +clone_depth_option="%s" +depth_msg="${clone_depth_option:+ with '${clone_depth_option}' option}" + +echo "$(date -Iseconds): Cloning project${depth_msg}" +git clone $clone_depth_option --branch "%s" "%s" "%s" exit_code=$? # Once cloning is successful, create the file which is used in the check above. @@ -31,29 +34,6 @@ then echo "$(date -Iseconds): Project cloning successful" touch "%s" echo "$(date -Iseconds): Updated file to indicate successful project cloning" - - if [ -n "%s" ]; then - # Define log file path - UNSHALLOW_LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/project-unshallow.log" - - mkdir -p "$(dirname "${UNSHALLOW_LOG_FILE}")" - - echo "$(date -Iseconds): Starting unshallow in background, logging to ${UNSHALLOW_LOG_FILE}" - { - cd "%s" || { echo "$(date -Iseconds): Failed to cd to clone directory"; exit 1; } - - if [ -f .git/shallow ]; then - echo "$(date -Iseconds): Repository is shallow, proceeding with unshallow" - if git fetch --unshallow --progress 2>&1; then - echo "$(date -Iseconds): Unshallow completed successfully" - else - echo "$(date -Iseconds): Unshallow failed with exit code $?" - fi - else - echo "$(date -Iseconds): Repository is not shallow, skipping unshallow" - fi - } >> "${UNSHALLOW_LOG_FILE}" & - fi else echo "$(date -Iseconds): Project cloning failed with exit code: ${exit_code}" >&2 fi 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 new file mode 100644 index 00000000000000..b51af681cf19b8 --- /dev/null +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_unshallow.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +if [ -f "%s" ] + then + cd "%s" || { echo "$(date -Iseconds): Failed to cd to clone directory"; exit 1; } + + if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then + echo "$(date -Iseconds): Repository is shallow, proceeding with unshallow" + # Define log file path + UNSHALLOW_LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/clone-unshallow.log" + + mkdir -p "$(dirname "${UNSHALLOW_LOG_FILE}")" + + echo "$(date -Iseconds): Starting unshallow in background, with output written to ${UNSHALLOW_LOG_FILE}" + { + if git fetch --unshallow --progress 2>&1; then + echo "$(date -Iseconds): Unshallow completed successfully" + else + echo "$(date -Iseconds): Unshallow failed with exit code $?" + fi + } >> "${UNSHALLOW_LOG_FILE}" & + else + echo "$(date -Iseconds): Repository is not shallow, skipping unshallow" + fi +else + echo "$(date -Iseconds): Project cloning failed. Unshallow skipped" +fi +echo "$(date -Iseconds): ----------------------------------------" +exit 0 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 9a66cb9ae0cabf..fb7a9efa9ce599 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 @@ -37,7 +37,7 @@ def self.insert(context) clone_dir = "#{volume_path}/#{project.path}" project_url = project.http_url_to_repo - clone_depth = Feature.enabled?(:workspaces_shallow_clone_project, project) ? PROJECT_CLONING_DEPTH_FLAG : "" + clone_depth_option = Feature.enabled?(:workspaces_shallow_clone_project, project) ? CLONE_DEPTH_OPTION : "" # Add the clone_project event clone_project_command_id = "gl-clone-project-command" @@ -48,7 +48,7 @@ def self.insert(context) clone_dir: Shellwords.shellescape(clone_dir), project_ref: Shellwords.shellescape(project_ref), project_url: Shellwords.shellescape(project_url), - clone_depth: clone_depth + clone_depth_option: clone_depth_option ) # NOTE: We will always have exactly one main_component found, because we have already @@ -70,6 +70,26 @@ def self.insert(context) } } + unless clone_depth_option.empty? + # Add the clone_unshallow event + clone_unshallow_command_id = "gl-clone-unshallow-command" + clone_unshallow_script = + format( + INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT, + project_cloning_successful_file: Shellwords.shellescape(project_cloning_successful_file), + clone_dir: Shellwords.shellescape(clone_dir) + ) + + commands << { + id: clone_unshallow_command_id, + exec: { + commandLine: clone_unshallow_script, + component: main_component_name, + label: INTERNAL_BLOCKING_COMMAND_LABEL + } + } + end + # Add the start_sshd event start_sshd_command_id = "gl-start-sshd-command" commands << { @@ -109,13 +129,18 @@ def self.insert(context) } } - # Prepend internal commands so they are executed before any user-defined poststart events. - poststart_events.prepend( + commands_to_prepend = [ clone_project_command_id, start_sshd_command_id, start_vscode_command_id, sleep_until_container_is_running_command_id - ) + ] + + # Insert the unshallow command after the clone command, if the FF is enabled and clone_depth_option is set. + commands_to_prepend.insert(1, clone_unshallow_command_id) unless clone_depth_option.empty? + + # Prepend internal commands so they are executed before any user-defined poststart events. + poststart_events.prepend(*commands_to_prepend) context end diff --git a/ee/spec/fixtures/remote_development/example.internal-poststart-commands-inserted-devfile.yaml.erb b/ee/spec/fixtures/remote_development/example.internal-poststart-commands-inserted-devfile.yaml.erb index 93b06e24fff62a..5e6fdf7b4e14bf 100644 --- a/ee/spec/fixtures/remote_development/example.internal-poststart-commands-inserted-devfile.yaml.erb +++ b/ee/spec/fixtures/remote_development/example.internal-poststart-commands-inserted-devfile.yaml.erb @@ -72,6 +72,15 @@ commands: %> component: tooling-container label: <%= INTERNAL_BLOCKING_COMMAND_LABEL %> + - id: gl-clone-unshallow-command + exec: + commandLine: | + <%= + script = INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT + indent_yaml_literal(script, 8) + %> + component: tooling-container + label: <%= INTERNAL_BLOCKING_COMMAND_LABEL %> - id: gl-start-sshd-command exec: commandLine: | @@ -101,6 +110,7 @@ events: - gl-tools-injector-command postStart: - gl-clone-project-command + - gl-clone-unshallow-command - gl-start-sshd-command - gl-init-tools-command - gl-sleep-until-container-is-running-command diff --git a/ee/spec/fixtures/remote_development/example.processed-devfile.yaml.erb b/ee/spec/fixtures/remote_development/example.processed-devfile.yaml.erb index 6e824aaa12d67e..6d683c9da64e5a 100644 --- a/ee/spec/fixtures/remote_development/example.processed-devfile.yaml.erb +++ b/ee/spec/fixtures/remote_development/example.processed-devfile.yaml.erb @@ -84,6 +84,15 @@ commands: %> component: tooling-container label: <%= INTERNAL_BLOCKING_COMMAND_LABEL %> + - id: gl-clone-unshallow-command + exec: + commandLine: | + <%= + script = INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT + indent_yaml_literal(script, 8) + %> + component: tooling-container + label: <%= INTERNAL_BLOCKING_COMMAND_LABEL %> - id: gl-start-sshd-command exec: commandLine: | @@ -113,6 +122,7 @@ events: - gl-tools-injector-command postStart: - gl-clone-project-command + - gl-clone-unshallow-command - gl-start-sshd-command - gl-init-tools-command - gl-sleep-until-container-is-running-command 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 afe962b5a7f196..a9dfe811fe2779 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 @@ -51,6 +51,7 @@ 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 => internal_blocking_poststart_commands_script, diff --git a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb index 8433829b787a03..d26cd64cb8d2a9 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb @@ -40,6 +40,12 @@ end end + let(:clone_unshallow_command) do + returned_value[:processed_devfile][:commands].find do |cmd| + cmd[:id] == "gl-clone-unshallow-command" + end + end + subject(:returned_value) do described_class.insert(context) end @@ -53,28 +59,32 @@ stub_feature_flags(workspaces_shallow_clone_project: project) end - it "includes depth flag in clone command" do + it "includes depth option in clone command" do expect(clone_command).not_to be_nil expect(clone_command[:exec][:commandLine]).to include("--depth 10") end it "includes unshallow logic in clone command" do - command_line = clone_command[:exec][:commandLine] + command_line = clone_unshallow_command[:exec][:commandLine] expect(command_line).to include("git fetch --unshallow") - expect(command_line).to include("project-unshallow.log") - expect(command_line).to include("if [ -f .git/shallow ]") + expect(command_line).to include("clone-unshallow.log") + expect(command_line).to include('if [ "$(git rev-parse --is-shallow-repository)" = "true" ]') end end - context "when workspaces_shallow_clone_project feature flag is disabled" do + context "when workspaces_shallow_clone_project feature option is disabled" do before do stub_feature_flags(workspaces_shallow_clone_project: false) end - it "does not include depth flag in clone command" do + it "does not include depth option in clone command" do expect(clone_command).not_to be_nil expect(clone_command[:exec][:commandLine]).not_to include("--depth") end + + it "does not add clone unshallow command" do + expect(clone_unshallow_command).to be_nil + 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 b9c6664d45447e..c9a86e84d916f8 100644 --- a/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb +++ b/ee/spec/support/helpers/remote_development/fixture_file_helpers.rb @@ -59,7 +59,7 @@ def format_clone_project_script!( "%s", Shellwords.shellescape("#{WORKSPACE_DATA_VOLUME_PATH}/#{project_name}") ) - content.gsub!("%s", PROJECT_CLONING_DEPTH_FLAG) + content.gsub!("%s", CLONE_DEPTH_OPTION) nil end 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 7bbef81b68cb42..a458367fe77d8e 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 @@ -1167,6 +1167,8 @@ def internal_blocking_poststart_commands_script #!/bin/sh echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-project-command..." #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-project-command || true + echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-unshallow-command..." + #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-unshallow-command || true echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-start-sshd-command..." #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-start-sshd-command || true echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-init-tools-command..." @@ -1222,7 +1224,19 @@ def clone_project_script clone_dir: Shellwords.shellescape(clone_dir), project_ref: Shellwords.shellescape(project_ref), project_url: Shellwords.shellescape(project_url), - clone_depth: create_constants_module::PROJECT_CLONING_DEPTH_FLAG + clone_depth_option: create_constants_module::CLONE_DEPTH_OPTION + ) + end + + # @return [String] + def clone_unshallow_script + volume_path = workspace_operations_constants_module::WORKSPACE_DATA_VOLUME_PATH + project_cloning_successful_file = "#{volume_path}/#{create_constants_module::PROJECT_CLONING_SUCCESSFUL_FILE_NAME}" + clone_dir = "#{workspace_operations_constants_module::WORKSPACE_DATA_VOLUME_PATH}/test-project" + 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) ) end @@ -1254,6 +1268,7 @@ def scripts_configmap( data = { "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 => internal_blocking_poststart_commands_script, @@ -1266,6 +1281,7 @@ def scripts_configmap( 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(:"gl-clone-unshallow-command") data[create_constants_module::LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME.to_sym] = legacy_poststart_commands_script end -- GitLab From acea8786c0292ef6a606e84540ec99af16eb368a Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Tue, 24 Jun 2025 20:03:50 -0400 Subject: [PATCH 4/5] Apply patch with suggested changes --- ...nternal_poststart_command_clone_project.sh | 10 ++-- ...ernal_poststart_command_clone_unshallow.sh | 50 +++++++++++-------- ...ommand_sleep_until_workspace_is_running.sh | 1 + .../internal_poststart_command_start_sshd.sh | 8 +-- ...internal_poststart_command_start_vscode.sh | 5 +- .../internal_poststart_commands_inserter.rb | 10 +++- ...ternal_poststart_commands_inserter_spec.rb | 47 ++++++++--------- 7 files changed, 78 insertions(+), 53 deletions(-) diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh index 90c9305cfd742f..6480bc1ac63cea 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_clone_project.sh @@ -8,7 +8,8 @@ echo "$(date -Iseconds): Cloning project if necessary..." # If the file does not exist, clone the project. if [ -f "%s" ] then - echo "$(date -Iseconds): Project cloning was already successful" + echo "$(date -Iseconds): Project cloning was already successful, because '%s' file already exists" + echo "$(date -Iseconds): ----------------------------------------" exit 0 fi @@ -21,7 +22,7 @@ then fi clone_depth_option="%s" -depth_msg="${clone_depth_option:+ with '${clone_depth_option}' option}" +depth_msg="${clone_depth_option:+ with \"${clone_depth_option}\" option}" echo "$(date -Iseconds): Cloning project${depth_msg}" git clone $clone_depth_option --branch "%s" "%s" "%s" @@ -33,11 +34,12 @@ if [ "${exit_code}" -eq 0 ] then echo "$(date -Iseconds): Project cloning successful" touch "%s" - echo "$(date -Iseconds): Updated file to indicate successful project cloning" + echo "$(date -Iseconds): Updated '%s' file to indicate successful project cloning" + echo "$(date -Iseconds): Successfully finished cloning project." else echo "$(date -Iseconds): Project cloning failed with exit code: ${exit_code}" >&2 + echo "$(date -Iseconds): Failed to clone project, exit code was ${exit_code}" fi -echo "$(date -Iseconds): Finished cloning project if necessary." echo "$(date -Iseconds): ----------------------------------------" exit "${exit_code}" 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 b51af681cf19b8..be1f77fab0d659 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 @@ -1,29 +1,37 @@ #!/bin/sh -if [ -f "%s" ] - then - cd "%s" || { echo "$(date -Iseconds): Failed to cd to clone directory"; exit 1; } +echo "$(date -Iseconds): ----------------------------------------" - if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then - echo "$(date -Iseconds): Repository is shallow, proceeding with unshallow" - # Define log file path - UNSHALLOW_LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/clone-unshallow.log" +if [ ! -f "%s" ]; then + echo "$(date -Iseconds): Project cloning previously failed. Unshallow skipped" + echo "$(date -Iseconds): ----------------------------------------" + exit 0 +fi - mkdir -p "$(dirname "${UNSHALLOW_LOG_FILE}")" +# shellcheck disable=SC2164 # We assume that 'clone_dir' must exist if 'project_cloning_successful_file' exists +cd "%s" - echo "$(date -Iseconds): Starting unshallow in background, with output written to ${UNSHALLOW_LOG_FILE}" - { - if git fetch --unshallow --progress 2>&1; then - echo "$(date -Iseconds): Unshallow completed successfully" - else - echo "$(date -Iseconds): Unshallow failed with exit code $?" - fi - } >> "${UNSHALLOW_LOG_FILE}" & - else - echo "$(date -Iseconds): Repository is not shallow, skipping unshallow" - fi -else - echo "$(date -Iseconds): Project cloning failed. Unshallow skipped" +if [ "$(git rev-parse --is-shallow-repository)" != "true" ]; then + echo "$(date -Iseconds): Repository is not shallow, skipping unshallow" + echo "$(date -Iseconds): ----------------------------------------" + exit 0 fi + +echo "$(date -Iseconds): Repository is shallow, proceeding with unshallow" +UNSHALLOW_LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/clone-unshallow.log" + +echo "$(date -Iseconds): Starting unshallow in background, with output written to ${UNSHALLOW_LOG_FILE}" +{ + echo "$(date -Iseconds): ----------------------------------------" + echo "$(date -Iseconds): Starting unshallow in background" + if git fetch --unshallow --progress 2>&1; then + echo "$(date -Iseconds): Unshallow completed successfully" + else + echo "$(date -Iseconds): Unshallow failed with exit code $?, removing '%s' file so cloning will be re-attempted on next container start" + rm "%s" + fi + echo "$(date -Iseconds): ----------------------------------------" +} >> "${UNSHALLOW_LOG_FILE}" & + echo "$(date -Iseconds): ----------------------------------------" exit 0 diff --git a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_sleep_until_workspace_is_running.sh b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_sleep_until_workspace_is_running.sh index a4dc9035c950ac..578ca14bc35e34 100644 --- a/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_sleep_until_workspace_is_running.sh +++ b/ee/lib/remote_development/workspace_operations/create/internal_poststart_command_sleep_until_workspace_is_running.sh @@ -9,3 +9,4 @@ while [ "$(cat ${status_file})" != "Running" ]; do done echo "$(date -Iseconds): Workspace state is now 'Running', continuing postStart hook execution." echo "$(date -Iseconds): Finished sleeping until workspace is running." +echo "$(date -Iseconds): ----------------------------------------" 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 cc4adb32df67df..ba3b2b30ff4b92 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,11 +1,13 @@ #!/bin/sh echo "$(date -Iseconds): ----------------------------------------" -echo "$(date -Iseconds): Starting sshd if it is found..." +echo "$(date -Iseconds): Starting sshd in background if it is found..." sshd_path=$(which sshd) if [ -x "${sshd_path}" ]; then - echo "$(date -Iseconds): Starting ${sshd_path} on port ${GL_SSH_PORT} with output written to ${GL_WORKSPACE_LOGS_DIR}/start-sshd.log" + 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): Finished starting sshd in background if it is found." else echo "$(date -Iseconds): 'sshd' not found in path. Not starting SSH server." >&2 + echo "$(date -Iseconds): Failed to start sshd, no sshd executable found" fi -echo "$(date -Iseconds): Finished starting sshd if it is found." +echo "$(date -Iseconds): ----------------------------------------" 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 deb62c5b33e2fe..75d68ac2c18642 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,7 +1,7 @@ #!/bin/sh echo "$(date -Iseconds): ----------------------------------------" -echo "$(date -Iseconds): Running main_component_updater_start_vscode.sh with output written to ${GL_WORKSPACE_LOGS_DIR}/start-vscode.log..." +echo "$(date -Iseconds): Starting GitLab Fork of VS Code server in background with output written to ${GL_WORKSPACE_LOGS_DIR}/start-vscode.log..." # Define log file path LOG_FILE="${GL_WORKSPACE_LOGS_DIR}/start-vscode.log" @@ -96,3 +96,6 @@ echo "$(date -Iseconds): - Workspace trust disabled: yes" --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/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 fb7a9efa9ce599..ae2e1ddb63c931 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 @@ -37,7 +37,7 @@ def self.insert(context) clone_dir = "#{volume_path}/#{project.path}" project_url = project.http_url_to_repo - clone_depth_option = Feature.enabled?(:workspaces_shallow_clone_project, project) ? CLONE_DEPTH_OPTION : "" + clone_depth_option = workspaces_shallow_clone_project_feature_enabled?(project) ? CLONE_DEPTH_OPTION : "" # Add the clone_project event clone_project_command_id = "gl-clone-project-command" @@ -144,6 +144,14 @@ def self.insert(context) context end + + # @param [Project] project + # @return [TrueClass, FalseClass] + def self.workspaces_shallow_clone_project_feature_enabled?(project) + Feature.enabled?(:workspaces_shallow_clone_project, project) + end + + private_class_method :workspaces_shallow_clone_project_feature_enabled? end end end diff --git a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb index d26cd64cb8d2a9..b7fe8073659d93 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/internal_poststart_commands_inserter_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "spec_helper" +require "fast_spec_helper" RSpec.describe RemoteDevelopment::WorkspaceOperations::Create::InternalPoststartCommandsInserter, feature_category: :workspaces do include_context "with remote development shared fixtures" @@ -12,10 +12,11 @@ let(:expected_processed_devfile_name) { "example.internal-poststart-commands-inserted-devfile.yaml.erb" } let(:expected_processed_devfile) { read_devfile(expected_processed_devfile_name) } - let_it_be(:project_path) { "test-project" } - - let_it_be(:group) { create(:group, name: "test-group") } - let_it_be(:project) { create(:project, group: group, path: project_path) } + let(:project_path) { "test-project" } + let(:project) do + http_url_to_repo = "#{root_url}test-group/#{project_path}.git" + instance_double("Project", path: project_path, http_url_to_repo: http_url_to_repo) # rubocop:disable RSpec/VerifiedDoubleReference -- We're using the quoted version so we can use fast_spec_helper + end let(:context) do { @@ -46,37 +47,37 @@ end end + let(:workspaces_shallow_clone_project_feature_enabled) { true } + subject(:returned_value) do described_class.insert(context) end + before do + expect(described_class) # rubocop:disable RSpec/ExpectInHook -- We are intentionally doing an expect here, so we will be forced to remove this code when we remove the feature flag + .to receive(:workspaces_shallow_clone_project_feature_enabled?) + .and_return(workspaces_shallow_clone_project_feature_enabled) + end + it "updates the devfile" do expect(returned_value[:processed_devfile]).to eq(expected_processed_devfile) end - context "when workspaces_shallow_clone_project feature flag is enabled" do - before do - stub_feature_flags(workspaces_shallow_clone_project: project) - end - - it "includes depth option in clone command" do - expect(clone_command).not_to be_nil - expect(clone_command[:exec][:commandLine]).to include("--depth 10") - end + it "includes depth option in clone command" do + expect(clone_command).not_to be_nil + expect(clone_command[:exec][:commandLine]).to include("--depth 10") + end - it "includes unshallow logic in clone command" do - command_line = clone_unshallow_command[:exec][:commandLine] + it "includes unshallow logic in clone command" do + command_line = clone_unshallow_command[:exec][:commandLine] - expect(command_line).to include("git fetch --unshallow") - expect(command_line).to include("clone-unshallow.log") - expect(command_line).to include('if [ "$(git rev-parse --is-shallow-repository)" = "true" ]') - end + expect(command_line).to include("git fetch --unshallow") + expect(command_line).to include("clone-unshallow.log") + expect(command_line).to include("git rev-parse --is-shallow-repository") end context "when workspaces_shallow_clone_project feature option is disabled" do - before do - stub_feature_flags(workspaces_shallow_clone_project: false) - end + let(:workspaces_shallow_clone_project_feature_enabled) { false } it "does not include depth option in clone command" do expect(clone_command).not_to be_nil -- GitLab From ea61141d748ab56759db8cba0ca1ad54f0c6f4f3 Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Wed, 25 Jun 2025 11:58:07 -0400 Subject: [PATCH 5/5] Apply script cleanup patch + remove projecrt_clone_successful_file removal logic --- .../kubernetes_poststart_hook_command.sh | 6 +++++ .../scripts_configmap_appender.rb | 2 ++ ...ernal_poststart_command_clone_unshallow.sh | 5 ++-- ...red_config_generator_golden_master_spec.rb | 26 +++++++++---------- .../remote_development_shared_contexts.rb | 20 ++++++++++++++ 5 files changed, 44 insertions(+), 15 deletions(-) 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..ac5fbfb80ef9b0 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 @@ -3,6 +3,7 @@ mkdir -p "${GL_WORKSPACE_LOGS_DIR}" ln -sf "${GL_WORKSPACE_LOGS_DIR}" /tmp +# shellcheck disable=SC2129 # We area using redirects with a command block as this warning proposes to do. It must be a false positive from the subsequent lines which handle stdout and stderr seprately. { echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running poststart commands for workspace..." @@ -14,8 +15,13 @@ ln -sf "${GL_WORKSPACE_LOGS_DIR}" /tmp "%s" 1>>"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log" 2>>"${GL_WORKSPACE_LOGS_DIR}/poststart-stderr.log" { + echo "$(date -Iseconds): Finished running internal blocking poststart commands script." echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running non-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" & + +{ + echo "$(date -Iseconds): Finished running non-blocking poststart commands script." +} >> "${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log" 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 fe83e18f90875a..b9889b637de4fe 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 @@ -130,8 +130,10 @@ def self.get_poststart_command_script_content(poststart_command_ids:) # See https://github.com/eclipse-che/che/issues/23404#issuecomment-2787779571 # for more context. <<~SH + echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running #{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{poststart_command_id}..." #{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{poststart_command_id} || true + echo "$(date -Iseconds): Finished running #{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{poststart_command_id}." SH end.join 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 be1f77fab0d659..4f8d7c1db61a0f 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 @@ -1,6 +1,7 @@ #!/bin/sh echo "$(date -Iseconds): ----------------------------------------" +echo "$(date -Iseconds): Spawning background process to unshallow repo if necessary..." if [ ! -f "%s" ]; then echo "$(date -Iseconds): Project cloning previously failed. Unshallow skipped" @@ -27,11 +28,11 @@ echo "$(date -Iseconds): Starting unshallow in background, with output written t if git fetch --unshallow --progress 2>&1; then echo "$(date -Iseconds): Unshallow completed successfully" else - echo "$(date -Iseconds): Unshallow failed with exit code $?, removing '%s' file so cloning will be re-attempted on next container start" - rm "%s" + echo "$(date -Iseconds): Unshallow failed with exit code $?" fi echo "$(date -Iseconds): ----------------------------------------" } >> "${UNSHALLOW_LOG_FILE}" & +echo "$(date -Iseconds): Finished spawning background process to unshallow repo." echo "$(date -Iseconds): ----------------------------------------" exit 0 diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_golden_master_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_golden_master_spec.rb index ae0b6e2bdb2470..d6c8f7427579df 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_golden_master_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_golden_master_spec.rb @@ -630,7 +630,7 @@ def golden_master_desired_config_with_include_all_resources_true 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}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n# shellcheck disable=SC2129 # We area using redirects with a command block as this warning proposes to do. It must be a false positive from the subsequent lines which handle stdout and stderr seprately.\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): Finished running internal blocking poststart commands script.\"\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\n{\n echo \"$(date -Iseconds): Finished running non-blocking poststart commands script.\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n" ] } } @@ -948,8 +948,8 @@ def golden_master_desired_config_with_include_all_resources_true namespace: "gl-rd-ns-991-990-fedcba" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/workspace-scripts/gl-internal-example-command-1 || true\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n/workspace-scripts/gl-internal-example-command-2 || true\n", + "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/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/workspace-scripts/gl-internal-example-command-2 || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/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'" } @@ -1210,7 +1210,7 @@ def golden_master_desired_config_with_include_all_resources_false 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}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n# shellcheck disable=SC2129 # We area using redirects with a command block as this warning proposes to do. It must be a false positive from the subsequent lines which handle stdout and stderr seprately.\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): Finished running internal blocking poststart commands script.\"\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\n{\n echo \"$(date -Iseconds): Finished running non-blocking poststart commands script.\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n" ] } } @@ -1528,8 +1528,8 @@ def golden_master_desired_config_with_include_all_resources_false namespace: "gl-rd-ns-991-990-fedcba" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/workspace-scripts/gl-internal-example-command-1 || true\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n/workspace-scripts/gl-internal-example-command-2 || true\n", + "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/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/workspace-scripts/gl-internal-example-command-2 || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/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'" } @@ -2009,7 +2009,7 @@ def golden_master_desired_config_from_legacy_devfile_with_poststart_and_with_inc namespace: "gl-rd-ns-991-990-fedcba" }, data: { - "gl-run-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/workspace-scripts/gl-internal-example-command-1 || true\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n/workspace-scripts/gl-internal-example-command-2 || true\n", + "gl-run-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/workspace-scripts/gl-internal-example-command-1 || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/gl-internal-example-command-1.\"\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n/workspace-scripts/gl-internal-example-command-2 || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/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'" } @@ -2845,7 +2845,7 @@ def golden_master_desired_config_for_shared_namespace_with_include_all_resources 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}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n# shellcheck disable=SC2129 # We area using redirects with a command block as this warning proposes to do. It must be a false positive from the subsequent lines which handle stdout and stderr seprately.\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): Finished running internal blocking poststart commands script.\"\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\n{\n echo \"$(date -Iseconds): Finished running non-blocking poststart commands script.\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n" ] } } @@ -3173,8 +3173,8 @@ def golden_master_desired_config_for_shared_namespace_with_include_all_resources namespace: "default" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/workspace-scripts/gl-internal-example-command-1 || true\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n/workspace-scripts/gl-internal-example-command-2 || true\n", + "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/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/workspace-scripts/gl-internal-example-command-2 || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/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'" } @@ -3413,7 +3413,7 @@ def golden_master_desired_config_for_shared_namespace_with_include_all_resources 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}\"\nln -sf \"${GL_WORKSPACE_LOGS_DIR}\" /tmp\n\n# shellcheck disable=SC2129 # We area using redirects with a command block as this warning proposes to do. It must be a false positive from the subsequent lines which handle stdout and stderr seprately.\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): Finished running internal blocking poststart commands script.\"\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\n{\n echo \"$(date -Iseconds): Finished running non-blocking poststart commands script.\"\n} >> \"${GL_WORKSPACE_LOGS_DIR}/poststart-stdout.log\"\n" ] } } @@ -3741,8 +3741,8 @@ def golden_master_desired_config_for_shared_namespace_with_include_all_resources namespace: "default" }, data: { - "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/workspace-scripts/gl-internal-example-command-1 || true\n", - "gl-run-non-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-2...\"\n/workspace-scripts/gl-internal-example-command-2 || true\n", + "gl-run-internal-blocking-poststart-commands.sh": "#!/bin/sh\necho \"$(date -Iseconds): ----------------------------------------\"\necho \"$(date -Iseconds): Running /workspace-scripts/gl-internal-example-command-1...\"\n/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/workspace-scripts/gl-internal-example-command-2 || true\necho \"$(date -Iseconds): Finished running /workspace-scripts/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/support/shared_contexts/remote_development/remote_development_shared_contexts.rb b/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb index a458367fe77d8e..d575399d3867dd 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 @@ -1165,14 +1165,22 @@ def workspace_network_policy( def internal_blocking_poststart_commands_script <<~SCRIPT #!/bin/sh + echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-project-command..." #{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): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-unshallow-command..." #{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): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-start-sshd-command..." #{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): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-init-tools-command..." #{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." SCRIPT end @@ -1181,15 +1189,19 @@ def internal_blocking_poststart_commands_script def non_blocking_poststart_commands_script(user_command_ids: []) 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..." #{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." SCRIPT # Add user-defined commands if any user_command_ids.each do |command_id| script += <<~SCRIPT + echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/#{command_id}..." #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/#{command_id} || true + echo "$(date -Iseconds): Finished running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/#{command_id}." SCRIPT end @@ -1200,14 +1212,22 @@ def non_blocking_poststart_commands_script(user_command_ids: []) def legacy_poststart_commands_script <<~SCRIPT #!/bin/sh + echo "$(date -Iseconds): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-clone-project-command..." #{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): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-start-sshd-command..." #{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): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-init-tools-command..." #{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): ----------------------------------------" echo "$(date -Iseconds): Running #{create_constants_module::WORKSPACE_SCRIPTS_VOLUME_PATH}/gl-sleep-until-container-is-running-command..." #{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." SCRIPT end -- GitLab