@@ -19,7 +19,6 @@ import (
1919 "github.com/loft-sh/devspace/pkg/devspace/pipeline"
2020 "github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
2121 "github.com/loft-sh/devspace/pkg/devspace/plugin"
22- "github.com/loft-sh/devspace/pkg/devspace/server"
2322 "github.com/loft-sh/devspace/pkg/devspace/upgrade"
2423 "github.com/loft-sh/devspace/pkg/util/factory"
2524 logpkg "github.com/loft-sh/devspace/pkg/util/log"
@@ -29,6 +28,8 @@ import (
2928 "github.com/spf13/cobra"
3029 "gopkg.in/yaml.v3"
3130 "k8s.io/client-go/kubernetes/fake"
31+ "os"
32+ "strings"
3233)
3334
3435// DeployCmd holds the required data for the down cmd
@@ -124,7 +125,7 @@ func (cmd *DeployCmd) Run(f factory.Factory) error {
124125}
125126
126127func (cmd * DeployCmd ) runCommand (ctx * devspacecontext.Context , f factory.Factory , configOptions * loader.ConfigOptions ) error {
127- return runPipeline (ctx , f , & PipelineOptions {
128+ return runPipeline (ctx , f , true , & PipelineOptions {
128129 Options : types.Options {
129130 BuildOptions : build.Options {
130131 SkipBuild : cmd .SkipBuild ,
@@ -223,7 +224,7 @@ type PipelineOptions struct {
223224 UIPort int
224225}
225226
226- func runPipeline (ctx * devspacecontext.Context , f factory.Factory , options * PipelineOptions ) error {
227+ func runPipeline (ctx * devspacecontext.Context , f factory.Factory , forceLeader bool , options * PipelineOptions ) error {
227228 // create namespace if necessary
228229 if ! options .DeployOptions .Render {
229230 err := ctx .KubeClient .EnsureNamespace (ctx .Context , ctx .KubeClient .Namespace (), ctx .Log )
@@ -242,12 +243,6 @@ func runPipeline(ctx *devspacecontext.Context, f factory.Factory, options *Pipel
242243 }
243244 ctx = ctx .WithDependencies (dependencies )
244245
245- // start ui & open
246- serv , err := startServices (ctx , options .UIPort )
247- if err != nil {
248- return err
249- }
250-
251246 // execute plugin hook
252247 err = hook .ExecuteHooks (ctx , nil , "deploy" )
253248 if err != nil {
@@ -270,29 +265,36 @@ func runPipeline(ctx *devspacecontext.Context, f factory.Factory, options *Pipel
270265 }
271266 }
272267
273- // create dependency registry
274- dependencyRegistry := registry .NewDependencyRegistry ("http://" + serv .Server .Addr , options .DeployOptions .Render )
275-
276- // exclude ourselves
277- couldExclude , err := dependencyRegistry .MarkDependencyExcluded (ctx , ctx .Config .Config ().Name , true )
278- if err != nil {
279- return err
280- } else if ! couldExclude {
281- return fmt .Errorf ("couldn't start project %s, because there is another DevSpace instance active in the current namespace right now that uses the same project" , ctx .Config .Config ().Name )
268+ // marshal pipeline
269+ configPipelineBytes , err := yaml .Marshal (configPipeline )
270+ if err == nil {
271+ ctx .Log .Debugf ("Run pipeline:\n %s\n " , string (configPipelineBytes ))
282272 }
283273
284274 // create a new base dev pod manager
285275 devPodManager := devpod .NewManager (ctx .Context )
286276 defer devPodManager .Close ()
287277
288- // marshal pipeline
289- configPipelineBytes , err := yaml .Marshal (configPipeline )
290- if err == nil {
291- ctx .Log .Debugf ("Run pipeline:\n %s\n " , string (configPipelineBytes ))
292- }
278+ // create dependency registry
279+ dependencyRegistry := registry .NewDependencyRegistry (options .DeployOptions .Render )
293280
294281 // get deploy pipeline
295- pipe := pipeline .NewPipeline (options .Pipeline , devPodManager , dependencyRegistry , configPipeline , options .Options )
282+ pipe := pipeline .NewPipeline (ctx .Config .Config ().Name , devPodManager , dependencyRegistry , configPipeline , options .Options )
283+
284+ // start ui & open
285+ serv , err := dev .UI (ctx , options .UIPort , pipe )
286+ if err != nil {
287+ return err
288+ }
289+ dependencyRegistry .SetServer ("http://" + serv .Server .Addr )
290+
291+ // exclude ourselves
292+ couldExclude , err := dependencyRegistry .MarkDependencyExcluded (ctx , ctx .Config .Config ().Name , forceLeader )
293+ if err != nil {
294+ return err
295+ } else if ! couldExclude {
296+ return fmt .Errorf ("couldn't execute '%s', because there is another DevSpace instance active in the current namespace right now that uses the same project name (%s)" , strings .Join (os .Args , " " ), ctx .Config .Config ().Name )
297+ }
296298
297299 // start pipeline
298300 err = pipe .Run (ctx .WithLogger (ctx .Log .WithoutPrefix ()))
@@ -317,13 +319,3 @@ func runPipeline(ctx *devspacecontext.Context, f factory.Factory, options *Pipel
317319
318320 return nil
319321}
320-
321- func startServices (ctx * devspacecontext.Context , uiPort int ) (* server.Server , error ) {
322- // Open UI if configured
323- serv , err := dev .UI (ctx , uiPort )
324- if err != nil {
325- return nil , err
326- }
327-
328- return serv , nil
329- }
0 commit comments