-
Notifications
You must be signed in to change notification settings - Fork 311
/
deploy.go
86 lines (75 loc) · 3.16 KB
/
deploy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2021 The Okteto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package stack
import (
"context"
"time"
"github.com/joho/godotenv"
contextCMD "github.com/okteto/okteto/cmd/context"
"github.com/okteto/okteto/pkg/analytics"
"github.com/okteto/okteto/pkg/cmd/stack"
"github.com/okteto/okteto/pkg/log"
"github.com/okteto/okteto/pkg/model"
"github.com/okteto/okteto/pkg/okteto"
"github.com/spf13/cobra"
)
// Deploy deploys a stack
func Deploy(ctx context.Context) *cobra.Command {
options := &stack.StackDeployOptions{}
cmd := &cobra.Command{
Use: "deploy [service...]",
Short: "Deploy a stack",
RunE: func(cmd *cobra.Command, args []string) error {
if model.FileExists(".env") {
err := godotenv.Load()
if err != nil {
log.Errorf("error loading .env file: %s", err.Error())
}
}
s, err := contextCMD.LoadStackWithContext(ctx, options.Name, options.Namespace, options.StackPath)
if err != nil {
return err
}
analytics.TrackStackWarnings(s.Warnings.NotSupportedFields)
if len(args) > 0 {
options.ServicesToDeploy = args
} else {
definedSvcs := make([]string, 0)
for svcName := range s.Services {
definedSvcs = append(definedSvcs, svcName)
}
options.ServicesToDeploy = definedSvcs
}
err = stack.Deploy(ctx, s, options)
analytics.TrackDeployStack(err == nil, s.IsCompose)
if err == nil {
log.Success("Stack '%s' successfully deployed", s.Name)
}
if okteto.Context().IsOkteto {
if err := stack.ListEndpoints(ctx, s, ""); err != nil {
return err
}
}
return err
},
}
cmd.Flags().StringArrayVarP(&options.StackPath, "file", "f", []string{}, "path to the stack manifest files. If more than one is passed the latest will overwrite the fields from the previous")
cmd.Flags().StringVarP(&options.Name, "name", "", "", "overwrites the stack name")
cmd.Flags().StringVarP(&options.Namespace, "namespace", "n", "", "overwrites the stack namespace where the stack is deployed")
cmd.Flags().BoolVarP(&options.ForceBuild, "build", "", false, "build images before starting any Stack service")
cmd.Flags().BoolVarP(&options.Wait, "wait", "", false, "wait until a minimum number of containers are in a ready state for every service")
cmd.Flags().BoolVarP(&options.NoCache, "no-cache", "", false, "do not use cache when building the image")
cmd.Flags().DurationVarP(&options.Timeout, "timeout", "t", (10 * time.Minute), "the length of time to wait for completion, zero means never. Any other values should contain a corresponding time unit e.g. 1s, 2m, 3h ")
cmd.Flags().StringVarP(&options.Progress, "progress", "", "tty", "show plain/tty build output (default \"tty\")")
return cmd
}