added Dockerfile
This commit is contained in:
parent
a4b7637fd0
commit
e1fb619acb
2 changed files with 34 additions and 1 deletions
25
Dockerfile
Normal file
25
Dockerfile
Normal file
|
@ -0,0 +1,25 @@
|
|||
FROM golang:1.19-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY go.mod ./
|
||||
COPY go.sum ./
|
||||
|
||||
RUN apk add build-base && go mod download
|
||||
|
||||
COPY . ./
|
||||
|
||||
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /gowatch
|
||||
|
||||
|
||||
FROM golang:1.19-alpine AS base
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /gowatch ./gowatch
|
||||
COPY ./ ./
|
||||
|
||||
RUN mkdir /config
|
||||
ENV GOWATCH_DATABASE_DSN "/config/database.db"
|
||||
|
||||
ENTRYPOINT ["./gowatch"]
|
10
main.go
10
main.go
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-contrib/multitemplate"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -51,6 +52,7 @@ func (web *Web) init() {
|
|||
}
|
||||
|
||||
func (web *Web) initDB() {
|
||||
log.Println(viper.GetString("database.dsn"))
|
||||
db, err := gorm.Open(sqlite.Open(viper.GetString("database.dsn")))
|
||||
if err != nil {
|
||||
log.Panicln("Could not start DB: ", err)
|
||||
|
@ -78,6 +80,8 @@ func (web *Web) initRouter() {
|
|||
|
||||
web.router.GET("/cache/view", web.cacheView)
|
||||
web.router.POST("/cache/clear", web.cacheClear)
|
||||
|
||||
web.router.SetTrustedProxies(nil)
|
||||
}
|
||||
|
||||
func (web *Web) initTemplates() {
|
||||
|
@ -466,11 +470,15 @@ func main() {
|
|||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(".")
|
||||
viper.AddConfigPath("/config")
|
||||
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
viper.SetEnvPrefix("GOWATCH")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
log.Fatalln("Could not load config file")
|
||||
log.Println("Could not load config file, using env/defaults")
|
||||
}
|
||||
|
||||
web := newWeb()
|
||||
|
|
Loading…
Add table
Reference in a new issue