-
Notifications
You must be signed in to change notification settings - Fork 248
[bugfix, cleanup] Finish moving plugin services to process compose #1150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,11 @@ | ||
// Copyright 2023 Jetpack Technologies Inc and contributors. All rights reserved. | ||
// Use of this source code is governed by the license in the LICENSE file. | ||
|
||
//lint:file-ignore U1000 Ignore unused function temporarily for debugging | ||
package services | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/a8m/envsubst" | ||
"github.com/fatih/color" | ||
"github.com/pkg/errors" | ||
|
||
"go.jetpack.io/devbox/internal/envir" | ||
) | ||
|
||
type Services map[string]Service | ||
type Services map[string]Service // name -> Service | ||
|
||
type Service struct { | ||
Name string `json:"name"` | ||
Env map[string]string `json:"-"` | ||
RawPort string `json:"port"` | ||
Start string `json:"start"` | ||
Stop string `json:"stop"` | ||
Name string | ||
ProcessComposePath string | ||
} | ||
|
||
// 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. | ||
|
||
type serviceAction int | ||
|
||
const ( | ||
startService serviceAction = iota | ||
stopService | ||
) | ||
|
||
func printProxyURL(w io.Writer, services Services) error { // TODO: remove it? | ||
if !envir.IsDevboxCloud() { | ||
return nil | ||
} | ||
|
||
hostname, err := os.Hostname() | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
||
printGeneric := false | ||
for _, service := range services { | ||
if port, _ := service.Port(); port != "" { | ||
color.New(color.FgHiGreen).Fprintf( | ||
w, | ||
"To access %s on this vm use: %s-%s.svc.devbox.sh\n", | ||
service.Name, | ||
hostname, | ||
port, | ||
) | ||
} else { | ||
printGeneric = true | ||
} | ||
} | ||
|
||
if printGeneric { | ||
color.New(color.FgHiGreen).Fprintf( | ||
w, | ||
"To access other services on this vm use: %s-<port>.svc.devbox.sh\n", | ||
hostname, | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Service) Port() (string, error) { | ||
if s.RawPort == "" { | ||
return "", nil | ||
} | ||
return envsubst.String(s.RawPort) | ||
} | ||
|
||
func (s *Service) ProcessComposeYaml() (string, bool) { | ||
return s.ProcessComposePath, true | ||
} | ||
|
||
func (s *Service) StartName() string { | ||
return fmt.Sprintf("%s-service-start", s.Name) | ||
} | ||
|
||
func (s *Service) StopName() string { | ||
return fmt.Sprintf("%s-service-stop", s.Name) | ||
} | ||
|
||
func (s *Services) UnmarshalJSON(b []byte) error { | ||
var m map[string]Service | ||
if err := json.Unmarshal(b, &m); err != nil { | ||
return err | ||
} | ||
*s = make(Services) | ||
for name, svc := range m { | ||
svc.Name = name | ||
(*s)[name] = svc | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callsite to this was accidentally removed in https://github.com/jetpack-io/devbox/pull/836/files (I looked it up because I was surprised this was unused)
The purpose of this endpoint is to print the URL the user can use to proxy to their devbox.sh service. I think it's an important part of making devbox cloud usable.
That said, currently only a single plugin declares a port, so we may want to just show the generic message and figure out how to show the port later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll address this in a separate PR.