api.go 22 KB

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