Sha256: 67364efc6cd489151237f92ba656610bb072e8026e1077ec697ba48d5a5eab01

Contents?: true

Size: 1.8 KB

Versions: 12

Compression:

Stored size: 1.8 KB

Contents

class Indocker::Artifacts::Services::Synchronizer
  def initialize(logger:, progress:)
    @logger   = logger
    @progress = progress
  end

  def call(clonner, artifact_servers)
    @logger.info("Syncing git artifacts")

    remote_operations = []

    artifact_servers.each do |artifact, servers|
      remote_operations += servers.map do |server|
        @progress.start_syncing_artifact(server, artifact)

        thread = Thread.new do
          server.synchronize do
            session = Indocker::SshSession.new(
              host: server.host,
              user: server.user,
              port: server.port,
              logger: @logger
            )

            if artifact.is_git?
              @logger.info("Pulling git artifact  #{artifact.name.to_s.green} for #{server.user}@#{server.host}")
              result = clonner.clone(session, artifact.repository)

              if result.exit_code != 0
                @logger.error("Artifact repository :#{artifact.repository.name} was not clonned")
                @logger.error(result.stderr_data)
                exit 1
              end
            end

            artifact.files.each do |artifact_item|
              source_path = artifact.build_source_path(artifact_item.source_path)

              result = session.exec!("mkdir -p #{artifact_item.target_path}")
              result = session.exec!("cp #{source_path} #{artifact_item.target_path}")

              if !result.success?
                @logger.error(result.stdout_data)
                @logger.error(result.stderr_data)
                exit 1
              end
            end

            @progress.finish_syncing_artifact(server, artifact)
          end
        end

        Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :artifact_sync)
      end
    end

    remote_operations
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
indocker-0.3.9 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.8 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.7 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.6 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.5 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.4 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.3 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.2 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.1.18 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.1 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.3.0 lib/indocker/artifacts/services/synchronizer.rb
indocker-0.1.17 lib/indocker/artifacts/services/synchronizer.rb