api.go 22 KB

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