api.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. // Watch services' development context and sync/notify/rebuild/restart on changes
  80. Watch(ctx context.Context, project *types.Project, options WatchOptions) error
  81. // Viz generates a graphviz graph of the project services
  82. Viz(ctx context.Context, project *types.Project, options VizOptions) (string, error)
  83. // Wait blocks until at least one of the services' container exits
  84. Wait(ctx context.Context, projectName string, options WaitOptions) (int64, error)
  85. // Scale manages numbers of container instances running per service
  86. Scale(ctx context.Context, project *types.Project, options ScaleOptions) error
  87. // Export a service container's filesystem as a tar archive
  88. Export(ctx context.Context, projectName string, options ExportOptions) error
  89. // Create a new image from a service container's changes
  90. Commit(ctx context.Context, projectName string, options CommitOptions) error
  91. // Generate generates a Compose Project from existing containers
  92. Generate(ctx context.Context, options GenerateOptions) (*types.Project, error)
  93. // Volumes executes the equivalent to a `docker volume ls`
  94. Volumes(ctx context.Context, project string, options VolumesOptions) ([]VolumesSummary, error)
  95. }
  96. type VolumesOptions struct {
  97. Services []string
  98. }
  99. type VolumesSummary = *volume.Volume
  100. type ScaleOptions struct {
  101. Services []string
  102. }
  103. type WaitOptions struct {
  104. // Services passed in the command line to be waited
  105. Services []string
  106. // Executes a down when a container exits
  107. DownProjectOnContainerExit bool
  108. }
  109. type VizOptions struct {
  110. // IncludeNetworks if true, network names a container is attached to should appear in the graph node
  111. IncludeNetworks bool
  112. // IncludePorts if true, ports a container exposes should appear in the graph node
  113. IncludePorts bool
  114. // IncludeImageName if true, name of the image used to create a container should appear in the graph node
  115. IncludeImageName bool
  116. // Indentation string to be used to indent graphviz code, e.g. "\t", " "
  117. Indentation string
  118. }
  119. // WatchLogger is a reserved name to log watch events
  120. const WatchLogger = "#watch"
  121. // WatchOptions group options of the Watch API
  122. type WatchOptions struct {
  123. Build *BuildOptions
  124. LogTo LogConsumer
  125. Prune bool
  126. Services []string
  127. }
  128. // BuildOptions group options of the Build API
  129. type BuildOptions struct {
  130. // Pull always attempt to pull a newer version of the image
  131. Pull bool
  132. // Push pushes service images
  133. Push bool
  134. // Progress set type of progress output ("auto", "plain", "tty")
  135. Progress string
  136. // Args set build-time args
  137. Args types.MappingWithEquals
  138. // NoCache disables cache use
  139. NoCache bool
  140. // Quiet make the build process not output to the console
  141. Quiet bool
  142. // Services passed in the command line to be built
  143. Services []string
  144. // Deps also build selected services dependencies
  145. Deps bool
  146. // Ssh authentications passed in the command line
  147. SSHs []types.SSHKey
  148. // Memory limit for the build container
  149. Memory int64
  150. // Builder name passed in the command line
  151. Builder string
  152. // Print don't actually run builder but print equivalent build config
  153. Print bool
  154. // Check let builder validate build configuration
  155. Check bool
  156. // Attestations allows to enable attestations generation
  157. Attestations bool
  158. // Provenance generate a provenance attestation
  159. Provenance string
  160. // SBOM generate a SBOM attestation
  161. SBOM string
  162. // Out is the stream to write build progress
  163. Out io.Writer
  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. Application bool
  404. WithEnvironment bool
  405. AssumeYes bool
  406. OCIVersion OCIVersion
  407. }
  408. func (e Event) String() string {
  409. t := e.Timestamp.Format("2006-01-02 15:04:05.000000")
  410. var attr []string
  411. for k, v := range e.Attributes {
  412. attr = append(attr, fmt.Sprintf("%s=%s", k, v))
  413. }
  414. return fmt.Sprintf("%s container %s %s (%s)\n", t, e.Status, e.Container, strings.Join(attr, ", "))
  415. }
  416. // ListOptions group options of the ls API
  417. type ListOptions struct {
  418. All bool
  419. }
  420. // PsOptions group options of the Ps API
  421. type PsOptions struct {
  422. Project *types.Project
  423. All bool
  424. Services []string
  425. }
  426. // CopyOptions group options of the cp API
  427. type CopyOptions struct {
  428. Source string
  429. Destination string
  430. All bool
  431. Index int
  432. FollowLink bool
  433. CopyUIDGID bool
  434. }
  435. // PortPublisher hold status about published port
  436. type PortPublisher struct {
  437. URL string
  438. TargetPort int
  439. PublishedPort int
  440. Protocol string
  441. }
  442. // ContainerSummary hold high-level description of a container
  443. type ContainerSummary struct {
  444. ID string
  445. Name string
  446. Names []string
  447. Image string
  448. Command string
  449. Project string
  450. Service string
  451. Created int64
  452. State string
  453. Status string
  454. Health string
  455. ExitCode int
  456. Publishers PortPublishers
  457. Labels map[string]string
  458. SizeRw int64 `json:",omitempty"`
  459. SizeRootFs int64 `json:",omitempty"`
  460. Mounts []string
  461. Networks []string
  462. LocalVolumes int
  463. }
  464. // PortPublishers is a slice of PortPublisher
  465. type PortPublishers []PortPublisher
  466. // Len implements sort.Interface
  467. func (p PortPublishers) Len() int {
  468. return len(p)
  469. }
  470. // Less implements sort.Interface
  471. func (p PortPublishers) Less(i, j int) bool {
  472. left := p[i]
  473. right := p[j]
  474. if left.URL != right.URL {
  475. return left.URL < right.URL
  476. }
  477. if left.TargetPort != right.TargetPort {
  478. return left.TargetPort < right.TargetPort
  479. }
  480. if left.PublishedPort != right.PublishedPort {
  481. return left.PublishedPort < right.PublishedPort
  482. }
  483. return left.Protocol < right.Protocol
  484. }
  485. // Swap implements sort.Interface
  486. func (p PortPublishers) Swap(i, j int) {
  487. p[i], p[j] = p[j], p[i]
  488. }
  489. // ContainerProcSummary holds container processes top data
  490. type ContainerProcSummary struct {
  491. ID string
  492. Name string
  493. Processes [][]string
  494. Titles []string
  495. Service string
  496. Replica string
  497. }
  498. // ImageSummary holds container image description
  499. type ImageSummary struct {
  500. ID string
  501. Repository string
  502. Tag string
  503. Platform platforms.Platform
  504. Size int64
  505. Created time.Time
  506. LastTagTime time.Time
  507. }
  508. // ServiceStatus hold status about a service
  509. type ServiceStatus struct {
  510. ID string
  511. Name string
  512. Replicas int
  513. Desired int
  514. Ports []string
  515. Publishers []PortPublisher
  516. }
  517. // LogOptions defines optional parameters for the `Log` API
  518. type LogOptions struct {
  519. Project *types.Project
  520. Index int
  521. Services []string
  522. Tail string
  523. Since string
  524. Until string
  525. Follow bool
  526. Timestamps bool
  527. }
  528. // PauseOptions group options of the Pause API
  529. type PauseOptions struct {
  530. // Services passed in the command line to be started
  531. Services []string
  532. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  533. Project *types.Project
  534. }
  535. // ExportOptions group options of the Export API
  536. type ExportOptions struct {
  537. Service string
  538. Index int
  539. Output string
  540. }
  541. // CommitOptions group options of the Commit API
  542. type CommitOptions struct {
  543. Service string
  544. Reference string
  545. Pause bool
  546. Comment string
  547. Author string
  548. Changes opts.ListOpts
  549. Index int
  550. }
  551. type GenerateOptions struct {
  552. // ProjectName to set in the Compose file
  553. ProjectName string
  554. // Containers passed in the command line to be used as reference for service definition
  555. Containers []string
  556. }
  557. const (
  558. // STARTING indicates that stack is being deployed
  559. STARTING string = "Starting"
  560. // RUNNING indicates that stack is deployed and services are running
  561. RUNNING string = "Running"
  562. // UPDATING indicates that some stack resources are being recreated
  563. UPDATING string = "Updating"
  564. // REMOVING indicates that stack is being deleted
  565. REMOVING string = "Removing"
  566. // UNKNOWN indicates unknown stack state
  567. UNKNOWN string = "Unknown"
  568. // FAILED indicates that stack deployment failed
  569. FAILED string = "Failed"
  570. )
  571. const (
  572. // RecreateDiverged to recreate services which configuration diverges from compose model
  573. RecreateDiverged = "diverged"
  574. // RecreateForce to force service container being recreated
  575. RecreateForce = "force"
  576. // RecreateNever to never recreate existing service containers
  577. RecreateNever = "never"
  578. )
  579. // Stack holds the name and state of a compose application/stack
  580. type Stack struct {
  581. ID string
  582. Name string
  583. Status string
  584. ConfigFiles string
  585. Reason string
  586. }
  587. // LogConsumer is a callback to process log messages from services
  588. type LogConsumer interface {
  589. Log(containerName, message string)
  590. Err(containerName, message string)
  591. Status(container, msg string)
  592. }
  593. // ContainerEventListener is a callback to process ContainerEvent from services
  594. type ContainerEventListener func(event ContainerEvent)
  595. // ContainerEvent notify an event has been collected on source container implementing Service
  596. type ContainerEvent struct {
  597. Type int
  598. Time int64
  599. Container *ContainerSummary
  600. // Source is the name of the container _without the project prefix_.
  601. //
  602. // This is only suitable for display purposes within Compose, as it's
  603. // not guaranteed to be unique across services.
  604. Source string
  605. ID string
  606. Service string
  607. Line string
  608. // ExitCode is only set on ContainerEventExited events
  609. ExitCode int
  610. Restarting bool
  611. }
  612. const (
  613. // ContainerEventLog is a ContainerEvent of type log on stdout. Line is set
  614. ContainerEventLog = iota
  615. // ContainerEventErr is a ContainerEvent of type log on stderr. Line is set
  616. ContainerEventErr
  617. // ContainerEventStarted let consumer know a container has been started
  618. ContainerEventStarted
  619. // ContainerEventRestarted let consumer know a container has been restarted
  620. ContainerEventRestarted
  621. // ContainerEventStopped is a ContainerEvent of type stopped.
  622. ContainerEventStopped
  623. // ContainerEventCreated let consumer know a new container has been created
  624. ContainerEventCreated
  625. // ContainerEventRecreated let consumer know container stopped but his being replaced
  626. ContainerEventRecreated
  627. // ContainerEventExited is a ContainerEvent of type exit. ExitCode is set
  628. ContainerEventExited
  629. // UserCancel user cancelled compose up, we are stopping containers
  630. HookEventLog
  631. )
  632. // Separator is used for naming components
  633. var Separator = "-"
  634. // GetImageNameOrDefault computes the default image name for a service, used to tag built images
  635. func GetImageNameOrDefault(service types.ServiceConfig, projectName string) string {
  636. imageName := service.Image
  637. if imageName == "" {
  638. imageName = projectName + Separator + service.Name
  639. }
  640. return imageName
  641. }