GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cli/cmd/stack.go at main · PastureStack/cli

Expand file tree

/

stack.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
226 lines (198 loc) · 4.84 KB
/

stack.go

Copy path

File metadata and controls

226 lines (198 loc) · 4.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package cmd
import (
"errors"
"fmt"
"os"
"strings"
cli "github.com/PastureStack/cli/internal/legacycli"
"github.com/PastureStack/cli/internal/rancherclient/v2"
)
func StackCommand() cli.Command {
stackLsFlags := []cli.Flag{
listSystemFlag(),
cli.BoolFlag{
Name: "quiet,q",
Usage: "Only display IDs",
},
cli.StringFlag{
Name: "format",
Usage: "'json' or Custom format: '{{.ID}} {{.Stack.Name}}'",
},
}
return cli.Command{
Name: "stacks",
ShortName: "stack",
Usage: "Operations on stacks",
Action: defaultAction(stackLs),
Flags: stackLsFlags,
Subcommands: []cli.Command{
{
Name: "ls",
Usage: "List stacks",
Description: "\nLists all stacks in the current $PLATFORM_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ pasturestack stacks ls\n\t$ pasturestack --env 1a5 stacks ls\n",
ArgsUsage: "None",
Action: stackLs,
Flags: stackLsFlags,
},
{
Name: "create",
Usage: "Create a stacks",
Description: "\nCreates a stack in the current $PLATFORM_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ pasturestack stacks create\n\t$ pasturestack --env 1a5 stacks ls\n",
ArgsUsage: "None",
Action: stackCreate,
Flags: []cli.Flag{
cli.BoolTFlag{
Name: "start",
Usage: "Start stack on create",
},
cli.BoolFlag{
Name: "system,s",
Usage: "Create a system stack",
},
cli.BoolFlag{
Name: "empty,e",
Usage: "Create an empty stack",
},
cli.BoolFlag{
Name: "quiet,q",
Usage: "Only display IDs",
},
cli.StringFlag{
Name: "docker-compose,f",
Usage: "Docker Compose file",
Value: "docker-compose.yml",
},
cli.StringFlag{
Name: "rancher-compose,r",
Usage: "Compatibility Compose settings file",
Value: "rancher-compose.yml",
},
//cli.StringFlag{
// Name: "answers,a",
// Usage: "Answers files",
// Value: "answers",
//},
},
},
},
}
}
type StackData struct {
ID string
Catalog string
Stack client.Stack
State string
ServiceCount int
Upgrades string
}
func stackLs(ctx *cli.Context) error {
c, err := GetClient(ctx)
if err != nil {
return err
}
collection, err := c.Stack.List(defaultListOpts(ctx))
if err != nil {
return err
}
collectiondata := collection.Data
for {
collection, _ = collection.Next()
if collection == nil {
break
}
collectiondata = append(collectiondata, collection.Data...)
if !collection.Pagination.Partial {
break
}
}
operator, err := NewCatalogOperator(ctx)
if err != nil {
return err
}
writer := NewTableWriter([][]string{
{"ID", "ID"},
{"NAME", "Stack.Name"},
{"STATE", "State"},
{"CATALOG", "Catalog"},
{"SERVICES", "ServiceCount"},
{"SYSTEM", "Stack.System"},
{"DETAIL", "Stack.TransitioningMessage"},
{"AVAILABLE UPGRADES", "Upgrades"},
}, ctx)
defer writer.Close()
for _, item := range collectiondata {
combined := item.HealthState
if item.State != "active" || combined == "" {
combined = item.State
}
var upgrades []string
if item.ExternalId != "" {
upgrades = operator.GetTemplateVersionUpgradesByID(item.ExternalId)
}
writer.Write(&StackData{
ID: item.Id,
Stack: item,
State: combined,
Catalog: item.ExternalId,
ServiceCount: len(item.ServiceIds),
Upgrades: strings.Join(upgrades, ","),
})
}
return writer.Err()
}
func getFile(name string) (string, error) {
if name == "" {
return "", nil
}
bytes, err := os.ReadFile(name)
if os.IsNotExist(err) {
return "", nil
}
return string(bytes), err
}
func stackCreate(ctx *cli.Context) error {
c, err := GetClient(ctx)
names := []string{RandomName()}
if len(ctx.Args()) > 0 {
names = ctx.Args()
}
w, err := NewWaiter(ctx)
if err != nil {
return err
}
var lastErr error
for _, name := range names {
stack := &client.Stack{
Name: name,
System: ctx.Bool("system"),
StartOnCreate: ctx.Bool("start"),
}
if !ctx.Bool("empty") {
var err error
stack.DockerCompose, err = getFile(ctx.String("docker-compose"))
if err != nil {
return err
}
if stack.DockerCompose == "" {
return errors.New("docker-compose.yml files is required")
}
stack.RancherCompose, err = getFile(ctx.String("rancher-compose"))
if err != nil {
return fmt.Errorf("reading %s: %w", ctx.String("rancher-compose"), err)
}
//stack.Answers, err = parseAnswers(ctx)
//if err != nil {
//return errors.Wrap(err, "reading answers")
//}
}
stack, err = c.Stack.Create(stack)
if err != nil {
lastErr = err
}
w.Add(stack.Id)
}
if lastErr != nil {
return lastErr
}
return w.Wait()
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.