mirror of https://github.com/portainer/portainer
fix(libstack): add the build step for Compose BE-11448 (#173)
parent
4046bf7b31
commit
faa6b2b790
|
@ -70,6 +70,10 @@ func withComposeService(
|
||||||
return withCli(ctx, options, func(ctx context.Context, cli *command.DockerCli) error {
|
return withCli(ctx, options, func(ctx context.Context, cli *command.DockerCli) error {
|
||||||
composeService := compose.NewComposeService(cli)
|
composeService := compose.NewComposeService(cli)
|
||||||
|
|
||||||
|
if len(filePaths) == 0 {
|
||||||
|
return composeFn(composeService, nil)
|
||||||
|
}
|
||||||
|
|
||||||
env, err := parseEnvironment(options)
|
env, err := parseEnvironment(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -77,16 +81,13 @@ func withComposeService(
|
||||||
|
|
||||||
configDetails := types.ConfigDetails{
|
configDetails := types.ConfigDetails{
|
||||||
Environment: env,
|
Environment: env,
|
||||||
|
WorkingDir: filepath.Dir(filePaths[0]),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range filePaths {
|
for _, p := range filePaths {
|
||||||
configDetails.ConfigFiles = append(configDetails.ConfigFiles, types.ConfigFile{Filename: p})
|
configDetails.ConfigFiles = append(configDetails.ConfigFiles, types.ConfigFile{Filename: p})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(configDetails.ConfigFiles) == 0 {
|
|
||||||
return composeFn(composeService, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
project, err := loader.LoadWithContext(ctx, configDetails,
|
project, err := loader.LoadWithContext(ctx, configDetails,
|
||||||
func(o *loader.Options) {
|
func(o *loader.Options) {
|
||||||
o.SkipResolveEnvironment = true
|
o.SkipResolveEnvironment = true
|
||||||
|
@ -105,7 +106,7 @@ func withComposeService(
|
||||||
for i, service := range project.Services {
|
for i, service := range project.Services {
|
||||||
for j, envFile := range service.EnvFiles {
|
for j, envFile := range service.EnvFiles {
|
||||||
if !filepath.IsAbs(envFile.Path) {
|
if !filepath.IsAbs(envFile.Path) {
|
||||||
project.Services[i].EnvFiles[j].Path = filepath.Join(filepath.Dir(filePaths[0]), envFile.Path)
|
project.Services[i].EnvFiles[j].Path = filepath.Join(configDetails.WorkingDir, envFile.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +137,10 @@ func (c *ComposeDeployer) Deploy(ctx context.Context, filePaths []string, option
|
||||||
opts.Create.RemoveOrphans = options.RemoveOrphans
|
opts.Create.RemoveOrphans = options.RemoveOrphans
|
||||||
opts.Start.CascadeStop = options.AbortOnContainerExit
|
opts.Start.CascadeStop = options.AbortOnContainerExit
|
||||||
|
|
||||||
|
if err := composeService.Build(ctx, project, api.BuildOptions{}); err != nil {
|
||||||
|
return fmt.Errorf("compose build operation failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := composeService.Up(ctx, project, opts); err != nil {
|
if err := composeService.Up(ctx, project, opts); err != nil {
|
||||||
return fmt.Errorf("compose up operation failed: %w", err)
|
return fmt.Errorf("compose up operation failed: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -248,7 +253,7 @@ func addServiceLabels(project *types.Project, oneOff bool) {
|
||||||
api.ProjectLabel: project.Name,
|
api.ProjectLabel: project.Name,
|
||||||
api.ServiceLabel: s.Name,
|
api.ServiceLabel: s.Name,
|
||||||
api.VersionLabel: api.ComposeVersion,
|
api.VersionLabel: api.ComposeVersion,
|
||||||
api.WorkingDirLabel: "/",
|
api.WorkingDirLabel: project.WorkingDir,
|
||||||
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
|
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
|
||||||
api.OneoffLabel: oneOffLabel,
|
api.OneoffLabel: oneOffLabel,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue