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. // GetConfiguredStreams returns the configured I/O streams (stdout, stderr, stdin).
  96. // If no custom streams were configured, it returns the dockerCli streams.
  97. GetConfiguredStreams() (stdout io.Writer, stderr io.Writer, stdin io.Reader)
  98. }
  99. type VolumesOptions struct {
  100. Services []string
  101. }
  102. type VolumesSummary = *volume.Volume
  103. type ScaleOptions struct {
  104. Services []string
  105. }
  106. type WaitOptions struct {
  107. // Services passed in the command line to be waited
  108. Services []string
  109. // Executes a down when a container exits
  110. DownProjectOnContainerExit bool
  111. }
  112. type VizOptions struct {
  113. // IncludeNetworks if true, network names a container is attached to should appear in the graph node
  114. IncludeNetworks bool
  115. // IncludePorts if true, ports a container exposes should appear in the graph node
  116. IncludePorts bool
  117. // IncludeImageName if true, name of the image used to create a container should appear in the graph node
  118. IncludeImageName bool
  119. // Indentation string to be used to indent graphviz code, e.g. "\t", " "
  120. Indentation string
  121. }
  122. // WatchLogger is a reserved name to log watch events
  123. const WatchLogger = "#watch"
  124. // WatchOptions group options of the Watch API
  125. type WatchOptions struct {
  126. Build *BuildOptions
  127. LogTo LogConsumer
  128. Prune bool
  129. Services []string
  130. }
  131. // BuildOptions group options of the Build API
  132. type BuildOptions struct {
  133. // Pull always attempt to pull a newer version of the image
  134. Pull bool
  135. // Push pushes service images
  136. Push bool
  137. // Progress set type of progress output ("auto", "plain", "tty")
  138. Progress string
  139. // Args set build-time args
  140. Args types.MappingWithEquals
  141. // NoCache disables cache use
  142. NoCache bool
  143. // Quiet make the build process not output to the console
  144. Quiet bool
  145. // Services passed in the command line to be built
  146. Services []string
  147. // Deps also build selected services dependencies
  148. Deps bool
  149. // Ssh authentications passed in the command line
  150. SSHs []types.SSHKey
  151. // Memory limit for the build container
  152. Memory int64
  153. // Builder name passed in the command line
  154. Builder string
  155. // Print don't actually run builder but print equivalent build config
  156. Print bool
  157. // Check let builder validate build configuration
  158. Check bool
  159. // Attestations allows to enable attestations generation
  160. Attestations bool
  161. // Provenance generate a provenance attestation
  162. Provenance string
  163. // SBOM generate a SBOM attestation
  164. SBOM string
  165. // Out is the stream to write build progress
  166. Out io.Writer
  167. }
  168. // Apply mutates project according to build options
  169. func (o BuildOptions) Apply(project *types.Project) error {
  170. platform := project.Environment["DOCKER_DEFAULT_PLATFORM"]
  171. for name, service := range project.Services {
  172. if service.Provider == nil && service.Image == "" && service.Build == nil {
  173. return fmt.Errorf("invalid service %q. Must specify either image or build", name)
  174. }
  175. if service.Build == nil {
  176. continue
  177. }
  178. if platform != "" {
  179. if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, platform) {
  180. return fmt.Errorf("service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s", name, platform)
  181. }
  182. service.Platform = platform
  183. }
  184. if service.Platform != "" {
  185. if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, service.Platform) {
  186. return fmt.Errorf("service %q build configuration does not support platform: %s", name, service.Platform)
  187. }
  188. }
  189. service.Build.Pull = service.Build.Pull || o.Pull
  190. service.Build.NoCache = service.Build.NoCache || o.NoCache
  191. project.Services[name] = service
  192. }
  193. return nil
  194. }
  195. // CreateOptions group options of the Create API
  196. type CreateOptions struct {
  197. Build *BuildOptions
  198. // Services defines the services user interacts with
  199. Services []string
  200. // Remove legacy containers for services that are not defined in the project
  201. RemoveOrphans bool
  202. // Ignore legacy containers for services that are not defined in the project
  203. IgnoreOrphans bool
  204. // Recreate define the strategy to apply on existing containers
  205. Recreate string
  206. // RecreateDependencies define the strategy to apply on dependencies services
  207. RecreateDependencies string
  208. // Inherit reuse anonymous volumes from previous container
  209. Inherit bool
  210. // Timeout set delay to wait for container to gracefully stop before sending SIGKILL
  211. Timeout *time.Duration
  212. // QuietPull makes the pulling process quiet
  213. QuietPull bool
  214. }
  215. // StartOptions group options of the Start API
  216. type StartOptions struct {
  217. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  218. Project *types.Project
  219. // Attach to container and forward logs if not nil
  220. Attach LogConsumer
  221. // AttachTo set the services to attach to
  222. AttachTo []string
  223. // OnExit defines behavior when a container stops
  224. OnExit Cascade
  225. // ExitCodeFrom return exit code from specified service
  226. ExitCodeFrom string
  227. // Wait won't return until containers reached the running|healthy state
  228. Wait bool
  229. WaitTimeout time.Duration
  230. // Services passed in the command line to be started
  231. Services []string
  232. Watch bool
  233. NavigationMenu bool
  234. }
  235. type Cascade int
  236. const (
  237. CascadeIgnore Cascade = iota
  238. CascadeStop Cascade = iota
  239. CascadeFail Cascade = iota
  240. )
  241. // RestartOptions group options of the Restart API
  242. type RestartOptions struct {
  243. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  244. Project *types.Project
  245. // Timeout override container restart timeout
  246. Timeout *time.Duration
  247. // Services passed in the command line to be restarted
  248. Services []string
  249. // NoDeps ignores services dependencies
  250. NoDeps bool
  251. }
  252. // StopOptions group options of the Stop API
  253. type StopOptions struct {
  254. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  255. Project *types.Project
  256. // Timeout override container stop timeout
  257. Timeout *time.Duration
  258. // Services passed in the command line to be stopped
  259. Services []string
  260. }
  261. // UpOptions group options of the Up API
  262. type UpOptions struct {
  263. Create CreateOptions
  264. Start StartOptions
  265. }
  266. // DownOptions group options of the Down API
  267. type DownOptions struct {
  268. // RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
  269. RemoveOrphans bool
  270. // Project is the compose project used to define this app. Might be nil if user ran `down` just with project name
  271. Project *types.Project
  272. // Timeout override container stop timeout
  273. Timeout *time.Duration
  274. // Images remove image used by services. 'all': Remove all images. 'local': Remove only images that don't have a tag
  275. Images string
  276. // Volumes remove volumes, both declared in the `volumes` section and anonymous ones
  277. Volumes bool
  278. // Services passed in the command line to be stopped
  279. Services []string
  280. }
  281. // ConfigOptions group options of the Config API
  282. type ConfigOptions struct {
  283. // Format define the output format used to dump converted application model (json|yaml)
  284. Format string
  285. // Output defines the path to save the application model
  286. Output string
  287. // Resolve image reference to digests
  288. ResolveImageDigests bool
  289. }
  290. // PushOptions group options of the Push API
  291. type PushOptions struct {
  292. Quiet bool
  293. IgnoreFailures bool
  294. ImageMandatory bool
  295. }
  296. // PullOptions group options of the Pull API
  297. type PullOptions struct {
  298. Quiet bool
  299. IgnoreFailures bool
  300. IgnoreBuildable bool
  301. }
  302. // ImagesOptions group options of the Images API
  303. type ImagesOptions struct {
  304. Services []string
  305. }
  306. // KillOptions group options of the Kill API
  307. type KillOptions struct {
  308. // RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
  309. RemoveOrphans bool
  310. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  311. Project *types.Project
  312. // Services passed in the command line to be killed
  313. Services []string
  314. // Signal to send to containers
  315. Signal string
  316. // All can be set to true to try to kill all found containers, independently of their state
  317. All bool
  318. }
  319. // RemoveOptions group options of the Remove API
  320. type RemoveOptions struct {
  321. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  322. Project *types.Project
  323. // Stop option passed in the command line
  324. Stop bool
  325. // Volumes remove anonymous volumes
  326. Volumes bool
  327. // Force don't ask to confirm removal
  328. Force bool
  329. // Services passed in the command line to be removed
  330. Services []string
  331. }
  332. // RunOptions group options of the Run API
  333. type RunOptions struct {
  334. CreateOptions
  335. // Project is the compose project used to define this app. Might be nil if user ran command just with project name
  336. Project *types.Project
  337. Name string
  338. Service string
  339. Command []string
  340. Entrypoint []string
  341. Detach bool
  342. AutoRemove bool
  343. Tty bool
  344. Interactive bool
  345. WorkingDir string
  346. User string
  347. Environment []string
  348. CapAdd []string
  349. CapDrop []string
  350. Labels types.Labels
  351. Privileged bool
  352. UseNetworkAliases bool
  353. NoDeps bool
  354. // used by exec
  355. Index int
  356. }
  357. // AttachOptions group options of the Attach API
  358. type AttachOptions struct {
  359. Project *types.Project
  360. Service string
  361. Index int
  362. DetachKeys string
  363. NoStdin bool
  364. Proxy bool
  365. }
  366. // EventsOptions group options of the Events API
  367. type EventsOptions struct {
  368. Services []string
  369. Consumer func(event Event) error
  370. Since string
  371. Until string
  372. }
  373. // Event is a container runtime event served by Events API
  374. type Event struct {
  375. Timestamp time.Time
  376. Service string
  377. Container string
  378. Status string
  379. Attributes map[string]string
  380. }
  381. // PortOptions group options of the Port API
  382. type PortOptions struct {
  383. Protocol string
  384. Index int
  385. }
  386. // OCIVersion controls manifest generation to ensure compatibility
  387. // with different registries.
  388. //
  389. // Currently, this is not exposed as an option to the user – Compose uses
  390. // OCI 1.0 mode automatically for ECR registries based on domain and OCI 1.1
  391. // for all other registries.
  392. //
  393. // There are likely other popular registries that do not support the OCI 1.1
  394. // format, so it might make sense to expose this as a CLI flag or see if
  395. // there's a way to generically probe the registry for support level.
  396. type OCIVersion string
  397. const (
  398. OCIVersion1_0 OCIVersion = "1.0"
  399. OCIVersion1_1 OCIVersion = "1.1"
  400. )
  401. // PublishOptions group options of the Publish API
  402. type PublishOptions struct {
  403. ResolveImageDigests bool
  404. Application bool
  405. WithEnvironment 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. }