mirror of https://gitee.com/answerdev/answer.git
feat: update default config file path
This commit is contained in:
parent
ebda51ba29
commit
da6e241a34
|
@ -21,7 +21,6 @@ WORKDIR ${BUILD_DIR}
|
|||
COPY --from=node-builder /tmp/build ${BUILD_DIR}/ui/build
|
||||
RUN make clean build && \
|
||||
cp answer /usr/bin/answer && \
|
||||
mkdir -p /data/conf && chmod 777 /data/conf && cp configs/config.yaml /data/conf/config.yaml && \
|
||||
mkdir -p /data/upfiles && chmod 777 /data/upfiles && \
|
||||
mkdir -p /data/i18n && chmod 777 /data/i18n && cp -r i18n/*.yaml /data/i18n
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ var (
|
|||
|
||||
func init() {
|
||||
rootCmd.Version = Version
|
||||
runCmd.Flags().StringVarP(&confFlag, "config", "c", "data/config.yaml", "config path, eg: -c config.yaml")
|
||||
runCmd.Flags().StringVarP(&confFlag, "config", "c", "/data/conf/config.yaml", "config path, eg: -c config.yaml")
|
||||
|
||||
dumpCmd.Flags().StringVarP(&dumpDataPath, "path", "p", "./", "dump data path, eg: -p ./dump/data/")
|
||||
|
||||
|
@ -108,7 +108,7 @@ To run answer, use:
|
|||
Long: `Check if the current environment meets the startup requirements`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("Start checking the required environment...")
|
||||
if cli.CheckConfigFile() {
|
||||
if cli.CheckConfigFile(confFlag) {
|
||||
fmt.Println("config file exists [✔]")
|
||||
} else {
|
||||
fmt.Println("config file not exists [x]")
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/segmentfault/answer/assets"
|
||||
"github.com/segmentfault/answer/configs"
|
||||
|
@ -15,14 +16,13 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
defaultConfigFilePath = "/data/conf/config.yaml"
|
||||
defaultUploadFilePath = "/data/upfiles"
|
||||
defaultI18nPath = "/data/i18n"
|
||||
defaultConfigFilePath = "/data/conf/"
|
||||
defaultUploadFilePath = "/data/upfiles/"
|
||||
defaultI18nPath = "/data/i18n/"
|
||||
)
|
||||
|
||||
// InstallAllInitialEnvironment install all initial environment
|
||||
func InstallAllInitialEnvironment() {
|
||||
installDataDir()
|
||||
installConfigFile()
|
||||
installUploadDir()
|
||||
installI18nBundle()
|
||||
|
@ -30,25 +30,27 @@ func InstallAllInitialEnvironment() {
|
|||
return
|
||||
}
|
||||
|
||||
func installDataDir() {
|
||||
if _, err := dir.CreatePathIsNotExist("data"); err != nil {
|
||||
fmt.Printf("[data-dir] install fail %s\n", err.Error())
|
||||
} else {
|
||||
fmt.Printf("[data-dir] install success\n")
|
||||
}
|
||||
}
|
||||
|
||||
func installConfigFile() {
|
||||
fmt.Println("[config-file] try to install...")
|
||||
if CheckConfigFile() {
|
||||
defaultConfigFile := filepath.Join(defaultConfigFilePath, "config.yaml")
|
||||
|
||||
// if config file already exists do nothing.
|
||||
if CheckConfigFile(defaultConfigFile) {
|
||||
fmt.Println("[config-file] already exists")
|
||||
return
|
||||
}
|
||||
if err := WriterFile(defaultConfigFilePath, string(configs.Config)); err != nil {
|
||||
fmt.Printf("[config-file] install fail %s\n", err.Error())
|
||||
} else {
|
||||
fmt.Printf("[config-file] install success\n")
|
||||
|
||||
if _, err := dir.CreatePathIsNotExist(defaultConfigFilePath); err != nil {
|
||||
fmt.Printf("[config-file] create directory fail %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("[config-file] create directory success\n")
|
||||
|
||||
if err := WriterFile(defaultConfigFile, string(configs.Config)); err != nil {
|
||||
fmt.Printf("[config-file] install fail %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("[config-file] install success\n")
|
||||
}
|
||||
|
||||
func installUploadDir() {
|
||||
|
@ -74,7 +76,7 @@ func installI18nBundle() {
|
|||
}
|
||||
fmt.Printf("[i18n] find i18n bundle %d\n", len(i18nList))
|
||||
for _, item := range i18nList {
|
||||
path := fmt.Sprintf("%s/%s", defaultI18nPath, item.Name())
|
||||
path := filepath.Join(defaultI18nPath, item.Name())
|
||||
content, err := i18n.I18n.ReadFile(item.Name())
|
||||
if err != nil {
|
||||
continue
|
||||
|
|
|
@ -5,12 +5,12 @@ import (
|
|||
"github.com/segmentfault/answer/pkg/dir"
|
||||
)
|
||||
|
||||
func CheckConfigFile() bool {
|
||||
return dir.CheckPathExist(defaultConfigFilePath)
|
||||
func CheckConfigFile(configPath string) bool {
|
||||
return dir.CheckPathExist(configPath)
|
||||
}
|
||||
|
||||
func CheckUploadDir() bool {
|
||||
return dir.CheckPathExist(defaultConfigFilePath)
|
||||
return dir.CheckPathExist(defaultUploadFilePath)
|
||||
}
|
||||
|
||||
func CheckDB(dataConf *data.Database) bool {
|
||||
|
|
Loading…
Reference in New Issue