1
0

api.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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 api
  14. import (
  15. "context"
  16. "fmt"
  17. "io"
  18. "slices"
  19. "strings"
  20. "time"
  21. "github.com/compose-spec/compose-go/v2/types"
  22. "github.com/containerd/platforms"
  23. "github.com/docker/cli/opts"
  24. "github.com/docker/docker/api/types/volume"
  25. )
  26. // Compose is the API interface one can use to programmatically use docker/compose in a third-party software
  27. // Use [compose.NewComposeService] to get an actual instance
  28. type Compose interface {
  29. // Build executes the equivalent to a `compose build`
  30. Build(ctx context.Context, project *types.Project, options BuildOptions) error
  31. // Push executes the equivalent to a `compose push`
  32. Push(ctx context.Context, project *types.Project, options PushOptions) error
  33. // Pull executes the equivalent of a `compose pull`
  34. Pull(ctx context.Context, project *types.Project, options PullOptions) error
  35. // Create executes the equivalent to a `compose create`
  36. Create(ctx context.Context, project *types.Project, options CreateOptions) error
  37. // Start executes the equivalent to a `compose start`
  38. Start(ctx context.Context, projectName string, options StartOptions) error
  39. // Restart restarts containers
  40. Restart(ctx context.Context, projectName string, options RestartOptions) error
  41. // Stop executes the equivalent to a `compose stop`
  42. Stop(ctx context.Context, projectName string, options StopOptions) error
  43. // Up executes the equivalent to a `compose up`
  44. Up(ctx context.Context, project *types.Project, options UpOptions) error
  45. // Down executes the equivalent to a `compose down`
  46. Down(ctx context.Context, projectName string, options DownOptions) error
  47. // Logs executes the equivalent to a `compose logs`
  48. Logs(ctx context.Context, projectName string, consumer LogConsumer, options LogOptions) error
  49. // Ps executes the equivalent to a `compose ps`
  50. Ps(ctx context.Context, projectName string, options PsOptions) ([]ContainerSummary, error)
  51. // List executes the equivalent to a `docker stack ls`
  52. List(ctx context.Context, options ListOptions) ([]Stack, error)
  53. // Kill executes the equivalent to a `compose kill`
  54. Kill(ctx context.Context, projectName string, options KillOptions) error
  55. // RunOneOffContainer creates a service oneoff container and starts its dependencies
  56. RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
  57. // Remove executes the equivalent to a `compose rm`
  58. Remove(ctx context.Context, projectName string, options RemoveOptions) error
  59. // Exec executes a command in a running service container
  60. Exec(ctx context.Context, projectName string, options RunOptions) (int, error)
  61. // Attach STDIN,STDOUT,STDERR to a running service container
  62. Attach(ctx context.Context, projectName string, options AttachOptions) error
  63. // Copy copies a file/folder between a service container and the local filesystem
  64. Copy(ctx context.Context, projectName string, options CopyOptions) error
  65. // Pause executes the equivalent to a `compose pause`
  66. Pause(ctx context.Context, projectName string, options PauseOptions) error
  67. // UnPause executes the equivalent to a `compose unpause`
  68. UnPause(ctx context.Context, projectName string, options PauseOptions) error
  69. // Top executes the equivalent to a `compose top`
  70. Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
  71. // Events executes the equivalent to a `compose events`
  72. Events(ctx context.Context, projectName string, options EventsOptions) error
  73. // Port executes the equivalent to a `compose port`
  74. Port(ctx context.Context, projectName string, service string, port uint16, options PortOptions) (string, int, error)
  75. // Publish executes the equivalent to a `compose publish`
  76. Publish(ctx context.Context, project *types.Project, repository string, options PublishOptions) error
  77. // Images executes the equivalent of a `compose images`
  78. Images(ctx context.Context, projectName string, options ImagesOptions) (map[string]ImageSummary, error)
  79. // MaxConcurrency defines upper limit for concurrent operations against engine API
  80. MaxConcurrency(parallel int)
  81. // DryRunMode defines if dry run applies to the command
  82. DryRunMode(ctx context.Context, dryRun bool) (context.Context, error)
  83. // Watch services' development context and sync/notify/rebuild/restart on changes
  84. Watch(ctx context.Context, project *types.Project, options WatchOptions) error
  85. // Viz generates a graphviz graph of the project services
  86. Viz(ctx context.Context, project *types.Project, options VizOptions) (string, error)
  87. // Wait blocks until at least one of the services' container exits
  88. Wait(ctx context.Context, projectName string, options WaitOptions) (int64, error)
  89. // Scale manages numbers of container instances running per service
  90. Scale(ctx context.Context, project *types.Project, options ScaleOptions) error
  91. // Export a service container's filesystem as a tar archive
  92. Export(ctx context.Context, projectName string, options ExportOptions) error
  93. // Create a new image from a service container's changes
  94. Commit(ctx context.Context, projectName string, options CommitOptions) error
  95. // Generate generates a Compose Project from existing containers
  96. Generate(ctx context.Context, options GenerateOptions) (*types.Project, error)
  97. // Volumes executes the equivalent to a `docker volume ls`
  98. Volumes(ctx context.Context, project string, options VolumesOptions) ([]VolumesSummary, error)
  99. }
  100. type VolumesOptions struct {
  101. Services []string
  102. }
  103. type VolumesSummary = *volume.Volume
  104. type ScaleOptions struct {
  105. Services []string
  106. }
  107. type WaitOptions struct {
  108. // Services passed in the command line to be waited
  109. Services []string
  110. // Executes a down when a container exits
  111. DownProjectOnContainerExit bool
  112. }
  113. type VizOptions struct {
  114. // IncludeNetworks if true, network names a container is attached to should appear in the graph node
  115. IncludeNetworks bool
  116. // IncludePorts if true, ports a container exposes should appear in the graph node
  117. IncludePorts bool
  118. // IncludeImageName if true, name of the image used to create a container should appear in the graph node
  119. IncludeImageName bool
  120. // Indentation string to be used to indent graphviz code, e.g. "\t", " "
  121. Indentation string
  122. }
  123. // WatchLogger is a reserved name to log watch events
  124. const WatchLogger = "#watch"
  125. // WatchOptions group options of the Watch API
  126. type WatchOptions struct {
  127. Build *BuildOptions
  128. LogTo LogConsumer
  129. Prune bool
  130. Services []string
  131. }
  132. // BuildOptions group options of the Build API
  133. type BuildOptions struct {
  134. // Pull always attempt to pull a newer version of the image
  135. Pull bool
  136. // Push pushes service images
  137. Push bool
  138. // Progress set type of progress output ("auto", "plain", "tty")
  139. Progress string
  140. // Args set build-time args
  141. Args types.MappingWithEquals
  142. // NoCache disables cache use
  143. NoCache bool
  144. // Quiet make the build process not output to the console
  145. Quiet bool
  146. // Services passed in the command line to be built
  147. Services []string
  148. // Deps also build selected services dependencies
  149. Deps bool
  150. // Ssh authentications passed in the command line
  151. SSHs []types.SSHKey
  152. // Memory limit for the build container
  153. Memory int64
  154. // Builder name passed in the command line
  155. Builder string
  156. // Print don't actually run builder but print equivalent build config
  157. Print bool
  158. // Check let builder validate build configuration
  159. Check bool
  160. // Attestations allows to enable attestations generation
  161. Attestations bool
  162. // Provenance generate a provenance attestation
  163. Provenance string
  164. // SBOM generate a SBOM attestation
  165. SBOM string
  166. // Out is the stream to write build progress
  167. Out io.Writer
  168. }
  169. // Apply mutates project according to build options
  170. func (o BuildOptions) Apply(project *types.Project) error {
  171. platform := project.Environment["DOCKER_DEFAULT_PLATFORM"]
  172. for name, service := range project.Services {
  173. if service.Provider == nil && service.Image == "" && service.Build == nil {
  174. return fmt.Errorf("invalid service %q. Must specify either image or build", name)
  175. }
  176. if service.Build == nil {
  177. continue
  178. }
  179. if platform != "" {
  180. if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, platform) {
  181. return fmt.Errorf("service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s", name, platform)
  182. }
  183. service.Platform = platform
  184. }
  185. if service.Platform != "" {
  186. if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, service.Platform) {
  187. return fmt.Errorf("service %q build configuration does not support platform: %s", name, service.Platform)
  188. }
  189. }
  190. service.Build.Pull = service.Build.Pull || o.Pull
  191. service.Build.NoCache = service.Build.NoCache || o.NoCache
  192. project.Services[name] = service
  193. }
  194. return nil
  195. }
  196. // CreateOptions group options of the Create API
  197. type CreateOptions struct {
  198. Build *BuildOptions
  199. // Services defines the services user interacts with
  200. Services []string
  201. // Remove legacy containers for services that are not defined in the project
  202. RemoveOrphans bool
  203. // Ignore legacy containers for services that are not defined in the project
  204. IgnoreOrphans bool
  205. // Recreate define the strategy to apply on existing containers
  206. Recreate string
  207. // RecreateDependencies define the strategy to apply on dependencies services
  208. RecreateDependencies string
  209. // Inherit reuse anonymous volumes from previous container
  210. Inherit bool
  211. // Timeout set delay to wait for container to gracefully stop before sending SIGKILL
  212. Timeout *time.Duration
  213. // QuietPull makes the pulling process quiet
  214. QuietPull bool
  215. // AssumeYes assume "yes" as answer to all prompts and run non-interactively
  216. AssumeYes bool
  217. }
  218. // StartOptions group options of the Start API
  219. type StartOptions struct {
  220. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  221. Project *types.Project
  222. // Attach to container and forward logs if not nil
  223. Attach LogConsumer
  224. // AttachTo set the services to attach to
  225. AttachTo []string
  226. // OnExit defines behavior when a container stops
  227. OnExit Cascade
  228. // ExitCodeFrom return exit code from specified service
  229. ExitCodeFrom string
  230. // Wait won't return until containers reached the running|healthy state
  231. Wait bool
  232. WaitTimeout time.Duration
  233. // Services passed in the command line to be started
  234. Services []string
  235. Watch bool
  236. NavigationMenu bool
  237. }
  238. type Cascade int
  239. const (
  240. CascadeIgnore Cascade = iota
  241. CascadeStop Cascade = iota
  242. CascadeFail Cascade = iota
  243. )
  244. // RestartOptions group options of the Restart API
  245. type RestartOptions struct {
  246. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  247. Project *types.Project
  248. // Timeout override container restart timeout
  249. Timeout *time.Duration
  250. // Services passed in the command line to be restarted
  251. Services []string
  252. // NoDeps ignores services dependencies
  253. NoDeps bool
  254. }
  255. // StopOptions group options of the Stop API
  256. type StopOptions struct {
  257. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  258. Project *types.Project
  259. // Timeout override container stop timeout
  260. Timeout *time.Duration
  261. // Services passed in the command line to be stopped
  262. Services []string
  263. }
  264. // UpOptions group options of the Up API
  265. type UpOptions struct {
  266. Create CreateOptions
  267. Start StartOptions
  268. }
  269. // DownOptions group options of the Down API
  270. type DownOptions struct {
  271. // RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
  272. RemoveOrphans bool
  273. // Project is the compose project used to define this app. Might be nil if user ran `down` just with project name
  274. Project *types.Project
  275. // Timeout override container stop timeout
  276. Timeout *time.Duration
  277. // Images remove image used by services. 'all': Remove all images. 'local': Remove only images that don't have a tag
  278. Images string
  279. // Volumes remove volumes, both declared in the `volumes` section and anonymous ones
  280. Volumes bool
  281. // Services passed in the command line to be stopped
  282. Services []string
  283. }
  284. // ConfigOptions group options of the Config API
  285. type ConfigOptions struct {
  286. // Format define the output format used to dump converted application model (json|yaml)
  287. Format string
  288. // Output defines the path to save the application model
  289. Output string
  290. // Resolve image reference to digests
  291. ResolveImageDigests bool
  292. }
  293. // PushOptions group options of the Push API
  294. type PushOptions struct {
  295. Quiet bool
  296. IgnoreFailures bool
  297. ImageMandatory bool
  298. }
  299. // PullOptions group options of the Pull API
  300. type PullOptions struct {
  301. Quiet bool
  302. IgnoreFailures bool
  303. IgnoreBuildable bool
  304. }
  305. // ImagesOptions group options of the Images API
  306. type ImagesOptions struct {
  307. Services []string
  308. }
  309. // KillOptions group options of the Kill API
  310. type KillOptions struct {
  311. // RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
  312. RemoveOrphans bool
  313. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  314. Project *types.Project
  315. // Services passed in the command line to be killed
  316. Services []string
  317. // Signal to send to containers
  318. Signal string
  319. // All can be set to true to try to kill all found containers, independently of their state
  320. All bool
  321. }
  322. // RemoveOptions group options of the Remove API
  323. type RemoveOptions struct {
  324. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  325. Project *types.Project
  326. // Stop option passed in the command line
  327. Stop bool
  328. // Volumes remove anonymous volumes
  329. Volumes bool
  330. // Force don't ask to confirm removal
  331. Force bool
  332. // Services passed in the command line to be removed
  333. Services []string
  334. }
  335. // RunOptions group options of the Run API
  336. type RunOptions struct {
  337. CreateOptions
  338. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  339. Project *types.Project
  340. Name string
  341. Service string
  342. Command []string
  343. Entrypoint []string
  344. Detach bool
  345. AutoRemove bool
  346. Tty bool
  347. Interactive bool
  348. WorkingDir string
  349. User string
  350. Environment []string
  351. CapAdd []string
  352. CapDrop []string
  353. Labels types.Labels
  354. Privileged bool
  355. UseNetworkAliases bool
  356. NoDeps bool
  357. // used by exec
  358. Index int
  359. }
  360. // AttachOptions group options of the Attach API
  361. type AttachOptions struct {
  362. Project *types.Project
  363. Service string
  364. Index int
  365. DetachKeys string
  366. NoStdin bool
  367. Proxy bool
  368. }
  369. // EventsOptions group options of the Events API
  370. type EventsOptions struct {
  371. Services []string
  372. Consumer func(event Event) error
  373. Since string
  374. Until string
  375. }
  376. // Event is a container runtime event served by Events API
  377. type Event struct {
  378. Timestamp time.Time
  379. Service string
  380. Container string
  381. Status string
  382. Attributes map[string]string
  383. }
  384. // PortOptions group options of the Port API
  385. type PortOptions struct {
  386. Protocol string
  387. Index int
  388. }
  389. // OCIVersion controls manifest generation to ensure compatibility
  390. // with different registries.
  391. //
  392. // Currently, this is not exposed as an option to the user – Compose uses
  393. // OCI 1.0 mode automatically for ECR registries based on domain and OCI 1.1
  394. // for all other registries.
  395. //
  396. // There are likely other popular registries that do not support the OCI 1.1
  397. // format, so it might make sense to expose this as a CLI flag or see if
  398. // there's a way to generically probe the registry for support level.
  399. type OCIVersion string
  400. const (
  401. OCIVersion1_0 OCIVersion = "1.0"
  402. OCIVersion1_1 OCIVersion = "1.1"
  403. )
  404. // PublishOptions group options of the Publish API
  405. type PublishOptions struct {
  406. ResolveImageDigests bool
  407. Application bool
  408. WithEnvironment bool
  409. AssumeYes bool
  410. OCIVersion OCIVersion
  411. }
  412. func (e Event) String() string {
  413. t := e.Timestamp.Format("2006-01-02 15:04:05.000000")
  414. var attr []string
  415. for k, v := range e.Attributes {
  416. attr = append(attr, fmt.Sprintf("%s=%s", k, v))
  417. }
  418. return fmt.Sprintf("%s container %s %s (%s)\n", t, e.Status, e.Container, strings.Join(attr, ", "))
  419. }
  420. // ListOptions group options of the ls API
  421. type ListOptions struct {
  422. All bool
  423. }
  424. // PsOptions group options of the Ps API
  425. type PsOptions struct {
  426. Project *types.Project
  427. All bool
  428. Services []string
  429. }
  430. // CopyOptions group options of the cp API
  431. type CopyOptions struct {
  432. Source string
  433. Destination string
  434. All bool
  435. Index int
  436. FollowLink bool
  437. CopyUIDGID bool
  438. }
  439. // PortPublisher hold status about published port
  440. type PortPublisher struct {
  441. URL string
  442. TargetPort int
  443. PublishedPort int
  444. Protocol string
  445. }
  446. // ContainerSummary hold high-level description of a container
  447. type ContainerSummary struct {
  448. ID string
  449. Name string
  450. Names []string
  451. Image string
  452. Command string
  453. Project string
  454. Service string
  455. Created int64
  456. State string
  457. Status string
  458. Health string
  459. ExitCode int
  460. Publishers PortPublishers
  461. Labels map[string]string
  462. SizeRw int64 `json:",omitempty"`
  463. SizeRootFs int64 `json:",omitempty"`
  464. Mounts []string
  465. Networks []string
  466. LocalVolumes int
  467. }
  468. // PortPublishers is a slice of PortPublisher
  469. type PortPublishers []PortPublisher
  470. // Len implements sort.Interface
  471. func (p PortPublishers) Len() int {
  472. return len(p)
  473. }
  474. // Less implements sort.Interface
  475. func (p PortPublishers) Less(i, j int) bool {
  476. left := p[i]
  477. right := p[j]
  478. if left.URL != right.URL {
  479. return left.URL < right.URL
  480. }
  481. if left.TargetPort != right.TargetPort {
  482. return left.TargetPort < right.TargetPort
  483. }
  484. if left.PublishedPort != right.PublishedPort {
  485. return left.PublishedPort < right.PublishedPort
  486. }
  487. return left.Protocol < right.Protocol
  488. }
  489. // Swap implements sort.Interface
  490. func (p PortPublishers) Swap(i, j int) {
  491. p[i], p[j] = p[j], p[i]
  492. }
  493. // ContainerProcSummary holds container processes top data
  494. type ContainerProcSummary struct {
  495. ID string
  496. Name string
  497. Processes [][]string
  498. Titles []string
  499. Service string
  500. Replica string
  501. }
  502. // ImageSummary holds container image description
  503. type ImageSummary struct {
  504. ID string
  505. Repository string
  506. Tag string
  507. Platform platforms.Platform
  508. Size int64
  509. Created time.Time
  510. LastTagTime time.Time
  511. }
  512. // ServiceStatus hold status about a service
  513. type ServiceStatus struct {
  514. ID string
  515. Name string
  516. Replicas int
  517. Desired int
  518. Ports []string
  519. Publishers []PortPublisher
  520. }
  521. // LogOptions defines optional parameters for the `Log` API
  522. type LogOptions struct {
  523. Project *types.Project
  524. Index int
  525. Services []string
  526. Tail string
  527. Since string
  528. Until string
  529. Follow bool
  530. Timestamps bool
  531. }
  532. // PauseOptions group options of the Pause API
  533. type PauseOptions struct {
  534. // Services passed in the command line to be started
  535. Services []string
  536. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  537. Project *types.Project
  538. }
  539. // ExportOptions group options of the Export API
  540. type ExportOptions struct {
  541. Service string
  542. Index int
  543. Output string
  544. }
  545. // CommitOptions group options of the Commit API
  546. type CommitOptions struct {
  547. Service string
  548. Reference string
  549. Pause bool
  550. Comment string
  551. Author string
  552. Changes opts.ListOpts
  553. Index int
  554. }
  555. type GenerateOptions struct {
  556. // ProjectName to set in the Compose file
  557. ProjectName string
  558. // Containers passed in the command line to be used as reference for service definition
  559. Containers []string
  560. }
  561. const (
  562. // STARTING indicates that stack is being deployed
  563. STARTING string = "Starting"
  564. // RUNNING indicates that stack is deployed and services are running
  565. RUNNING string = "Running"
  566. // UPDATING indicates that some stack resources are being recreated
  567. UPDATING string = "Updating"
  568. // REMOVING indicates that stack is being deleted
  569. REMOVING string = "Removing"
  570. // UNKNOWN indicates unknown stack state
  571. UNKNOWN string = "Unknown"
  572. // FAILED indicates that stack deployment failed
  573. FAILED string = "Failed"
  574. )
  575. const (
  576. // RecreateDiverged to recreate services which configuration diverges from compose model
  577. RecreateDiverged = "diverged"
  578. // RecreateForce to force service container being recreated
  579. RecreateForce = "force"
  580. // RecreateNever to never recreate existing service containers
  581. RecreateNever = "never"
  582. )
  583. // Stack holds the name and state of a compose application/stack
  584. type Stack struct {
  585. ID string
  586. Name string
  587. Status string
  588. ConfigFiles string
  589. Reason string
  590. }
  591. // LogConsumer is a callback to process log messages from services
  592. type LogConsumer interface {
  593. Log(containerName, message string)
  594. Err(containerName, message string)
  595. Status(container, msg string)
  596. }
  597. // ContainerEventListener is a callback to process ContainerEvent from services
  598. type ContainerEventListener func(event ContainerEvent)
  599. // ContainerEvent notify an event has been collected on source container implementing Service
  600. type ContainerEvent struct {
  601. Type int
  602. Time int64
  603. Container *ContainerSummary
  604. // Source is the name of the container _without the project prefix_.
  605. //
  606. // This is only suitable for display purposes within Compose, as it's
  607. // not guaranteed to be unique across services.
  608. Source string
  609. ID string
  610. Service string
  611. Line string
  612. // ExitCode is only set on ContainerEventExited events
  613. ExitCode int
  614. Restarting bool
  615. }
  616. const (
  617. // ContainerEventLog is a ContainerEvent of type log on stdout. Line is set
  618. ContainerEventLog = iota
  619. // ContainerEventErr is a ContainerEvent of type log on stderr. Line is set
  620. ContainerEventErr
  621. // ContainerEventStarted let consumer know a container has been started
  622. ContainerEventStarted
  623. // ContainerEventRestarted let consumer know a container has been restarted
  624. ContainerEventRestarted
  625. // ContainerEventStopped is a ContainerEvent of type stopped.
  626. ContainerEventStopped
  627. // ContainerEventCreated let consumer know a new container has been created
  628. ContainerEventCreated
  629. // ContainerEventRecreated let consumer know container stopped but his being replaced
  630. ContainerEventRecreated
  631. // ContainerEventExited is a ContainerEvent of type exit. ExitCode is set
  632. ContainerEventExited
  633. // UserCancel user cancelled compose up, we are stopping containers
  634. HookEventLog
  635. )
  636. // Separator is used for naming components
  637. var Separator = "-"
  638. // GetImageNameOrDefault computes the default image name for a service, used to tag built images
  639. func GetImageNameOrDefault(service types.ServiceConfig, projectName string) string {
  640. imageName := service.Image
  641. if imageName == "" {
  642. imageName = projectName + Separator + service.Name
  643. }
  644. return imageName
  645. }