api.go 22 KB

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