fix docker build, running ok now
This commit is contained in:
parent
58b5a26122
commit
5fc6a6ecbe
3 changed files with 18 additions and 13 deletions
20
Dockerfile
20
Dockerfile
|
@ -1,15 +1,12 @@
|
|||
## Build
|
||||
|
||||
FROM golang:1.16-alpine AS build
|
||||
FROM golang:1.18-alpine AS build
|
||||
|
||||
RUN mkdir /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
|
||||
|
||||
## Deploy
|
||||
|
@ -19,9 +16,14 @@ MAINTAINER Help-14 [mail@help14.com]
|
|||
LABEL maintainer="mail@help14.com"
|
||||
|
||||
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
|
||||
ENTRYPOINT magma
|
||||
|
||||
WORKDIR /app
|
||||
ENTRYPOINT ./magma
|
1
build.sh
1
build.sh
|
@ -1,2 +1,3 @@
|
|||
#!/bin/bash
|
||||
docker build -t magma -f- ./ < Dockerfile
|
||||
docker tag magma:latest help14/magma:latest
|
10
src/main.go
10
src/main.go
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/help-14/magma/modules"
|
||||
)
|
||||
|
||||
var pwd string
|
||||
var appConfig modules.Config
|
||||
var websiteData = struct {
|
||||
Config modules.WebsiteConfig
|
||||
|
@ -21,6 +22,7 @@ var websiteData = struct {
|
|||
}{}
|
||||
|
||||
func main() {
|
||||
pwd, _ = os.Getwd()
|
||||
prepareSampleFiles()
|
||||
appConfig = modules.LoadConfig()
|
||||
|
||||
|
@ -71,20 +73,20 @@ func serveWeather(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.Execute(w, websiteData)
|
||||
}
|
||||
|
||||
func prepareSampleFiles() {
|
||||
files, err := ioutil.ReadDir("./sample/")
|
||||
files, err := ioutil.ReadDir(filepath.Join(pwd, "sample"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
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) {
|
||||
modules.CopyFile(samplePath, commonPath)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue