Added Dockerfile

This commit is contained in:
Leon Mika 2025-02-01 11:04:32 +11:00
parent 50f7e9632e
commit 1b67fe284d
4 changed files with 33 additions and 10 deletions

View file

@ -12,7 +12,7 @@ exclude_file = []
exclude_regex = ["_test.go", "build/.*"]
exclude_unchanged = false
follow_symlink = false
full_bin = "export $(cat .env | xargs) ; make init-db ; cd build ; ./hugo-cms"
full_bin = "export $(cat .env | xargs) ; make prep-dev init-db ; cd build ; ./hugo-cms"
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html", "gohtml", "css", "js"]
include_file = []

21
Dockerfile Normal file
View file

@ -0,0 +1,21 @@
FROM golang:1.23.3 AS builder
WORKDIR /usr/src/app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN make compile
FROM scratch
COPY --from=builder /usr/src/app/build/ /.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /
ENV PORT=3000
CMD ["/hugo-cms"]

View file

@ -5,12 +5,15 @@ clean:
.Phony: prep
prep:
-docker-compose up -d
mkdir -p build
.Phony: compile
compile: prep
go build -o ./build/hugo-cms
CGO_ENABLED=0 go build -o ./build/hugo-cms
.Phony: prep-dev
prep-dev:
docker-compose up -d
.Phony: init-db
init-db:

13
main.go
View file

@ -51,6 +51,12 @@ func main() {
}
defer dbp.Close()
log.Println("Connected to database")
if err := dbp.Migrate(context.Background()); err != nil {
log.Fatal(err)
}
log.Println("Database migrated")
userService := users.NewService(dbp)
if *flagUser != "" {
@ -83,13 +89,6 @@ func main() {
postHandlers := handlers.Post{Post: postService}
authHandlers := handlers.AuthHandler{UserService: userService}
log.Println("Connected to database")
if err := dbp.Migrate(context.Background()); err != nil {
log.Fatal(err)
}
log.Println("Database migrated")
tmplEngine := html.NewFileSystem(http.FS(templates.FS), ".html")
tmplEngine.Funcmap["markdown"] = func(s string) (template.HTML, error) {
var buf bytes.Buffer