-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#228 was reverted due to deployment to Fly requires `bash`. The bash script is replaced with a Go binary (`uptermd-fly`). Dockerfile.upterm is adjusted to accomondate for Fly deployment and self-hosting with different build targets.
- Loading branch information
1 parent
1b54c1d
commit 540df7e
Showing
10 changed files
with
226 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/owenthereal/upterm/cmd/uptermd/command" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
logger := log.New() | ||
|
||
flyAppName := os.Getenv("FLY_APP_NAME") | ||
if flyAppName == "" { | ||
logger.Fatal("FLY_APP_NAME is not set") | ||
} | ||
|
||
flyMachineID := os.Getenv("FLY_MACHINE_ID") | ||
if flyMachineID == "" { | ||
logger.Fatal("FLY_MACHINE_ID is not set") | ||
} | ||
|
||
os.Setenv("UPTERMD_NODE_ADDR", fmt.Sprintf("%s.vm.%s.internal:2222", flyMachineID, flyAppName)) | ||
os.Setenv("UPTERMD_SSH_ADDR", "0.0.0.0:2222") | ||
os.Setenv("UPTERMD_WS_ADDR", "0.0.0.0:8080") | ||
os.Setenv("UPTERMD_HOSTNAME", "uptermd.upterm.dev") | ||
|
||
if err := command.Root(logger).Execute(); err != nil { | ||
logger.Fatal(err) | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/owenthereal/upterm/server" | ||
"github.com/owenthereal/upterm/utils" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Root(logger log.FieldLogger) *cobra.Command { | ||
rootCmd := &rootCmd{} | ||
cmd := &cobra.Command{ | ||
Use: "uptermd", | ||
Short: "Upterm Daemon", | ||
RunE: rootCmd.Run, | ||
} | ||
|
||
cmd.PersistentFlags().String("config", "", "server config") | ||
|
||
cmd.PersistentFlags().StringP("ssh-addr", "", utils.DefaultLocalhost("2222"), "ssh server address") | ||
cmd.PersistentFlags().StringP("ws-addr", "", "", "websocket server address") | ||
cmd.PersistentFlags().StringP("node-addr", "", "", "node address") | ||
cmd.PersistentFlags().StringSliceP("private-key", "", nil, "server private key") | ||
cmd.PersistentFlags().StringSliceP("hostname", "", nil, "server hostname for public-key authentication certificate principals. If empty, public-key authentication is used instead.") | ||
|
||
cmd.PersistentFlags().StringP("network", "", "mem", "network provider") | ||
cmd.PersistentFlags().StringSliceP("network-opt", "", nil, "network provider option") | ||
|
||
cmd.PersistentFlags().StringP("metric-addr", "", "", "metric server address") | ||
cmd.PersistentFlags().BoolP("debug", "", os.Getenv("DEBUG") != "", "debug") | ||
|
||
return cmd | ||
} | ||
|
||
type rootCmd struct { | ||
} | ||
|
||
func (cmd *rootCmd) Run(c *cobra.Command, args []string) error { | ||
var opt server.Opt | ||
if err := unmarshalFlags(c, &opt); err != nil { | ||
return err | ||
} | ||
|
||
return server.Start(opt) | ||
} | ||
|
||
func unmarshalFlags(cmd *cobra.Command, opts interface{}) error { | ||
v := viper.New() | ||
|
||
cmd.Flags().VisitAll(func(flag *pflag.Flag) { | ||
flagName := flag.Name | ||
if flagName != "config" && flagName != "help" { | ||
if err := v.BindPFlag(flagName, flag); err != nil { | ||
panic(fmt.Errorf("error binding flag '%s': %w", flagName, err).Error()) | ||
} | ||
} | ||
}) | ||
|
||
v.AutomaticEnv() | ||
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) | ||
v.SetEnvPrefix("UPTERMD") | ||
|
||
cfgFile, err := cmd.Flags().GetString("config") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, err := os.Stat(cfgFile); err == nil { | ||
v.SetConfigFile(cfgFile) | ||
} | ||
|
||
if err := v.ReadInConfig(); err != nil { | ||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok { | ||
return fmt.Errorf("error loading config file %s: %w", cfgFile, err) | ||
} | ||
} | ||
|
||
return v.Unmarshal(opts) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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.