api.go 23 KB

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