api.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. // Attestations allows to enable attestations generation
  159. Attestations bool
  160. // Provenance generate a provenance attestation
  161. Provenance string
  162. // SBOM generate a SBOM attestation
  163. SBOM string
  164. }
  165. // Apply mutates project according to build options
  166. func (o BuildOptions) Apply(project *types.Project) error {
  167. platform := project.Environment["DOCKER_DEFAULT_PLATFORM"]
  168. for name, service := range project.Services {
  169. if service.Provider == nil && service.Image == "" && service.Build == nil {
  170. return fmt.Errorf("invalid service %q. Must specify either image or build", name)
  171. }
  172. if service.Build == nil {
  173. continue
  174. }
  175. if platform != "" {
  176. if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, platform) {
  177. return fmt.Errorf("service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s", name, platform)
  178. }
  179. service.Platform = platform
  180. }
  181. if service.Platform != "" {
  182. if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, service.Platform) {
  183. return fmt.Errorf("service %q build configuration does not support platform: %s", name, service.Platform)
  184. }
  185. }
  186. service.Build.Pull = service.Build.Pull || o.Pull
  187. service.Build.NoCache = service.Build.NoCache || o.NoCache
  188. project.Services[name] = service
  189. }
  190. return nil
  191. }
  192. // CreateOptions group options of the Create API
  193. type CreateOptions struct {
  194. Build *BuildOptions
  195. // Services defines the services user interacts with
  196. Services []string
  197. // Remove legacy containers for services that are not defined in the project
  198. RemoveOrphans bool
  199. // Ignore legacy containers for services that are not defined in the project
  200. IgnoreOrphans bool
  201. // Recreate define the strategy to apply on existing containers
  202. Recreate string
  203. // RecreateDependencies define the strategy to apply on dependencies services
  204. RecreateDependencies string
  205. // Inherit reuse anonymous volumes from previous container
  206. Inherit bool
  207. // Timeout set delay to wait for container to gracefully stop before sending SIGKILL
  208. Timeout *time.Duration
  209. // QuietPull makes the pulling process quiet
  210. QuietPull bool
  211. // AssumeYes assume "yes" as answer to all prompts and run non-interactively
  212. AssumeYes bool
  213. }
  214. // StartOptions group options of the Start API
  215. type StartOptions struct {
  216. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  217. Project *types.Project
  218. // Attach to container and forward logs if not nil
  219. Attach LogConsumer
  220. // AttachTo set the services to attach to
  221. AttachTo []string
  222. // OnExit defines behavior when a container stops
  223. OnExit Cascade
  224. // ExitCodeFrom return exit code from specified service
  225. ExitCodeFrom string
  226. // Wait won't return until containers reached the running|healthy state
  227. Wait bool
  228. WaitTimeout time.Duration
  229. // Services passed in the command line to be started
  230. Services []string
  231. Watch bool
  232. NavigationMenu bool
  233. }
  234. type Cascade int
  235. const (
  236. CascadeIgnore Cascade = iota
  237. CascadeStop Cascade = iota
  238. CascadeFail Cascade = iota
  239. )
  240. // RestartOptions group options of the Restart API
  241. type RestartOptions struct {
  242. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  243. Project *types.Project
  244. // Timeout override container restart timeout
  245. Timeout *time.Duration
  246. // Services passed in the command line to be restarted
  247. Services []string
  248. // NoDeps ignores services dependencies
  249. NoDeps bool
  250. }
  251. // StopOptions group options of the Stop API
  252. type StopOptions struct {
  253. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  254. Project *types.Project
  255. // Timeout override container stop timeout
  256. Timeout *time.Duration
  257. // Services passed in the command line to be stopped
  258. Services []string
  259. }
  260. // UpOptions group options of the Up API
  261. type UpOptions struct {
  262. Create CreateOptions
  263. Start StartOptions
  264. }
  265. // DownOptions group options of the Down API
  266. type DownOptions struct {
  267. // RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
  268. RemoveOrphans bool
  269. // Project is the compose project used to define this app. Might be nil if user ran `down` just with project name
  270. Project *types.Project
  271. // Timeout override container stop timeout
  272. Timeout *time.Duration
  273. // Images remove image used by services. 'all': Remove all images. 'local': Remove only images that don't have a tag
  274. Images string
  275. // Volumes remove volumes, both declared in the `volumes` section and anonymous ones
  276. Volumes bool
  277. // Services passed in the command line to be stopped
  278. Services []string
  279. }
  280. // ConfigOptions group options of the Config API
  281. type ConfigOptions struct {
  282. // Format define the output format used to dump converted application model (json|yaml)
  283. Format string
  284. // Output defines the path to save the application model
  285. Output string
  286. // Resolve image reference to digests
  287. ResolveImageDigests bool
  288. }
  289. // PushOptions group options of the Push API
  290. type PushOptions struct {
  291. Quiet bool
  292. IgnoreFailures bool
  293. ImageMandatory bool
  294. }
  295. // PullOptions group options of the Pull API
  296. type PullOptions struct {
  297. Quiet bool
  298. IgnoreFailures bool
  299. IgnoreBuildable bool
  300. }
  301. // ImagesOptions group options of the Images API
  302. type ImagesOptions struct {
  303. Services []string
  304. }
  305. // KillOptions group options of the Kill API
  306. type KillOptions struct {
  307. // RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
  308. RemoveOrphans bool
  309. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  310. Project *types.Project
  311. // Services passed in the command line to be killed
  312. Services []string
  313. // Signal to send to containers
  314. Signal string
  315. // All can be set to true to try to kill all found containers, independently of their state
  316. All bool
  317. }
  318. // RemoveOptions group options of the Remove API
  319. type RemoveOptions struct {
  320. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  321. Project *types.Project
  322. // Stop option passed in the command line
  323. Stop bool
  324. // Volumes remove anonymous volumes
  325. Volumes bool
  326. // Force don't ask to confirm removal
  327. Force bool
  328. // Services passed in the command line to be removed
  329. Services []string
  330. }
  331. // RunOptions group options of the Run API
  332. type RunOptions struct {
  333. CreateOptions
  334. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  335. Project *types.Project
  336. Name string
  337. Service string
  338. Command []string
  339. Entrypoint []string
  340. Detach bool
  341. AutoRemove bool
  342. Tty bool
  343. Interactive bool
  344. WorkingDir string
  345. User string
  346. Environment []string
  347. CapAdd []string
  348. CapDrop []string
  349. Labels types.Labels
  350. Privileged bool
  351. UseNetworkAliases bool
  352. NoDeps bool
  353. // used by exec
  354. Index int
  355. }
  356. // AttachOptions group options of the Attach API
  357. type AttachOptions struct {
  358. Project *types.Project
  359. Service string
  360. Index int
  361. DetachKeys string
  362. NoStdin bool
  363. Proxy bool
  364. }
  365. // EventsOptions group options of the Events API
  366. type EventsOptions struct {
  367. Services []string
  368. Consumer func(event Event) error
  369. Since string
  370. Until string
  371. }
  372. // Event is a container runtime event served by Events API
  373. type Event struct {
  374. Timestamp time.Time
  375. Service string
  376. Container string
  377. Status string
  378. Attributes map[string]string
  379. }
  380. // PortOptions group options of the Port API
  381. type PortOptions struct {
  382. Protocol string
  383. Index int
  384. }
  385. // OCIVersion controls manifest generation to ensure compatibility
  386. // with different registries.
  387. //
  388. // Currently, this is not exposed as an option to the user – Compose uses
  389. // OCI 1.0 mode automatically for ECR registries based on domain and OCI 1.1
  390. // for all other registries.
  391. //
  392. // There are likely other popular registries that do not support the OCI 1.1
  393. // format, so it might make sense to expose this as a CLI flag or see if
  394. // there's a way to generically probe the registry for support level.
  395. type OCIVersion string
  396. const (
  397. OCIVersion1_0 OCIVersion = "1.0"
  398. OCIVersion1_1 OCIVersion = "1.1"
  399. )
  400. // PublishOptions group options of the Publish API
  401. type PublishOptions struct {
  402. ResolveImageDigests bool
  403. WithEnvironment bool
  404. AssumeYes bool
  405. OCIVersion OCIVersion
  406. }
  407. func (e Event) String() string {
  408. t := e.Timestamp.Format("2006-01-02 15:04:05.000000")
  409. var attr []string
  410. for k, v := range e.Attributes {
  411. attr = append(attr, fmt.Sprintf("%s=%s", k, v))
  412. }
  413. return fmt.Sprintf("%s container %s %s (%s)\n", t, e.Status, e.Container, strings.Join(attr, ", "))
  414. }
  415. // ListOptions group options of the ls API
  416. type ListOptions struct {
  417. All bool
  418. }
  419. // PsOptions group options of the Ps API
  420. type PsOptions struct {
  421. Project *types.Project
  422. All bool
  423. Services []string
  424. }
  425. // CopyOptions group options of the cp API
  426. type CopyOptions struct {
  427. Source string
  428. Destination string
  429. All bool
  430. Index int
  431. FollowLink bool
  432. CopyUIDGID bool
  433. }
  434. // PortPublisher hold status about published port
  435. type PortPublisher struct {
  436. URL string
  437. TargetPort int
  438. PublishedPort int
  439. Protocol string
  440. }
  441. // ContainerSummary hold high-level description of a container
  442. type ContainerSummary struct {
  443. ID string
  444. Name string
  445. Names []string
  446. Image string
  447. Command string
  448. Project string
  449. Service string
  450. Created int64
  451. State string
  452. Status string
  453. Health string
  454. ExitCode int
  455. Publishers PortPublishers
  456. Labels map[string]string
  457. SizeRw int64 `json:",omitempty"`
  458. SizeRootFs int64 `json:",omitempty"`
  459. Mounts []string
  460. Networks []string
  461. LocalVolumes int
  462. }
  463. // PortPublishers is a slice of PortPublisher
  464. type PortPublishers []PortPublisher
  465. // Len implements sort.Interface
  466. func (p PortPublishers) Len() int {
  467. return len(p)
  468. }
  469. // Less implements sort.Interface
  470. func (p PortPublishers) Less(i, j int) bool {
  471. left := p[i]
  472. right := p[j]
  473. if left.URL != right.URL {
  474. return left.URL < right.URL
  475. }
  476. if left.TargetPort != right.TargetPort {
  477. return left.TargetPort < right.TargetPort
  478. }
  479. if left.PublishedPort != right.PublishedPort {
  480. return left.PublishedPort < right.PublishedPort
  481. }
  482. return left.Protocol < right.Protocol
  483. }
  484. // Swap implements sort.Interface
  485. func (p PortPublishers) Swap(i, j int) {
  486. p[i], p[j] = p[j], p[i]
  487. }
  488. // ContainerProcSummary holds container processes top data
  489. type ContainerProcSummary struct {
  490. ID string
  491. Name string
  492. Processes [][]string
  493. Titles []string
  494. Service string
  495. Replica string
  496. }
  497. // ImageSummary holds container image description
  498. type ImageSummary struct {
  499. ID string
  500. Repository string
  501. Tag string
  502. Platform platforms.Platform
  503. Size int64
  504. LastTagTime time.Time
  505. }
  506. // ServiceStatus hold status about a service
  507. type ServiceStatus struct {
  508. ID string
  509. Name string
  510. Replicas int
  511. Desired int
  512. Ports []string
  513. Publishers []PortPublisher
  514. }
  515. // LogOptions defines optional parameters for the `Log` API
  516. type LogOptions struct {
  517. Project *types.Project
  518. Index int
  519. Services []string
  520. Tail string
  521. Since string
  522. Until string
  523. Follow bool
  524. Timestamps bool
  525. }
  526. // PauseOptions group options of the Pause API
  527. type PauseOptions struct {
  528. // Services passed in the command line to be started
  529. Services []string
  530. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  531. Project *types.Project
  532. }
  533. // ExportOptions group options of the Export API
  534. type ExportOptions struct {
  535. Service string
  536. Index int
  537. Output string
  538. }
  539. // CommitOptions group options of the Commit API
  540. type CommitOptions struct {
  541. Service string
  542. Reference string
  543. Pause bool
  544. Comment string
  545. Author string
  546. Changes opts.ListOpts
  547. Index int
  548. }
  549. type GenerateOptions struct {
  550. // ProjectName to set in the Compose file
  551. ProjectName string
  552. // Containers passed in the command line to be used as reference for service definition
  553. Containers []string
  554. }
  555. const (
  556. // STARTING indicates that stack is being deployed
  557. STARTING string = "Starting"
  558. // RUNNING indicates that stack is deployed and services are running
  559. RUNNING string = "Running"
  560. // UPDATING indicates that some stack resources are being recreated
  561. UPDATING string = "Updating"
  562. // REMOVING indicates that stack is being deleted
  563. REMOVING string = "Removing"
  564. // UNKNOWN indicates unknown stack state
  565. UNKNOWN string = "Unknown"
  566. // FAILED indicates that stack deployment failed
  567. FAILED string = "Failed"
  568. )
  569. const (
  570. // RecreateDiverged to recreate services which configuration diverges from compose model
  571. RecreateDiverged = "diverged"
  572. // RecreateForce to force service container being recreated
  573. RecreateForce = "force"
  574. // RecreateNever to never recreate existing service containers
  575. RecreateNever = "never"
  576. )
  577. // Stack holds the name and state of a compose application/stack
  578. type Stack struct {
  579. ID string
  580. Name string
  581. Status string
  582. ConfigFiles string
  583. Reason string
  584. }
  585. // LogConsumer is a callback to process log messages from services
  586. type LogConsumer interface {
  587. Log(containerName, message string)
  588. Err(containerName, message string)
  589. Status(container, msg string)
  590. }
  591. // ContainerEventListener is a callback to process ContainerEvent from services
  592. type ContainerEventListener func(event ContainerEvent)
  593. // ContainerEvent notify an event has been collected on source container implementing Service
  594. type ContainerEvent struct {
  595. Type int
  596. Time int64
  597. Container *ContainerSummary
  598. // Source is the name of the container _without the project prefix_.
  599. //
  600. // This is only suitable for display purposes within Compose, as it's
  601. // not guaranteed to be unique across services.
  602. Source string
  603. ID string
  604. Service string
  605. Line string
  606. // ExitCode is only set on ContainerEventExited events
  607. ExitCode int
  608. Restarting bool
  609. }
  610. const (
  611. // ContainerEventLog is a ContainerEvent of type log on stdout. Line is set
  612. ContainerEventLog = iota
  613. // ContainerEventErr is a ContainerEvent of type log on stderr. Line is set
  614. ContainerEventErr
  615. // ContainerEventStarted let consumer know a container has been started
  616. ContainerEventStarted
  617. // ContainerEventRestarted let consumer know a container has been restarted
  618. ContainerEventRestarted
  619. // ContainerEventStopped is a ContainerEvent of type stopped.
  620. ContainerEventStopped
  621. // ContainerEventCreated let consumer know a new container has been created
  622. ContainerEventCreated
  623. // ContainerEventRecreated let consumer know container stopped but his being replaced
  624. ContainerEventRecreated
  625. // ContainerEventExited is a ContainerEvent of type exit. ExitCode is set
  626. ContainerEventExited
  627. // UserCancel user cancelled compose up, we are stopping containers
  628. HookEventLog
  629. )
  630. // Separator is used for naming components
  631. var Separator = "-"
  632. // GetImageNameOrDefault computes the default image name for a service, used to tag built images
  633. func GetImageNameOrDefault(service types.ServiceConfig, projectName string) string {
  634. imageName := service.Image
  635. if imageName == "" {
  636. imageName = projectName + Separator + service.Name
  637. }
  638. return imageName
  639. }