Browse Source

fix docker build, running ok now

Help-14 3 years ago
parent
commit
5fc6a6ecbe
3 changed files with 18 additions and 13 deletions
  1. 11 9
      Dockerfile
  2. 1 0
      build.sh
  3. 6 4
      src/main.go

+ 11 - 9
Dockerfile

@@ -1,15 +1,12 @@
 ## Build
 ## Build
 
 
-FROM golang:1.16-alpine AS build
+FROM golang:1.18-alpine AS build
 
 
 RUN mkdir /app
 RUN mkdir /app
 WORKDIR /app
 WORKDIR /app
+COPY ./src /app
 
 
-COPY ./src/main.go /app/
-COPY ./src/go.mod /app/
-COPY ./src/go.sum /app/
-COPY ./src/modules /app/
-
+RUN go mod download
 RUN go build -o /bin
 RUN go build -o /bin
 
 
 ## Deploy
 ## Deploy
@@ -19,9 +16,14 @@ MAINTAINER Help-14 [mail@help14.com]
 LABEL maintainer="mail@help14.com"
 LABEL maintainer="mail@help14.com"
 
 
 RUN mkdir /app
 RUN mkdir /app
-WORKDIR /app
 
 
-COPY --from=build /bin /app
+COPY --from=build /bin/magma /app/
+COPY ./src/common /app/common
+COPY ./src/languages /app/languages
+COPY ./src/sample /app/sample
+COPY ./src/themes /app/themes
 
 
 EXPOSE 7001
 EXPOSE 7001
-ENTRYPOINT magma
+
+WORKDIR /app
+ENTRYPOINT ./magma

+ 1 - 0
build.sh

@@ -1,2 +1,3 @@
 #!/bin/bash
 #!/bin/bash
 docker build -t magma -f- ./ < Dockerfile
 docker build -t magma -f- ./ < Dockerfile
+docker tag magma:latest help14/magma:latest

+ 6 - 4
src/main.go

@@ -13,6 +13,7 @@ import (
 	"github.com/help-14/magma/modules"
 	"github.com/help-14/magma/modules"
 )
 )
 
 
+var pwd string
 var appConfig modules.Config
 var appConfig modules.Config
 var websiteData = struct {
 var websiteData = struct {
 	Config   modules.WebsiteConfig
 	Config   modules.WebsiteConfig
@@ -21,6 +22,7 @@ var websiteData = struct {
 }{}
 }{}
 
 
 func main() {
 func main() {
+	pwd, _ = os.Getwd()
 	prepareSampleFiles()
 	prepareSampleFiles()
 	appConfig = modules.LoadConfig()
 	appConfig = modules.LoadConfig()
 
 
@@ -71,20 +73,20 @@ func serveWeather(w http.ResponseWriter, r *http.Request) {
 }
 }
 
 
 func serveTemplate(w http.ResponseWriter, r *http.Request) {
 func serveTemplate(w http.ResponseWriter, r *http.Request) {
-	lp := filepath.Join("themes", appConfig.Website.Theme, "index.html")
+	lp := filepath.Join(pwd, "themes", appConfig.Website.Theme, "index.html")
 	tmpl, _ := template.ParseFiles(lp)
 	tmpl, _ := template.ParseFiles(lp)
 	tmpl.Execute(w, websiteData)
 	tmpl.Execute(w, websiteData)
 }
 }
 
 
 func prepareSampleFiles() {
 func prepareSampleFiles() {
-	files, err := ioutil.ReadDir("./sample/")
+	files, err := ioutil.ReadDir(filepath.Join(pwd, "sample"))
 	if err != nil {
 	if err != nil {
 		log.Fatal(err)
 		log.Fatal(err)
 		return
 		return
 	}
 	}
 	for _, file := range files {
 	for _, file := range files {
-		samplePath := filepath.Join("sample", file.Name())
-		commonPath := filepath.Join("common", file.Name())
+		samplePath := filepath.Join(pwd, "sample", file.Name())
+		commonPath := filepath.Join(pwd, "common", file.Name())
 		if _, err := os.Stat(commonPath); errors.Is(err, os.ErrNotExist) {
 		if _, err := os.Stat(commonPath); errors.Is(err, os.ErrNotExist) {
 			modules.CopyFile(samplePath, commonPath)
 			modules.CopyFile(samplePath, commonPath)
 		}
 		}