Compare commits
2 Commits
aafe60ee35
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da6a846550 | ||
|
|
ce6ab8ab5f |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,3 +6,6 @@ dist
|
|||||||
.idea
|
.idea
|
||||||
forge
|
forge
|
||||||
dev_*.sh
|
dev_*.sh
|
||||||
|
*.tar
|
||||||
|
*.tgz
|
||||||
|
*.tar.gz
|
||||||
5
go.mod
5
go.mod
@@ -3,14 +3,13 @@ module yizhisec.com/hsv2/forge
|
|||||||
go 1.25.2
|
go 1.25.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.loveuer.com/yizhisec/pkg3 v0.0.1
|
github.com/fatih/color v1.18.0
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
github.com/samber/lo v1.52.0
|
github.com/samber/lo v1.52.0
|
||||||
github.com/spf13/cobra v1.10.1
|
github.com/spf13/cobra v1.10.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fatih/color v1.18.0 // indirect
|
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -1,5 +1,3 @@
|
|||||||
gitea.loveuer.com/yizhisec/pkg3 v0.0.1 h1:bcT58K6W7TQ5u7Lt7B5JxrVbU/riXwcrshd2lu+Q22c=
|
|
||||||
gitea.loveuer.com/yizhisec/pkg3 v0.0.1/go.mod h1:Ws/tNONjDC4BLdOXAe+wPD6xk3H7TIXvh2de8qKqQpc=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func Check() *cobra.Command {
|
|||||||
|
|
||||||
_cmd.Flags().StringVar(&workdir, "workdir", "/root/hs-installation", "Working directory")
|
_cmd.Flags().StringVar(&workdir, "workdir", "/root/hs-installation", "Working directory")
|
||||||
_cmd.Flags().StringVar(&target, "target", "self", "Target")
|
_cmd.Flags().StringVar(&target, "target", "self", "Target")
|
||||||
_cmd.Flags().BoolVar(&ignoreDisk, "ignore-check-disk", false, "ignore disk requirement check result")
|
_cmd.Flags().BoolVar(&ignoreDisk, "ignore-kheck-disk", false, "ignore disk requirement check result")
|
||||||
_cmd.Flags().BoolVar(&ignoreMemory, "ignore-check-memory", false, "ignore memory requirement check result")
|
_cmd.Flags().BoolVar(&ignoreMemory, "ignore-check-memory", false, "ignore memory requirement check result")
|
||||||
_cmd.Flags().BoolVar(&ignoreCPU, "ignore-check-cpu", false, "ignore cpu requirement check result")
|
_cmd.Flags().BoolVar(&ignoreCPU, "ignore-check-cpu", false, "ignore cpu requirement check result")
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"yizhisec.com/hsv2/forge/internal/cmd/makecmd"
|
"yizhisec.com/hsv2/forge/internal/cmd/makecmd"
|
||||||
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeCmd() *cobra.Command {
|
func makeCmd() *cobra.Command {
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
tc "yizhisec.com/hsv2/forge/pkg/tool/client"
|
tc "yizhisec.com/hsv2/forge/pkg/tool/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package makecmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
||||||
@@ -24,5 +26,84 @@ func Minio() *cobra.Command {
|
|||||||
|
|
||||||
_cmd.Flags().IntVar(&storage, "storage-size", 100, "Storage size(GB)")
|
_cmd.Flags().IntVar(&storage, "storage-size", 100, "Storage size(GB)")
|
||||||
|
|
||||||
|
_cmd.AddCommand(minioBase())
|
||||||
|
|
||||||
|
return _cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func minioBase() *cobra.Command {
|
||||||
|
var (
|
||||||
|
push bool
|
||||||
|
)
|
||||||
|
|
||||||
|
_cmd := &cobra.Command{
|
||||||
|
Use: "base",
|
||||||
|
Short: "Make Minio Image Rely(minio initer)",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
const (
|
||||||
|
DOCKERFILE = `FROM %s
|
||||||
|
COPY mc /usr/local/bin/mc
|
||||||
|
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories && \
|
||||||
|
apk update && \
|
||||||
|
apk add curl wget tzdata && chmod +x /usr/local/bin/mc && \
|
||||||
|
mkdir -p /data && \
|
||||||
|
wget https://artifactory.yizhisec.com/artifactory/filestore/hsv2/db/ipv4.ipdb -O /data/ipv4.ipdb
|
||||||
|
`
|
||||||
|
)
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
mk = maker.NewMaker(opt.Cfg.Make.Dir)
|
||||||
|
tmpDir = filepath.Join(os.TempDir(), "minio-base")
|
||||||
|
mcFile = filepath.Join(tmpDir, "mc")
|
||||||
|
dockerfile = filepath.Join(tmpDir, "Dockerfile")
|
||||||
|
)
|
||||||
|
|
||||||
|
if err = os.MkdirAll(tmpDir, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
if err = mk.RunCommand(cmd.Context(),
|
||||||
|
tmpDir,
|
||||||
|
fmt.Sprintf("docker run -d --name minio-base %s server /data", opt.IMAGE_MINIO),
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer mk.RunCommand(cmd.Context(), tmpDir, "docker rm -f minio-base")
|
||||||
|
|
||||||
|
if err = mk.RunCommand(cmd.Context(),
|
||||||
|
tmpDir,
|
||||||
|
fmt.Sprintf("docker cp minio-base:/usr/bin/mc %s", mcFile),
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = os.WriteFile(dockerfile, []byte(fmt.Sprintf(DOCKERFILE, opt.IMAGE_ALPINE)), 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = mk.RunCommand(cmd.Context(),
|
||||||
|
tmpDir,
|
||||||
|
fmt.Sprintf("docker build --network host -t %s -f %s %s", opt.IMAGE_MINIO_BASE, dockerfile, tmpDir),
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if push {
|
||||||
|
if err = mk.RunCommand(cmd.Context(),
|
||||||
|
tmpDir,
|
||||||
|
fmt.Sprintf("docker push %s", opt.IMAGE_MINIO_BASE),
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_cmd.Flags().BoolVar(&push, "push", false, "Push image to registry")
|
||||||
|
|
||||||
return _cmd
|
return _cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
)
|
)
|
||||||
@@ -12,14 +11,6 @@ var rootCmd = &cobra.Command{
|
|||||||
Use: "forge",
|
Use: "forge",
|
||||||
Short: "Forge is a tool for building and installing hsv2",
|
Short: "Forge is a tool for building and installing hsv2",
|
||||||
Long: `A tool for managing build and installation workflows for hsv2.`,
|
Long: `A tool for managing build and installation workflows for hsv2.`,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
if opt.Cfg.Debug {
|
|
||||||
logger.SetLogLevel(logger.LogLevelDebug)
|
|
||||||
logger.Warn("running in debug mode")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute(ctx context.Context) error {
|
func Execute(ctx context.Context) error {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/syscheck"
|
"yizhisec.com/hsv2/forge/pkg/syscheck"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type installer struct {
|
type installer struct {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type K0sOpt func(*k0sOpt)
|
type K0sOpt func(*k0sOpt)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i *installer) Prepare(ctx context.Context) error {
|
func (i *installer) Prepare(ctx context.Context) error {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/pkg/archiver"
|
"yizhisec.com/hsv2/forge/pkg/archiver"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/pkg/archiver"
|
"yizhisec.com/hsv2/forge/pkg/archiver"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *maker) RunCommand(ctx context.Context, dir string, _cmds ...string) error {
|
func (m *maker) RunCommand(ctx context.Context, dir string, _cmds ...string) error {
|
||||||
@@ -12,6 +14,8 @@ func (m *maker) RunCommand(ctx context.Context, dir string, _cmds ...string) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Debug("maker.RunCommand: dir = %s, cmds = %v", dir, _cmds)
|
||||||
|
|
||||||
for _, cmdStr := range _cmds {
|
for _, cmdStr := range _cmds {
|
||||||
cmd := exec.CommandContext(ctx, "sh", "-c", cmdStr)
|
cmd := exec.CommandContext(ctx, "sh", "-c", cmdStr)
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||||
"yizhisec.com/hsv2/forge/pkg/extractor"
|
"yizhisec.com/hsv2/forge/pkg/extractor"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/tool/random"
|
"yizhisec.com/hsv2/forge/pkg/tool/random"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
"yizhisec.com/hsv2/forge/pkg/archiver"
|
"yizhisec.com/hsv2/forge/pkg/archiver"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/pkg/archiver"
|
"yizhisec.com/hsv2/forge/pkg/archiver"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package maker
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestImage(t *testing.T) {
|
func TestImage(t *testing.T) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
@@ -14,20 +15,20 @@ import (
|
|||||||
// todo, remake minio-init image
|
// todo, remake minio-init image
|
||||||
func (m *maker) Minio(ctx context.Context, storage string) error {
|
func (m *maker) Minio(ctx context.Context, storage string) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
location = filepath.Join(m.workdir, "dependency", "minio")
|
workdir = filepath.Join(m.workdir, "dependency", "minio")
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.Info("☑️ maker.Minio: 开始构建 minio 依赖, workdir = %s", location)
|
logger.Info("☑️ maker.Minio: 开始构建 minio 依赖, workdir = %s", workdir)
|
||||||
|
logger.Debug("☑️ maker.Minio: 构建工作目录, workdir = %s", workdir)
|
||||||
logger.Debug("☑️ maker.Minio: 构建工作目录, workdir = %s", location)
|
_ = os.RemoveAll(workdir)
|
||||||
if err = os.MkdirAll(location, 0755); err != nil {
|
if err = os.MkdirAll(workdir, 0755); err != nil {
|
||||||
logger.Debug("❌ maker.Minio: 创建工作目录失败, workdir = %s, err = %v", location, err)
|
logger.Debug("❌ maker.Minio: 创建工作目录失败, workdir = %s, err = %v", workdir, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger.Debug("✅ maker.Minio: 创建工作目录成功, workdir = %s", location)
|
logger.Debug("✅ maker.Minio: 创建工作目录成功, workdir = %s", workdir)
|
||||||
|
|
||||||
filename := filepath.Join(location, "minio.yaml")
|
filename := filepath.Join(workdir, "minio.yaml")
|
||||||
logger.Debug("☑️ maker.Minio: 准备资源文件, filename = %s, storage = %s", filename, storage)
|
logger.Debug("☑️ maker.Minio: 准备资源文件, filename = %s, storage = %s", filename, storage)
|
||||||
bs := []byte(fmt.Sprintf(resource.YAMLMinIO, storage))
|
bs := []byte(fmt.Sprintf(resource.YAMLMinIO, storage))
|
||||||
if err = os.WriteFile(filename, bs, 0644); err != nil {
|
if err = os.WriteFile(filename, bs, 0644); err != nil {
|
||||||
@@ -38,13 +39,13 @@ func (m *maker) Minio(ctx context.Context, storage string) error {
|
|||||||
|
|
||||||
logger.Debug("☑️ maker.Minio: 开始获取所需镜像...")
|
logger.Debug("☑️ maker.Minio: 开始获取所需镜像...")
|
||||||
var images = []*model.Image{
|
var images = []*model.Image{
|
||||||
{Name: "hub.yizhisec.com/hybridscope/v3/minio-init:latest", Fallback: "", Save: "dep.minio-init.tar"},
|
{Name: opt.IMAGE_MINIO_BASE, Fallback: "", Save: "minio-init.tar"},
|
||||||
{Name: "hub.yizhisec.com/external/minio:RELEASE.2025-03-12T18-04-18Z", Fallback: "", Save: "dep.minio.tar"},
|
{Name: opt.IMAGE_MINIO, Fallback: "", Save: "minio.tar"},
|
||||||
}
|
}
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
opts := []ImageOpt{
|
opts := []ImageOpt{
|
||||||
WithImageFallback(image.Fallback),
|
WithImageFallback(image.Fallback),
|
||||||
WithImageSave(filepath.Join(location, image.Save)),
|
WithImageSave(filepath.Join(workdir, image.Save)),
|
||||||
WithImageForcePull(image.Force),
|
WithImageForcePull(image.Force),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ func (m *maker) Minio(ctx context.Context, storage string) error {
|
|||||||
}
|
}
|
||||||
logger.Debug("✅ maker.Minio: 获取所需镜像成功!!!")
|
logger.Debug("✅ maker.Minio: 获取所需镜像成功!!!")
|
||||||
|
|
||||||
logger.Info("✅ maker.Minio: 构建 minio 依赖成功, workdir = %s", location)
|
logger.Info("✅ maker.Minio: 构建 minio 依赖成功, workdir = %s", workdir)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/internal/opt"
|
"yizhisec.com/hsv2/forge/internal/opt"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/model"
|
"yizhisec.com/hsv2/forge/pkg/model"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
@@ -123,7 +123,7 @@ kubectl rollout restart deployment backup-seafile-deployment -n seafile`
|
|||||||
ServerHostname: "cloud.hybridscope.com",
|
ServerHostname: "cloud.hybridscope.com",
|
||||||
Storage: "50Gi",
|
Storage: "50Gi",
|
||||||
}
|
}
|
||||||
workdir = filepath.Join(m.workdir, "dependency", "seafile")
|
workdir = filepath.Join(m.workdir, "dependency", "seafile")
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, fn := range opts {
|
for _, fn := range opts {
|
||||||
@@ -187,7 +187,7 @@ kubectl rollout restart deployment backup-seafile-deployment -n seafile`
|
|||||||
|
|
||||||
// 7. prepare images
|
// 7. prepare images
|
||||||
logger.Debug("☑️ make.Seafile: 准备 images")
|
logger.Debug("☑️ make.Seafile: 准备 images")
|
||||||
imgDir := filepath.Join(m.workdir, "dependency", "image")
|
imgDir := filepath.Join(m.workdir, "dependency", "image")
|
||||||
if err = os.MkdirAll(imgDir, 0755); err != nil {
|
if err = os.MkdirAll(imgDir, 0755); err != nil {
|
||||||
logger.Error("❌ make.Seafile: 准备 images 目录: %s 失败, err = %v", imgDir, err)
|
logger.Error("❌ make.Seafile: 准备 images 目录: %s 失败, err = %v", imgDir, err)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
|
||||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||||
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package opt
|
package opt
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IMAGE_NGINX = "docker-mirror.yizhisec.com/library/nginx:1.29.4-alpine3.23"
|
IMAGE_NGINX = "docker-mirror.yizhisec.com/library/nginx:1.29.4-alpine3.23"
|
||||||
|
IMAGE_MINIO = "hub.yizhisec.com/external/minio:RELEASE.2025-03-12T18-04-18Z"
|
||||||
|
IMAGE_ALPINE = "docker-mirror.yizhisec.com/library/alpine:3.23.2"
|
||||||
|
IMAGE_MINIO_BASE = "hub.yizhisec.com/hsv2/base/minio-init:latest"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options defines options for downloading and extracting archives
|
// Options defines options for downloading and extracting archives
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDownloadAndExtract(t *testing.T) {
|
func TestDownloadAndExtract(t *testing.T) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options defines options for downloading files
|
// Options defines options for downloading files
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PullOption is a functional option for configuring image pull
|
// PullOption is a functional option for configuring image pull
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestPullImage_PublicImage tests pulling a public image from Docker Hub
|
// TestPullImage_PublicImage tests pulling a public image from Docker Hub
|
||||||
|
|||||||
53
pkg/logger/ctx.go
Normal file
53
pkg/logger/ctx.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
uuid2 "github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type _traceId struct{}
|
||||||
|
|
||||||
|
var TraceId = _traceId{}
|
||||||
|
|
||||||
|
func traceId(ctx context.Context) string {
|
||||||
|
if ctx == nil {
|
||||||
|
uuid, _ := uuid2.NewV7()
|
||||||
|
return uuid.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
if id, _ := ctx.Value(TraceId).(string); id != "" {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid, _ := uuid2.NewV7()
|
||||||
|
return uuid.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func DebugCtx(ctx context.Context, msg string, data ...any) {
|
||||||
|
msg = traceId(ctx) + " | " + msg
|
||||||
|
DefaultLogger.Debug(msg, data...)
|
||||||
|
}
|
||||||
|
func InfoCtx(ctx context.Context, msg string, data ...any) {
|
||||||
|
msg = traceId(ctx) + " | " + msg
|
||||||
|
DefaultLogger.Info(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func WarnCtx(ctx context.Context, msg string, data ...any) {
|
||||||
|
msg = traceId(ctx) + " | " + msg
|
||||||
|
DefaultLogger.Warn(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrorCtx(ctx context.Context, msg string, data ...any) {
|
||||||
|
msg = traceId(ctx) + " | " + msg
|
||||||
|
DefaultLogger.Error(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PanicCtx(ctx context.Context, msg string, data ...any) {
|
||||||
|
msg = traceId(ctx) + " | " + msg
|
||||||
|
DefaultLogger.Panic(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FatalCtx(ctx context.Context, msg string, data ...any) {
|
||||||
|
msg = traceId(ctx) + " | " + msg
|
||||||
|
DefaultLogger.Fatal(msg, data...)
|
||||||
|
}
|
||||||
17
pkg/logger/ctx_test.go
Normal file
17
pkg/logger/ctx_test.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCtxLog(t *testing.T) {
|
||||||
|
DebugCtx(nil, "hello %s", "world")
|
||||||
|
InfoCtx(nil, "hello %s", "world")
|
||||||
|
WarnCtx(context.Background(), "hello %s", "world")
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx = context.WithValue(ctx, TraceId, "value")
|
||||||
|
SetLogLevel(LogLevelDebug)
|
||||||
|
DebugCtx(ctx, "hello %s", "world")
|
||||||
|
ErrorCtx(ctx, "hello %s", "world")
|
||||||
|
}
|
||||||
67
pkg/logger/default.go
Normal file
67
pkg/logger/default.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
nilLogger = func(prefix, timestamp, msg string, data ...any) {}
|
||||||
|
normalLogger = func(prefix, timestamp, msg string, data ...any) {
|
||||||
|
fmt.Printf(prefix+"| "+timestamp+" | "+msg+"\n", data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
panicLogger = func(prefix, timestamp, msg string, data ...any) {
|
||||||
|
panic(fmt.Sprintf(prefix+"| "+timestamp+" | "+msg+"\n", data...))
|
||||||
|
}
|
||||||
|
|
||||||
|
fatalLogger = func(prefix, timestamp, msg string, data ...any) {
|
||||||
|
fmt.Printf(prefix+"| "+timestamp+" | "+msg+"\n", data...)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultLogger = &logger{
|
||||||
|
Mutex: sync.Mutex{},
|
||||||
|
timeFormat: "2006-01-02T15:04:05",
|
||||||
|
writer: os.Stdout,
|
||||||
|
level: LogLevelInfo,
|
||||||
|
debug: nilLogger,
|
||||||
|
info: normalLogger,
|
||||||
|
warn: normalLogger,
|
||||||
|
error: normalLogger,
|
||||||
|
panic: panicLogger,
|
||||||
|
fatal: fatalLogger,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetTimeFormat(format string) {
|
||||||
|
DefaultLogger.SetTimeFormat(format)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetLogLevel(level LogLevel) {
|
||||||
|
DefaultLogger.SetLogLevel(level)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Debug(msg string, data ...any) {
|
||||||
|
DefaultLogger.Debug(msg, data...)
|
||||||
|
}
|
||||||
|
func Info(msg string, data ...any) {
|
||||||
|
DefaultLogger.Info(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Warn(msg string, data ...any) {
|
||||||
|
DefaultLogger.Warn(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Error(msg string, data ...any) {
|
||||||
|
DefaultLogger.Error(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Panic(msg string, data ...any) {
|
||||||
|
DefaultLogger.Panic(msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fatal(msg string, data ...any) {
|
||||||
|
DefaultLogger.Fatal(msg, data...)
|
||||||
|
}
|
||||||
115
pkg/logger/logger.go
Normal file
115
pkg/logger/logger.go
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"io"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LogLevel uint32
|
||||||
|
|
||||||
|
const (
|
||||||
|
LogLevelDebug = iota
|
||||||
|
LogLevelInfo
|
||||||
|
LogLevelWarn
|
||||||
|
LogLevelError
|
||||||
|
LogLevelPanic
|
||||||
|
LogLevelFatal
|
||||||
|
)
|
||||||
|
|
||||||
|
type logger struct {
|
||||||
|
sync.Mutex
|
||||||
|
timeFormat string
|
||||||
|
writer io.Writer
|
||||||
|
level LogLevel
|
||||||
|
debug func(prefix, timestamp, msg string, data ...any)
|
||||||
|
info func(prefix, timestamp, msg string, data ...any)
|
||||||
|
warn func(prefix, timestamp, msg string, data ...any)
|
||||||
|
error func(prefix, timestamp, msg string, data ...any)
|
||||||
|
panic func(prefix, timestamp, msg string, data ...any)
|
||||||
|
fatal func(prefix, timestamp, msg string, data ...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
red = color.New(color.FgRed)
|
||||||
|
hired = color.New(color.FgHiRed)
|
||||||
|
green = color.New(color.FgGreen)
|
||||||
|
yellow = color.New(color.FgYellow)
|
||||||
|
white = color.New(color.FgWhite)
|
||||||
|
)
|
||||||
|
|
||||||
|
func (l *logger) SetTimeFormat(format string) {
|
||||||
|
l.Lock()
|
||||||
|
defer l.Unlock()
|
||||||
|
l.timeFormat = format
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) SetLogLevel(level LogLevel) {
|
||||||
|
l.Lock()
|
||||||
|
defer l.Unlock()
|
||||||
|
|
||||||
|
if level > LogLevelDebug {
|
||||||
|
l.debug = nilLogger
|
||||||
|
} else {
|
||||||
|
l.debug = normalLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
if level > LogLevelInfo {
|
||||||
|
l.info = nilLogger
|
||||||
|
} else {
|
||||||
|
l.info = normalLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
if level > LogLevelWarn {
|
||||||
|
l.warn = nilLogger
|
||||||
|
} else {
|
||||||
|
l.warn = normalLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
if level > LogLevelError {
|
||||||
|
l.error = nilLogger
|
||||||
|
} else {
|
||||||
|
l.error = normalLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
if level > LogLevelPanic {
|
||||||
|
l.panic = nilLogger
|
||||||
|
} else {
|
||||||
|
l.panic = panicLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
if level > LogLevelFatal {
|
||||||
|
l.fatal = nilLogger
|
||||||
|
} else {
|
||||||
|
l.fatal = fatalLogger
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Debug(msg string, data ...any) {
|
||||||
|
l.debug(white.Sprint("Debug "), time.Now().Format(l.timeFormat), msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Info(msg string, data ...any) {
|
||||||
|
l.info(green.Sprint("Info "), time.Now().Format(l.timeFormat), msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Warn(msg string, data ...any) {
|
||||||
|
l.warn(yellow.Sprint("Warn "), time.Now().Format(l.timeFormat), msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Error(msg string, data ...any) {
|
||||||
|
l.error(red.Sprint("Error "), time.Now().Format(l.timeFormat), msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Panic(msg string, data ...any) {
|
||||||
|
l.panic(hired.Sprint("Panic "), time.Now().Format(l.timeFormat), msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Fatal(msg string, data ...any) {
|
||||||
|
l.fatal(hired.Sprint("Fatal "), time.Now().Format(l.timeFormat), msg, data...)
|
||||||
|
}
|
||||||
|
|
||||||
|
type WroteLogger interface {
|
||||||
|
Info(msg string, data ...any)
|
||||||
|
}
|
||||||
21
pkg/logger/new.go
Normal file
21
pkg/logger/new.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func New() *logger {
|
||||||
|
return &logger{
|
||||||
|
Mutex: sync.Mutex{},
|
||||||
|
timeFormat: "2006-01-02T15:04:05",
|
||||||
|
writer: os.Stdout,
|
||||||
|
level: LogLevelInfo,
|
||||||
|
debug: nilLogger,
|
||||||
|
info: normalLogger,
|
||||||
|
warn: normalLogger,
|
||||||
|
error: normalLogger,
|
||||||
|
panic: panicLogger,
|
||||||
|
fatal: fatalLogger,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,15 +47,6 @@ location /client/dl/ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
location /user/avatar/ {
|
|
||||||
auth_request /token_auth;
|
|
||||||
|
|
||||||
proxy_set_header Cookie $http_cookie;
|
|
||||||
alias /static/avatar/;
|
|
||||||
expires 7d;
|
|
||||||
add_header Cache-Control public;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /file/share/ {
|
location /file/share/ {
|
||||||
auth_request /token_auth;
|
auth_request /token_auth;
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ server {
|
|||||||
|
|
||||||
server_tokens off;
|
server_tokens off;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://front-admin-service;
|
||||||
|
}
|
||||||
|
|
||||||
location /api/system/version {
|
location /api/system/version {
|
||||||
proxy_pass http://app-helper-service/api/v2_2/system/version;
|
proxy_pass http://app-helper-service/api/v2_2/system/version;
|
||||||
}
|
}
|
||||||
@@ -90,14 +94,16 @@ server {
|
|||||||
proxy_pass http://app-helper-service.hsv2;
|
proxy_pass http://app-helper-service.hsv2;
|
||||||
}
|
}
|
||||||
|
|
||||||
# location /wm/ {
|
location /user/avatar/ {
|
||||||
# alias /data/wm/;
|
proxy_pass http://app-helper-service.hsv2/api/v2_2/_obj/;
|
||||||
# expires 30d;
|
}
|
||||||
# add_header Cache-Control public;
|
|
||||||
# }
|
|
||||||
|
|
||||||
location / {
|
location /api/account/profile/avatar {
|
||||||
proxy_pass http://front-admin-service;
|
proxy_pass http://app-helper-service.hsv2/api/v2_2/user/profile/avatar/update;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/admin/business-center/network-app/tunnel {
|
||||||
|
proxy_pass http://app-helper-service.hsv2/api/v2_2/interceptor/mie/resource/icon$request_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api/v2_1/user {
|
location /api/v2_1/user {
|
||||||
@@ -120,6 +126,10 @@ server {
|
|||||||
proxy_pass http://client-linux-service;
|
proxy_pass http://client-linux-service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /api/v2_2/yosguard {
|
||||||
|
proxy_pass http://10.118.2.10:7788;
|
||||||
|
}
|
||||||
|
|
||||||
include /etc/nginx/common/common.conf;
|
include /etc/nginx/common/common.conf;
|
||||||
|
|
||||||
location /ws {
|
location /ws {
|
||||||
@@ -130,28 +140,11 @@ server {
|
|||||||
proxy_read_timeout 300s;
|
proxy_read_timeout 300s;
|
||||||
}
|
}
|
||||||
|
|
||||||
# location /backup {
|
|
||||||
# proxy_pass http://hs-backup-server;
|
|
||||||
# proxy_set_header Host $host;
|
|
||||||
# proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
# proxy_read_timeout 300s;
|
|
||||||
# }
|
|
||||||
|
|
||||||
location /api/local/user/import/template {
|
location /api/local/user/import/template {
|
||||||
auth_request /token_auth;
|
auth_request /token_auth;
|
||||||
alias /static/resource/local_user_import_template.xlsx;
|
alias /static/resource/local_user_import_template.xlsx;
|
||||||
}
|
}
|
||||||
|
|
||||||
# location /wm/api {
|
|
||||||
# proxy_pass http://hs-watermark-server;
|
|
||||||
# proxy_http_version 1.1;
|
|
||||||
# proxy_set_header Host $host;
|
|
||||||
# proxy_set_header X-Real-IP $proxy_protocol_addr;
|
|
||||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
# proxy_read_timeout 300s;
|
|
||||||
# }
|
|
||||||
|
|
||||||
location @my_401 {
|
location @my_401 {
|
||||||
default_type text/html;
|
default_type text/html;
|
||||||
return 401 '<!doctypehtml><html lang=en><meta charset=UTF-8><meta content="width=device-width,initial-scale=1"name=viewport><title>401</title><style>body{display:flex;flex-direction:column;align-items:center;justify-content:center}</style><h1>401 Unauthorized</h1>';
|
return 401 '<!doctypehtml><html lang=en><meta charset=UTF-8><meta content="width=device-width,initial-scale=1"name=viewport><title>401</title><style>body{display:flex;flex-direction:column;align-items:center;justify-content:center}</style><h1>401 Unauthorized</h1>';
|
||||||
|
|||||||
Reference in New Issue
Block a user