Exemplo n.º 1
0
func (s *rpcServer) UploadImage(stream pb.Kurma_UploadImageServer) error {
	s.log.Debug("Received upload request")
	packet, err := stream.Recv()
	if err != nil {
		return err
	}

	pc := s.pendingUploads[packet.StreamId]
	delete(s.pendingUploads, packet.StreamId)

	r := pb.NewByteStreamReader(stream, packet)
	s.log.Debug("Initializing container")
	_, err = s.manager.Create(pc.name, pc.imageManifest, r)
	return err
}
Exemplo n.º 2
0
func (s *rpcServer) UploadImage(inStream pb.Kurma_UploadImageServer) error {
	s.log.Debug("Received upload request")

	// NOTE: Unlike in the local daemon, we don't need to revalidate the image
	// manifest between Create and Upload. The backend validates in the Manager
	// because within the backend, there are multiple inputs to Manager.Create
	// (ie, bootstrapping vs the local API).
	//
	// Over the local API, it will cache the image manifest from the Create call
	// and re-use it on the UploadImage call, not pulling it from the binary
	// image.

	packet, err := inStream.Recv()
	if err != nil {
		return err
	}

	outStream, err := s.client.UploadImage(inStream.Context())
	if err != nil {
		return err
	}

	r := pb.NewByteStreamReader(inStream, packet)
	w := pb.NewByteStreamWriter(outStream, packet.StreamId)

	if _, err := io.Copy(w, r); err != nil {
		return fmt.Errorf("write error: %v", err)
	}
	if _, err := outStream.CloseAndRecv(); err != nil {
		return err
	}
	if err := inStream.SendAndClose(&pb.None{}); err != nil {
		return err
	}
	return nil
}