Skip to content

Commit

Permalink
WiP
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Feb 15, 2023
1 parent 313b82e commit ef70f19
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
23 changes: 13 additions & 10 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type ProjectOptions struct {
ConfigPaths []string
WorkDir string
ProjectDir string
EnvFile string
EnvFiles []string
Compatibility bool
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func (o *ProjectOptions) addProjectFlags(f *pflag.FlagSet) {
f.StringArrayVar(&o.Profiles, "profile", []string{}, "Specify a profile to enable")
f.StringVarP(&o.ProjectName, "project-name", "p", "", "Project name")
f.StringArrayVarP(&o.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
f.StringVar(&o.EnvFile, "env-file", "", "Specify an alternate environment file.")
f.StringArrayVar(&o.EnvFiles, "env-file", nil, "Specify alternate environment files.")
f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the, first specified, Compose file)")
f.StringVar(&o.WorkDir, "workdir", "", "DEPRECATED! USE --project-directory INSTEAD.\nSpecify an alternate working directory\n(default: the path of the, first specified, Compose file)")
f.BoolVar(&o.Compatibility, "compatibility", false, "Run compose in backward compatibility mode")
Expand Down Expand Up @@ -198,8 +198,8 @@ func (o *ProjectOptions) ToProject(services []string, po ...cli.ProjectOptionsFn
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
api.OneoffLabel: "False", // default, will be overridden by `run` command
}
if o.EnvFile != "" {
s.CustomLabels[api.EnvironmentFileLabel] = o.EnvFile
if len(o.EnvFiles) != 0 {
s.CustomLabels[api.EnvironmentFileLabel] = strings.Join(o.EnvFiles, ",")
}
project.Services[i] = s
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj
append(po,
cli.WithWorkingDirectory(o.ProjectDir),
cli.WithOsEnv,
cli.WithEnvFile(o.EnvFile),
cli.WithEnvFiles(o.EnvFiles...),
cli.WithDotEnv,
cli.WithConfigFileEnv,
cli.WithDefaultConfigPath,
Expand Down Expand Up @@ -322,10 +322,13 @@ func RootCommand(streams command.Cli, backend api.Service) *cobra.Command { //no
opts.ProjectDir = opts.WorkDir
fmt.Fprint(os.Stderr, aec.Apply("option '--workdir' is DEPRECATED at root level! Please use '--project-directory' instead.\n", aec.RedF))
}
if opts.EnvFile != "" && !filepath.IsAbs(opts.EnvFile) {
opts.EnvFile, err = filepath.Abs(opts.EnvFile)
if err != nil {
return err
for i, file := range opts.EnvFiles {
if !filepath.IsAbs(file) {
file, err = filepath.Abs(file)
if err != nil {
return err
}
opts.EnvFiles[i] = file
}
}
if v, ok := os.LookupEnv("COMPOSE_PARALLEL_LIMIT"); ok && !cmd.Flags().Changed("parallel") {
Expand Down Expand Up @@ -412,7 +415,7 @@ func setEnvWithDotEnv(prjOpts *ProjectOptions) error {
return err
}

envFromFile, err := cli.GetEnvFromFile(composegoutils.GetAsEqualsMap(os.Environ()), workingDir, options.EnvFile)
envFromFile, err := cli.GetEnvFromFile(composegoutils.GetAsEqualsMap(os.Environ()), workingDir, options.EnvFiles)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ require (
)

replace (
github.com/compose-spec/compose-go => github.com/ndeloof/compose-go v1.2.4-0.20230215173948-358a28587d79

// Override for e2e tests
github.com/cucumber/godog => github.com/laurazard/godog v0.0.0-20220922095256-4c4b17abdae7

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/compose-spec/compose-go v1.9.0 h1:oaewhNhUP/AClVs6ytHzcjw1xwK+2EMWuvHXj6tYvRc=
github.com/compose-spec/compose-go v1.9.0/go.mod h1:Tb5Ae2PsYN3GTqYqzl2IRbTPiJtPZZjMw8UKUvmehFk=
github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
Expand Down Expand Up @@ -575,6 +573,8 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/ndeloof/compose-go v1.2.4-0.20230215173948-358a28587d79 h1:z6n976xv6pD1JbetDbZIj4BKL8zShim3g5EZXAf+2kw=
github.com/ndeloof/compose-go v1.2.4-0.20230215173948-358a28587d79/go.mod h1:Tb5Ae2PsYN3GTqYqzl2IRbTPiJtPZZjMw8UKUvmehFk=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
10 changes: 10 additions & 0 deletions pkg/compose/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
}
}

// ignore depends_on relations which are not impacted by restarting service
for i, service := range project.Services {
for name, r := range service.DependsOn {
if !r.Restart {
delete(service.DependsOn, name)
}
}
project.Services[i] = service
}

if len(options.Services) == 0 {
err = project.ForServices(options.Services)
if err != nil {
Expand Down

0 comments on commit ef70f19

Please sign in to comment.