api.go 22 KB

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