api.go 23 KB

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