Skip to content

Commit 420c355

Browse files
committed
feat: refactor architecture for less disk usage when daemon service is active
1 parent 77d2416 commit 420c355

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1514
-1083
lines changed

.debug.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DSC="This is development environment configurations to prevent conflict with production environment configurations in case of developing the sandal under sandal container."
1+
DSC="This is development environment configurations to prevent conflict with production environment configurations in case of developing the sandal under sandal container"
22
SANDAL_HOST_NET="172.19.0.1/24;fd34:0135:0127::1/64"
33
SANDAL_LOG_LEVEL=debug
44
SANDAL_LIB_DIR="/tmp/sandal/lib"

main.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ package main
22

33
import (
44
"github.com/ahmetozer/sandal/pkg/cmd"
5-
"github.com/ahmetozer/sandal/pkg/container"
5+
"github.com/ahmetozer/sandal/pkg/container/cruntime"
66
)
77

8-
func init() {
9-
cmd.SetLogLoggerLevel()
10-
}
11-
128
func main() {
139

14-
if container.IsChild() {
15-
container.Exec()
10+
if cruntime.IsChild() {
11+
cruntime.ContainerProc()
1612
} else {
1713
cmd.Main()
1814
}

pkg/cmd/log.go pkg/cmd/_init.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import (
66
"strings"
77
)
88

9-
func SetLogLoggerLevel() {
9+
func init() {
10+
setLogLoggerLevel()
11+
}
12+
13+
func setLogLoggerLevel() {
1014

1115
switch strings.ToLower(os.Getenv("SANDAL_LOG_LEVEL")) {
1216
case "info":

pkg/cmd/clear.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"fmt"
66
"log"
77

8-
"github.com/ahmetozer/sandal/pkg/config"
9-
"github.com/ahmetozer/sandal/pkg/container"
8+
"github.com/ahmetozer/sandal/pkg/container/cruntime"
9+
"github.com/ahmetozer/sandal/pkg/controller"
1010
)
1111

12-
func clear(args []string) error {
12+
func Clear(args []string) error {
1313

1414
f := flag.NewFlagSet("exec", flag.ExitOnError)
1515

@@ -30,18 +30,18 @@ func clear(args []string) error {
3030
return nil
3131
}
3232

33-
conts, _ := config.Containers()
33+
conts, _ := controller.Containers()
3434
for _, c := range conts {
3535
if !deleteAll {
3636
if !c.Remove {
3737
continue
3838
}
3939
}
40-
if container.IsRunning(&c) {
41-
log.Printf("container %s is running, rm=%v", c.Name, c.Remove)
40+
if cruntime.IsRunning(c) {
41+
log.Printf("container %s is running, rm=%v", c.Name, c.Remove)
4242
continue
4343
}
44-
deRunContainer(&c)
44+
cruntime.DeRunContainer(c)
4545
}
4646
return nil
4747
}

pkg/cmd/cmd.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
package cmd
22

33
import (
4+
"flag"
45
"fmt"
56
"os"
67
"strings"
78

8-
"github.com/ahmetozer/sandal/pkg/config"
9+
"github.com/ahmetozer/sandal/pkg/controller"
910
)
1011

11-
func cmd(args []string) error {
12-
if len(args) < 1 {
12+
func Cmd(args []string) error {
13+
14+
f := flag.NewFlagSet("", flag.ExitOnError)
15+
16+
all := f.Bool("all", false, "print all")
17+
if len(args) < 1 && !*all {
1318
return fmt.Errorf("no container name is provided")
1419
}
15-
conts, err := config.Containers()
20+
21+
f.Parse(args)
22+
23+
conts, err := controller.Containers()
1624
if err != nil {
1725
return err
1826
}
1927
for _, c := range conts {
20-
if c.Name == args[0] {
28+
if c.Name == args[0] || *all {
2129
c.HostArgs[0] = os.Args[0] // sync with current command
2230
for i := range c.HostArgs {
2331
k := strings.Split(c.HostArgs[i], "=")

pkg/cmd/convert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010
)
1111

12-
func convert(args []string) error {
12+
func Convert(args []string) error {
1313

1414
thisFlags, args := SplitFlagsArgs(args)
1515

0 commit comments

Comments
 (0)