compose.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package proxy
  14. import (
  15. "context"
  16. "github.com/compose-spec/compose-go/cli"
  17. "github.com/docker/compose-cli/api/containers"
  18. composev1 "github.com/docker/compose-cli/protos/compose/v1"
  19. containersv1 "github.com/docker/compose-cli/protos/containers/v1"
  20. "github.com/docker/compose-cli/server/proxy/streams"
  21. )
  22. func (p *proxy) Up(ctx context.Context, request *composev1.ComposeUpRequest) (*composev1.ComposeUpResponse, error) {
  23. options, err := cli.NewProjectOptions(request.Files,
  24. cli.WithOsEnv,
  25. cli.WithWorkingDirectory(request.WorkDir),
  26. cli.WithName(request.ProjectName))
  27. if err != nil {
  28. return nil, err
  29. }
  30. project, err := cli.ProjectFromOptions(options)
  31. if err != nil {
  32. return nil, err
  33. }
  34. return &composev1.ComposeUpResponse{}, Client(ctx).ComposeService().Up(ctx, project, true)
  35. }
  36. func (p *proxy) Down(ctx context.Context, request *composev1.ComposeDownRequest) (*composev1.ComposeDownResponse, error) {
  37. err := Client(ctx).ComposeService().Down(ctx, "TODO")
  38. if err != nil {
  39. return nil, err
  40. }
  41. response := &composev1.ComposeDownResponse{}
  42. return response, err
  43. }
  44. func (p *proxy) ComposeLogs(request *containersv1.LogsRequest, stream containersv1.Containers_LogsServer) error {
  45. return Client(stream.Context()).ContainerService().Logs(stream.Context(), request.GetContainerId(), containers.LogsRequest{
  46. Follow: request.Follow,
  47. Writer: &streams.Log{
  48. Stream: stream,
  49. },
  50. })
  51. }