-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from SpatiumPortae/develop
Develop -> Master
- Loading branch information
Showing
38 changed files
with
1,419 additions
and
916 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
# Mutli-stage build. | ||
# Multi-stage build. | ||
FROM golang:1.18-alpine3.14 as build-stage | ||
|
||
# Copy source code and build binary. | ||
ARG version | ||
# Copy source code and build binary | ||
RUN mkdir /usr/app | ||
COPY . /usr/app | ||
WORKDIR /usr/app | ||
RUN CGO=0 go build -ldflags="-s -X main.version=${version}" -o app ./cmd/portal/ | ||
RUN CGO=0 go build -ldflags="-s -X main.version=${version}" -o portal ./cmd/portal/ | ||
|
||
# Copy binary from build container and build image. | ||
FROM alpine:3.14 | ||
RUN mkdir /usr/app | ||
RUN mkdir /usr/app | ||
WORKDIR /usr/app | ||
COPY --from=build-stage /usr/app/app . | ||
COPY --from=build-stage /usr/app/portal . | ||
|
||
ENTRYPOINT [ "./app", "serve","-p", "8080" ] | ||
ENTRYPOINT [ "./portal", "serve"] |
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,92 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/SpatiumPortae/portal/cmd/portal/config" | ||
"github.com/alecthomas/chroma/quick" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Config() *cobra.Command { | ||
|
||
pathCmd := &cobra.Command{ | ||
Use: "path", | ||
Short: "Output the path of the config file", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(viper.ConfigFileUsed()) | ||
}, | ||
} | ||
|
||
viewCmd := &cobra.Command{ | ||
Use: "view", | ||
Short: "View the configured options", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
configPath := viper.ConfigFileUsed() | ||
config, err := os.ReadFile(configPath) | ||
if err != nil { | ||
return fmt.Errorf("config file (%s) could not be read: %w", configPath, err) | ||
} | ||
if err := quick.Highlight(os.Stdout, string(config), "yaml", "terminal256", "onedark"); err != nil { | ||
// Failed to highlight output, output un-highlighted config file contents. | ||
fmt.Println(string(config)) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
editCmd := &cobra.Command{ | ||
Use: "edit", | ||
Short: "Edit the configuration file", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
configPath := viper.ConfigFileUsed() | ||
// Strip arguments from editor variable -- allows exec.Command to lookup the editor executable correctly. | ||
editor, _, _ := strings.Cut(os.Getenv("EDITOR"), " ") | ||
if len(editor) == 0 { | ||
//lint:ignore ST1005 error string is command output | ||
return fmt.Errorf( | ||
"Could not find default editor (is the $EDITOR variable set?)\nOptionally you can open the file (%s) manually", configPath, | ||
) | ||
} | ||
|
||
editorCmd := exec.Command(editor, configPath) | ||
editorCmd.Stdin = os.Stdin | ||
editorCmd.Stdout = os.Stdout | ||
editorCmd.Stderr = os.Stderr | ||
if err := editorCmd.Run(); err != nil { | ||
return fmt.Errorf("failed to open file (%s) in editor (%s): %w", configPath, editor, err) | ||
} | ||
return nil | ||
}, | ||
} | ||
resetCmd := &cobra.Command{ | ||
Use: "reset", | ||
Short: "Reset to the default configuration", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
configPath := viper.ConfigFileUsed() | ||
err := os.WriteFile(configPath, config.GetDefault().Yaml(), 0) | ||
if err != nil { | ||
return fmt.Errorf("config file (%s) could not be read/written to: %w", configPath, err) | ||
} | ||
return nil | ||
}, | ||
} | ||
configCmd := &cobra.Command{ | ||
Use: "config", | ||
Short: "View and configure options", | ||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), | ||
ValidArgs: []string{pathCmd.Name(), viewCmd.Name(), editCmd.Name(), resetCmd.Name()}, | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
configCmd.AddCommand(pathCmd) | ||
configCmd.AddCommand(viewCmd) | ||
configCmd.AddCommand(editCmd) | ||
configCmd.AddCommand(resetCmd) | ||
|
||
return configCmd | ||
} |
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,33 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
relayFlagDesc = `Address of relay server. Accepted formats: | ||
- 127.0.0.1:8080 | ||
- [::1]:8080 | ||
- somedomain.com/relay | ||
- ... | ||
` | ||
tuiStyleFlagDesc = "Style of the tui (rich|raw)" | ||
) | ||
|
||
func setupLoggingFromViper(cmd string) (*os.File, error) { | ||
if viper.GetBool("verbose") { | ||
f, err := tea.LogToFile(fmt.Sprintf(".portal-%s.log", cmd), fmt.Sprintf("portal-%s: \n", cmd)) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not log to the provided file: %w", err) | ||
} | ||
return f, nil | ||
} | ||
log.SetOutput(io.Discard) | ||
return nil, nil | ||
} |
Oops, something went wrong.