mirror of https://github.com/docker/compose.git
Merge pull request #1340 from docker/no_build
This commit is contained in:
commit
19af456504
|
@ -17,6 +17,8 @@
|
||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,10 +36,17 @@ func createCommand(p *projectOptions) *cobra.Command {
|
||||||
Use: "create [SERVICE...]",
|
Use: "create [SERVICE...]",
|
||||||
Short: "Creates containers for a service.",
|
Short: "Creates containers for a service.",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if opts.Build && opts.noBuild {
|
||||||
|
return fmt.Errorf("--build and --no-build are incompatible")
|
||||||
|
}
|
||||||
|
if opts.forceRecreate && opts.noRecreate {
|
||||||
|
return fmt.Errorf("--force-recreate and --no-recreate are incompatible")
|
||||||
|
}
|
||||||
return runCreateStart(cmd.Context(), upOptions{
|
return runCreateStart(cmd.Context(), upOptions{
|
||||||
composeOptions: &composeOptions{
|
composeOptions: &composeOptions{
|
||||||
projectOptions: p,
|
projectOptions: p,
|
||||||
Build: opts.Build,
|
Build: opts.Build,
|
||||||
|
noBuild: opts.noBuild,
|
||||||
},
|
},
|
||||||
noStart: true,
|
noStart: true,
|
||||||
forceRecreate: opts.forceRecreate,
|
forceRecreate: opts.forceRecreate,
|
||||||
|
@ -47,6 +56,7 @@ func createCommand(p *projectOptions) *cobra.Command {
|
||||||
}
|
}
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers.")
|
flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers.")
|
||||||
|
flags.BoolVar(&opts.noBuild, "no-build", false, "Don't build an image, even if it's missing.")
|
||||||
flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
|
flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
|
||||||
flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
|
flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
@ -43,6 +43,7 @@ import (
|
||||||
type composeOptions struct {
|
type composeOptions struct {
|
||||||
*projectOptions
|
*projectOptions
|
||||||
Build bool
|
Build bool
|
||||||
|
noBuild bool
|
||||||
// ACI only
|
// ACI only
|
||||||
DomainName string
|
DomainName string
|
||||||
}
|
}
|
||||||
|
@ -87,6 +88,9 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
||||||
if opts.exitCodeFrom != "" {
|
if opts.exitCodeFrom != "" {
|
||||||
opts.cascadeStop = true
|
opts.cascadeStop = true
|
||||||
}
|
}
|
||||||
|
if opts.Build && opts.noBuild {
|
||||||
|
return fmt.Errorf("--build and --no-build are incompatible")
|
||||||
|
}
|
||||||
if opts.cascadeStop && opts.Detach {
|
if opts.cascadeStop && opts.Detach {
|
||||||
return fmt.Errorf("--abort-on-container-exit and --detach are incompatible")
|
return fmt.Errorf("--abort-on-container-exit and --detach are incompatible")
|
||||||
}
|
}
|
||||||
|
@ -103,6 +107,7 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
||||||
flags.StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
flags.StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
||||||
flags.BoolVarP(&opts.Detach, "detach", "d", false, "Detached mode: Run containers in the background")
|
flags.BoolVarP(&opts.Detach, "detach", "d", false, "Detached mode: Run containers in the background")
|
||||||
flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers.")
|
flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers.")
|
||||||
|
flags.BoolVar(&opts.noBuild, "no-build", false, "Don't build an image, even if it's missing.")
|
||||||
flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
|
flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
|
||||||
flags.StringArrayVar(&opts.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.")
|
flags.StringArrayVar(&opts.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.")
|
||||||
flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome output.")
|
flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome output.")
|
||||||
|
@ -284,10 +289,18 @@ func setup(ctx context.Context, opts composeOptions, services []string) (*client
|
||||||
project.Services[0].DomainName = opts.DomainName
|
project.Services[0].DomainName = opts.DomainName
|
||||||
}
|
}
|
||||||
if opts.Build {
|
if opts.Build {
|
||||||
for _, service := range project.Services {
|
for i, service := range project.Services {
|
||||||
service.PullPolicy = types.PullPolicyBuild
|
service.PullPolicy = types.PullPolicyBuild
|
||||||
|
project.Services[i] = service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if opts.noBuild {
|
||||||
|
for i, service := range project.Services {
|
||||||
|
service.Build = nil
|
||||||
|
project.Services[i] = service
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if opts.EnvFile != "" {
|
if opts.EnvFile != "" {
|
||||||
var services types.Services
|
var services types.Services
|
||||||
for _, s := range project.Services {
|
for _, s := range project.Services {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO build vs pull should be controlled by pull policy, see https://github.com/compose-spec/compose-spec/issues/26
|
|
||||||
if service.Image != "" {
|
if service.Image != "" {
|
||||||
if localImagePresent {
|
if localImagePresent {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue