conf.go 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package glue
  2. import (
  3. "encoding/json"
  4. "os"
  5. "path"
  6. "github.com/docker/engine-api/types/container"
  7. "github.com/opencontainers/specs/specs-go"
  8. )
  9. type DockerPluginState struct {
  10. ContainerID string
  11. State specs.State
  12. Spec specs.Spec
  13. HostConfig container.HostConfig
  14. Config container.Config
  15. }
  16. func ReadState() (*DockerPluginState, error) {
  17. pluginState := DockerPluginState{}
  18. config := struct {
  19. ID string
  20. Config container.Config
  21. }{}
  22. if err := json.NewDecoder(os.Stdin).Decode(&pluginState.State); err != nil {
  23. return nil, err
  24. }
  25. if err := readJSONFile(os.Getenv("DOCKER_HOST_CONFIG"), &pluginState.HostConfig); err != nil {
  26. return nil, err
  27. }
  28. if err := readJSONFile(os.Getenv("DOCKER_CONFIG"), &config); err != nil {
  29. return nil, err
  30. }
  31. pluginState.Config = config.Config
  32. pluginState.ContainerID = config.ID
  33. return &pluginState, readJSONFile(path.Join(pluginState.State.BundlePath, "config.json"), &pluginState.Spec)
  34. }