Пример #1
0
func GetClient(c *C) client.APIClient {
	client, err := lclient.Create(lclient.Options{})

	c.Assert(err, IsNil)

	return client
}
Пример #2
0
// NewDefaultClientFactory creates and returns the default client factory that uses
// github.com/docker/engine-api client.
func NewDefaultClientFactory(opts composeclient.Options) (ClientFactory, error) {
	client, err := composeclient.Create(opts)
	if err != nil {
		return nil, err
	}

	return &defaultClientFactory{
		client: client,
	}, nil
}
Пример #3
0
func NewClientFactory(opts composeClient.Options) (project.ClientFactory, error) {
	userOpts := opts
	systemOpts := opts

	userOpts.Host = config.DOCKER_HOST
	systemOpts.Host = config.DOCKER_SYSTEM_HOST

	userClient, err := composeClient.Create(userOpts)
	if err != nil {
		return nil, err
	}

	systemClient, err := composeClient.Create(systemOpts)
	if err != nil {
		return nil, err
	}

	return &ClientFactory{
		userClient:   userClient,
		systemClient: systemClient,
	}, nil
}
Пример #4
0
func getPid(service string, project *project.Project) (int, error) {
	s, err := project.CreateService(service)
	if err != nil {
		return 0, err
	}

	containers, err := s.Containers(context.Background())
	if err != nil {
		return 0, err
	}

	if len(containers) == 0 {
		return 0, nil
	}

	client, err := composeClient.Create(composeClient.Options{
		Host: config.DOCKER_SYSTEM_HOST,
	})
	if err != nil {
		return 0, err
	}

	id, err := containers[0].ID()
	if err != nil {
		return 0, err
	}

	info, err := client.ContainerInspect(context.Background(), id)
	if err != nil || info.ID == "" {
		return 0, err
	}

	if info.State.Running {
		return info.State.Pid, nil
	}

	return 0, nil
}