|
1 | 1 | // Copyright 2023 Jetpack Technologies Inc and contributors. All rights reserved.
|
2 | 2 | // Use of this source code is governed by the license in the LICENSE file.
|
3 | 3 |
|
4 |
| -//lint:file-ignore U1000 Ignore unused function temporarily for debugging |
5 | 4 | package services
|
6 | 5 |
|
7 |
| -import ( |
8 |
| - "encoding/json" |
9 |
| - "fmt" |
10 |
| - "io" |
11 |
| - "os" |
12 |
| - |
13 |
| - "github.com/a8m/envsubst" |
14 |
| - "github.com/fatih/color" |
15 |
| - "github.com/pkg/errors" |
16 |
| - |
17 |
| - "go.jetpack.io/devbox/internal/envir" |
18 |
| -) |
19 |
| - |
20 |
| -type Services map[string]Service |
| 6 | +type Services map[string]Service // name -> Service |
21 | 7 |
|
22 | 8 | type Service struct {
|
23 |
| - Name string `json:"name"` |
24 |
| - Env map[string]string `json:"-"` |
25 |
| - RawPort string `json:"port"` |
26 |
| - Start string `json:"start"` |
27 |
| - Stop string `json:"stop"` |
| 9 | + Name string |
28 | 10 | ProcessComposePath string
|
29 | 11 | }
|
30 |
| - |
31 |
| -// TODO: (john) Since moving to process-compose, our services no longer use the old `toggleServices` function. We'll need to clean a lot of this up in a later PR. |
32 |
| - |
33 |
| -type serviceAction int |
34 |
| - |
35 |
| -const ( |
36 |
| - startService serviceAction = iota |
37 |
| - stopService |
38 |
| -) |
39 |
| - |
40 |
| -func printProxyURL(w io.Writer, services Services) error { // TODO: remove it? |
41 |
| - if !envir.IsDevboxCloud() { |
42 |
| - return nil |
43 |
| - } |
44 |
| - |
45 |
| - hostname, err := os.Hostname() |
46 |
| - if err != nil { |
47 |
| - return errors.WithStack(err) |
48 |
| - } |
49 |
| - |
50 |
| - printGeneric := false |
51 |
| - for _, service := range services { |
52 |
| - if port, _ := service.Port(); port != "" { |
53 |
| - color.New(color.FgHiGreen).Fprintf( |
54 |
| - w, |
55 |
| - "To access %s on this vm use: %s-%s.svc.devbox.sh\n", |
56 |
| - service.Name, |
57 |
| - hostname, |
58 |
| - port, |
59 |
| - ) |
60 |
| - } else { |
61 |
| - printGeneric = true |
62 |
| - } |
63 |
| - } |
64 |
| - |
65 |
| - if printGeneric { |
66 |
| - color.New(color.FgHiGreen).Fprintf( |
67 |
| - w, |
68 |
| - "To access other services on this vm use: %s-<port>.svc.devbox.sh\n", |
69 |
| - hostname, |
70 |
| - ) |
71 |
| - } |
72 |
| - return nil |
73 |
| -} |
74 |
| - |
75 |
| -func (s *Service) Port() (string, error) { |
76 |
| - if s.RawPort == "" { |
77 |
| - return "", nil |
78 |
| - } |
79 |
| - return envsubst.String(s.RawPort) |
80 |
| -} |
81 |
| - |
82 |
| -func (s *Service) ProcessComposeYaml() (string, bool) { |
83 |
| - return s.ProcessComposePath, true |
84 |
| -} |
85 |
| - |
86 |
| -func (s *Service) StartName() string { |
87 |
| - return fmt.Sprintf("%s-service-start", s.Name) |
88 |
| -} |
89 |
| - |
90 |
| -func (s *Service) StopName() string { |
91 |
| - return fmt.Sprintf("%s-service-stop", s.Name) |
92 |
| -} |
93 |
| - |
94 |
| -func (s *Services) UnmarshalJSON(b []byte) error { |
95 |
| - var m map[string]Service |
96 |
| - if err := json.Unmarshal(b, &m); err != nil { |
97 |
| - return err |
98 |
| - } |
99 |
| - *s = make(Services) |
100 |
| - for name, svc := range m { |
101 |
| - svc.Name = name |
102 |
| - (*s)[name] = svc |
103 |
| - } |
104 |
| - return nil |
105 |
| -} |
0 commit comments