Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat: update default config file path

LinkinStar50f2180426d2
diff --git a/Dockerfile b/Dockerfile
index 590fa0a1..91094435 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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
diff --git a/cmd/answer/command.go b/cmd/answer/command.go
index 3facd636..f38d1a95 100644
--- a/cmd/answer/command.go
+++ b/cmd/answer/command.go
@@ -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]")
diff --git a/internal/cli/install.go b/internal/cli/install.go
index 74a1f574..0e2de67f 100644
--- a/internal/cli/install.go
+++ b/internal/cli/install.go
@@ -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 {
+
+ 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())
- } else {
- fmt.Printf("[config-file] install success\n")
+ 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
diff --git a/internal/cli/install_check.go b/internal/cli/install_check.go
index ac18dc05..66772506 100644
--- a/internal/cli/install_check.go
+++ b/internal/cli/install_check.go
@@ -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 {