detached dfe4d56

Fix config.yml not at root level in container

commit
dfe4d5649eb2744fa73aaa8950df3e2837023253
author
bnema · · 2023-11-03 09:42 UTC
parent
7882325
signature
unsigned
3 files · +16 -23
M .gitignore +2 -1
@@ -11,4 +11,5 @@ main
1111 gordon
1212 dist/
1313 data/
14-setup.sh⏎̸
14+setup.sh
15+.iscontainer⏎̸
@@ -11,4 +11,5 @@ main
11 gordon11 gordon
12 dist/12 dist/
13 data/13 data/
14-setup.sh⏎̸14+setup.sh
15+.iscontainer⏎̸
M cmd/cli/main.go +0 -9
@@ -8,7 +8,6 @@ import (
88 "github.com/bnema/gordon/internal/cli/cmd"
99 "github.com/bnema/gordon/internal/common"
1010 "github.com/bnema/gordon/internal/server"
11- "github.com/bnema/gordon/pkg/docker"
1211 "github.com/spf13/cobra"
1312 )
1413
@@ -45,13 +44,5 @@ func main() {
4544 // Set the BuildVersion
4645 s.Config.Build.BuildVersion = build
4746
48- inContainer, err := docker.IsRunningInContainer()
49- if err != nil {
50- fmt.Printf("Error checking if running in a container: %s\n", err)
51- } else if inContainer {
52- fmt.Println("Running inside a container.")
53- } else {
54- fmt.Println("Not running inside a container.")
55- }
5647 Execute(a, s)
5748 }
@@ -8,7 +8,6 @@ import (
8 "github.com/bnema/gordon/internal/cli/cmd"8 "github.com/bnema/gordon/internal/cli/cmd"
9 "github.com/bnema/gordon/internal/common"9 "github.com/bnema/gordon/internal/common"
10 "github.com/bnema/gordon/internal/server"10 "github.com/bnema/gordon/internal/server"
11- "github.com/bnema/gordon/pkg/docker"
12 "github.com/spf13/cobra"11 "github.com/spf13/cobra"
13 )12 )
14 13
@@ -45,13 +44,5 @@ func main() {
45 // Set the BuildVersion44 // Set the BuildVersion
46 s.Config.Build.BuildVersion = build45 s.Config.Build.BuildVersion = build
47 46
48- inContainer, err := docker.IsRunningInContainer()
49- if err != nil {
50- fmt.Printf("Error checking if running in a container: %s\n", err)
51- } else if inContainer {
52- fmt.Println("Running inside a container.")
53- } else {
54- fmt.Println("Not running inside a container.")
55- }
56 Execute(a, s)47 Execute(a, s)
57 }48 }
M internal/common/initconfig.go +14 -13
@@ -5,10 +5,10 @@ import (
55 "fmt"
66 "io/fs"
77 "os"
8- "os/user"
98 "path/filepath"
109 "runtime"
1110
11+ "github.com/bnema/gordon/pkg/docker"
1212 "github.com/bnema/gordon/pkg/parser"
1313 )
1414
@@ -54,27 +54,28 @@ var (
5454 podmansock = "/run/user/1000/podman/podman.sock"
5555 )
5656
57-func isMaybeRunningInDocker() bool { // Thanks Pocketbase
58- _, err := os.Stat("/.dockerenv")
59- return err == nil
60-}
61-
6257 func getConfigDir() (string, error) {
63- usr, err := user.Current()
64- if err != nil {
65- return "", fmt.Errorf("error getting user's home directory: %w", err)
58+ if inContainer, err := docker.IsRunningInContainer(); err != nil {
59+ return "", fmt.Errorf("error checking if running in a container: %w", err)
60+ } else if inContainer {
61+ // Return the path for configuration inside the container
62+ return "/.config/Gordon", nil
6663 }
6764
68- if isMaybeRunningInDocker() {
69- return ".", nil // The directory where the binary is located
65+ // For non-container environments, determine the user's home directory
66+ homeDir, err := os.UserHomeDir()
67+ if err != nil {
68+ return "", fmt.Errorf("error getting user's home directory: %w", err)
7069 }
7170
71+ // Determine the configuration directory based on the operating system
7272 var configDir string
7373 if runtime.GOOS == "windows" {
74- configDir = filepath.Join(usr.HomeDir, "AppData", "Roaming", "Gordon")
74+ configDir = filepath.Join(homeDir, "AppData", "Roaming", "Gordon")
7575 } else {
76- configDir = filepath.Join(usr.HomeDir, ".config", "Gordon")
76+ configDir = filepath.Join(homeDir, ".config", "Gordon")
7777 }
78+
7879 return configDir, nil
7980 }
8081
@@ -5,10 +5,10 @@ import (
5 "fmt"5 "fmt"
6 "io/fs"6 "io/fs"
7 "os"7 "os"
8- "os/user"
9 "path/filepath"8 "path/filepath"
10 "runtime"9 "runtime"
11 10
11+ "github.com/bnema/gordon/pkg/docker"
12 "github.com/bnema/gordon/pkg/parser"12 "github.com/bnema/gordon/pkg/parser"
13 )13 )
14 14
@@ -54,27 +54,28 @@ var (
54 podmansock = "/run/user/1000/podman/podman.sock"54 podmansock = "/run/user/1000/podman/podman.sock"
55 )55 )
56 56
57-func isMaybeRunningInDocker() bool { // Thanks Pocketbase
58- _, err := os.Stat("/.dockerenv")
59- return err == nil
60-}
61-
62 func getConfigDir() (string, error) {57 func getConfigDir() (string, error) {
63- usr, err := user.Current()58+ if inContainer, err := docker.IsRunningInContainer(); err != nil {
64- if err != nil {59+ return "", fmt.Errorf("error checking if running in a container: %w", err)
65- return "", fmt.Errorf("error getting user's home directory: %w", err)60+ } else if inContainer {
61+ // Return the path for configuration inside the container
62+ return "/.config/Gordon", nil
66 }63 }
67 64
68- if isMaybeRunningInDocker() {65+ // For non-container environments, determine the user's home directory
69- return ".", nil // The directory where the binary is located66+ homeDir, err := os.UserHomeDir()
67+ if err != nil {
68+ return "", fmt.Errorf("error getting user's home directory: %w", err)
70 }69 }
71 70
71+ // Determine the configuration directory based on the operating system
72 var configDir string72 var configDir string
73 if runtime.GOOS == "windows" {73 if runtime.GOOS == "windows" {
74- configDir = filepath.Join(usr.HomeDir, "AppData", "Roaming", "Gordon")74+ configDir = filepath.Join(homeDir, "AppData", "Roaming", "Gordon")
75 } else {75 } else {
76- configDir = filepath.Join(usr.HomeDir, ".config", "Gordon")76+ configDir = filepath.Join(homeDir, ".config", "Gordon")
77 }77 }
78+
78 return configDir, nil79 return configDir, nil
79 }80 }
80 81

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close