소스 검색

fix docker

Help-14 3 년 전
부모
커밋
0fc3b781b5
2개의 변경된 파일8개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      docker-compose.yml
  2. 7 4
      src/main.go

+ 1 - 1
docker-compose.yml

@@ -1,7 +1,7 @@
 services:
   magma:
     container_name: magma
-    image: magma
+    image: help14/magma
     restart: unless-stopped
     volumes:
       - ./data/:/app/data

+ 7 - 4
src/main.go

@@ -1,12 +1,12 @@
 package main
 
 import (
+	"fmt"
 	"html/template"
 	"io/ioutil"
 	"log"
 	"net/http"
 	"os"
-	"os/exec"
 	"path/filepath"
 	"time"
 
@@ -24,15 +24,18 @@ var websiteData = struct {
 func main() {
 	pwd, _ = os.Getwd()
 
-	exec.Command("mkdir", "-p", "./data").Run()
-	exec.Command("cp", "--recursive", "./common/*", "./data/").Run()
+	dataPath := filepath.Join(pwd, "data")
+	if _, err := os.Stat(filepath.Join(dataPath, "data.yaml")); os.IsNotExist(err) {
+		fmt.Println("Copy files to data folder")
+		modules.CopyDirectory(filepath.Join(pwd, "common"), dataPath)
+	}
 
 	appConfig = modules.LoadConfig()
 	websiteData.Config = appConfig.Website
 	websiteData.Language = modules.LoadLanguage(appConfig.Website.Language)
 	websiteData.Contents = modules.LoadContent().Data
 
-	commonfs := http.FileServer(http.Dir(filepath.Join(pwd, "data")))
+	commonfs := http.FileServer(http.Dir(filepath.Join(dataPath, "common")))
 	http.Handle("/common/", http.StripPrefix("/common/", commonfs))
 
 	languagefs := http.FileServer(http.Dir(filepath.Join(pwd, "languages")))