본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Transfer Service(전송 서비스)

원문 보기 위키 갱신

transfer service는 소스와 대상 사이에서 아티팩트 객체를 전송하는 데 쓰는 단순하고 유연한 서비스예요. API가 유연하다는 건 transfer 인터페이스의 각 구현이 소스-대상 간 전송이 가능한지 스스로 판단한다는 뜻이에요. 덕분에 API 버전을 올리거나 다른 구현에 인터페이스 변경을 떠넘기지 않고도, 새 기능을 구현 쪽에서 바로 추가할 수 있죠.

출처: 문서

본문

transfer service는 소스와 대상 사이에서 아티팩트 객체를 전송하는 데 쓸 수 있는 단순하고 유연한 서비스예요. 유연한 API는 transfer 인터페이스의 각 구현이 소스와 대상 간 전송이 가능한지 직접 결정하도록 허용해요. 그래서 API 버전을 올리거나 다른 구현이 인터페이스 변경을 처리하도록 요구하지 않고도, 새 기능을 구현이 직접 추가할 수 있어요.

transfer service는 libchan 프로젝트가 내놓은 핵심 아이디어 위에 세워졌어요: 바이너리 스트림과 데이터 채널을 1급 객체로 다루는 API가 더 유연하고, 끊임없는 프로토콜·API 업데이트 없이도 더 넓은 활용 사례를 연다는 거죠. 이를 위해 transfer service는 streaming service를 활용해 grpc나 ttrpc를 쓰는 상황에서도 transfer 객체가 바이너리·객체 스트림에 접근할 수 있게 해요.

Transfer API

transfer API는 하나의 연산으로 구성돼 있고, 의도한 동작에 따라 다양한 객체를 넣어 호출할 수 있어요.

Go에서는 API가 다음처럼 보여요:

	Transfer(ctx context.Context, source any, destination any, opts ...Opt) error
}

proto API는 다음과 같아요:

	rpc Transfer(TransferRequest) returns (google.protobuf.Empty);
}

message TransferRequest {
	google.protobuf.Any source = 1;
	google.protobuf.Any destination = 2;
	TransferOptions options = 3;
}

message TransferOptions {
 string progress_stream = 1;
 // Progress min interval
}

Transfer 객체(소스와 대상)

Transfer 연산

소스 대상 설명 로컬 구현 버전
Registry Image Store "pull" 1.7
Image Store Registry "push" 1.7
객체 스트림 (Archive) Image Store "import" 1.7
Image Store 객체 스트림 (Archive) "export" 1.7
객체 스트림 (Layer) Mount/Snapshot "unpack" 미구현
Mount/Snapshot 객체 스트림 (Layer) "diff" 미구현
Image Store Image Store "tag" 1.7
Registry Registry 레지스트리 이미지 미러링 미구현

로컬 containerd 데몬 지원

containerd는 대부분의 기본 transfer 연산을 구현하는 단일 내장 transfer 플러그인을 갖고 있어요. 로컬 플러그인은 다른 containerd 플러그인과 같은 방식으로 설정할 수 있어요

[plugins."io.containerd.transfer.v1"]

다이어그램

Pull 구성 요소

subgraph containerd Client
  Client(Client)
end
subgraph containerd
  subgraph Service
    Streaming(Streaming Service)
    Transfer(Transfer Service)
  end
  subgraph Transfer objects
    RS(Registry Source)
    ISD(Image Store Destination)
  end
  subgraph Backend
    R(Resolver)
    CS(ContentStore)
    IS(Image Store)
    S(Snapshotter)
  end
end
Reg(((Remote Registry)))

Client-- Create Stream --> Streaming
Client-- Pull via Transfer --> Transfer
Transfer-- Get Stream --> Streaming
Transfer-- Progress via Stream--> Client
Transfer-->RS
Transfer-->ISD
Transfer-->CS
RS-->R
ISD-->IS
R-->Reg
ISD-->CS
ISD-->S

스트리밍

transfer service는 연산의 일부로 데이터 스트림을 보내거나 받을 때, 그리고 콜백(동기 또는 비동기)을 처리할 때 스트리밍을 써요. 스트리밍 프로토콜은 클라이언트 Go 인터페이스에는 보이지 않아야 해요. 함수, 리더, 라이터 같은 객체 타입은 RPC를 탈 때 스트리밍 프로토콜로 투명하게 변환돼요. 그래서 클라이언트·서버 인터페이스는 그대로 유지되고, proto 직렬화·역직렬화만 스트리밍 프로토콜을 알고 스트림 매니저에 접근하면 돼요. 스트림은 클라이언트가 클라이언트 쪽 스트림 매니저로 만들어서, proto RPC를 통해 문자열 스트림 식별자로 전송돼요. 서비스의 서버 구현은 서버 쪽 스트림 매니저에서 이 식별자로 스트림을 찾아요.

진행 상황(Progress)

Progress는 서버가 클라이언트로 보내는 비동기 콜백이에요. 보통 Go 인터페이스에서는 단순 콜백 함수로 표현되고, 클라이언트가 구현하면 서버가 호출해요.

Go 타입으로는 progress가 이 타입들을 써요


type Progress struct {
	Event    string
	Name     string
	Parents  []string
	Progress int64
	Total    int64
}

스트림으로 전송되는 proto 메시지 타입은

	string event = 1;
	string name = 2;
	repeated string parents = 3;
	int64 progress = 4;
	int64 total = 5;
}

Progress는 transfer 옵션으로 전달해 어떤 transfer 연산에든 진행 상황을 받을 수 있어요. 진행 이벤트의 내용은 transfer 연산에 따라 달라질 수 있어요.

바이너리 스트림

transfer 객체는 io.Reader와 io.WriteCloser를 직접 쓸 수도 있어요.

바이트는 두 가지 단순한 proto 메시지 타입으로 스트림 위를 이동해요

	bytes data = 1;
}

message WindowUpdate {
	int32 update = 1;
}

발신자가 Data 메시지를 보내고 수신자가 WindowUpdate 메시지를 보내요. 클라이언트가 io.Reader를 보낼 때는 클라이언트가 발신자, 서버가 수신자예요. 클라이언트가 io.WriteCloser를 보낼 때는 서버가 발신자, 클라이언트가 수신자예요.

바이너리 스트림은 import(io.Reader 전송)와 export(io.WriteCloser 전송)에 쓰여요.

자격 증명(Credentials)

자격 증명은 서버에서 클라이언트로 향하는 동기 콜백으로 처리돼요. 서버가 레지스트리의 인가 요청을 만났을 때 콜백이 일어나요.

transfer 객체에서 자격 증명 헬퍼를 쓰기 위한 Go 인터페이스는 다음과 같아요

	GetCredentials(ctx context.Context, ref, host string) (Credentials, error)
}

type Credentials struct {
	Host     string
	Username string
	Secret   string
	Header   string
}

proto 메시지로 스트림을 통해 전송돼요

message AuthRequest {
	// host is the registry host
	string host = 1;

	// reference is the namespace and repository name requested from the registry
	string reference = 2;

	// wwwauthenticate is the HTTP WWW-Authenticate header values returned from the registry
	repeated string wwwauthenticate = 3;
}

enum AuthType {
	NONE = 0;

	// CREDENTIALS is used to exchange username/password for access token
	// using an oauth or "Docker Registry Token" server
	CREDENTIALS = 1;

	// REFRESH is used to exchange secret for access token using an oauth
	// or "Docker Registry Token" server
	REFRESH = 2;

	// HEADER is used to set the HTTP Authorization header to secret
	// directly for the registry.
	// Value should be `<auth-scheme> <authorization-parameters>`
	HEADER = 3;
}

message AuthResponse {
	AuthType authType = 1;
	string secret = 2;
	string username = 3;
	google.protobuf.Timestamp expire_at = 4;
}

더 알아보기 (Learn more)