feat: 许多变化
1. make apps 逻辑大变更, vendor 成标准传入 args 2. nginx -> app-helper
This commit is contained in:
@@ -31,7 +31,7 @@ func Check() *cobra.Command {
|
||||
|
||||
_cmd.Flags().StringVar(&workdir, "workdir", "/root/hs-installation", "Working directory")
|
||||
_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(&ignoreCPU, "ignore-check-cpu", false, "ignore cpu requirement check result")
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ package cmd
|
||||
import (
|
||||
"os"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
"github.com/spf13/cobra"
|
||||
"yizhisec.com/hsv2/forge/internal/cmd/makecmd"
|
||||
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
||||
"yizhisec.com/hsv2/forge/internal/opt"
|
||||
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||
)
|
||||
|
||||
func makeCmd() *cobra.Command {
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
"github.com/spf13/cobra"
|
||||
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
||||
"yizhisec.com/hsv2/forge/internal/opt"
|
||||
"yizhisec.com/hsv2/forge/pkg/logger"
|
||||
tc "yizhisec.com/hsv2/forge/pkg/tool/client"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package makecmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"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.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
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
"github.com/spf13/cobra"
|
||||
"yizhisec.com/hsv2/forge/internal/opt"
|
||||
)
|
||||
@@ -12,14 +11,6 @@ var rootCmd = &cobra.Command{
|
||||
Use: "forge",
|
||||
Short: "Forge is a tool for building and installing 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 {
|
||||
|
||||
Reference in New Issue
Block a user