Added Dockerfile
This commit is contained in:
parent
50f7e9632e
commit
1b67fe284d
|
@ -12,7 +12,7 @@ exclude_file = []
|
||||||
exclude_regex = ["_test.go", "build/.*"]
|
exclude_regex = ["_test.go", "build/.*"]
|
||||||
exclude_unchanged = false
|
exclude_unchanged = false
|
||||||
follow_symlink = 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_dir = []
|
||||||
include_ext = ["go", "tpl", "tmpl", "html", "gohtml", "css", "js"]
|
include_ext = ["go", "tpl", "tmpl", "html", "gohtml", "css", "js"]
|
||||||
include_file = []
|
include_file = []
|
||||||
|
|
21
Dockerfile
Normal file
21
Dockerfile
Normal 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"]
|
7
Makefile
7
Makefile
|
@ -5,12 +5,15 @@ clean:
|
||||||
|
|
||||||
.Phony: prep
|
.Phony: prep
|
||||||
prep:
|
prep:
|
||||||
-docker-compose up -d
|
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
|
|
||||||
.Phony: compile
|
.Phony: compile
|
||||||
compile: prep
|
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
|
.Phony: init-db
|
||||||
init-db:
|
init-db:
|
||||||
|
|
13
main.go
13
main.go
|
@ -51,6 +51,12 @@ func main() {
|
||||||
}
|
}
|
||||||
defer dbp.Close()
|
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)
|
userService := users.NewService(dbp)
|
||||||
|
|
||||||
if *flagUser != "" {
|
if *flagUser != "" {
|
||||||
|
@ -83,13 +89,6 @@ func main() {
|
||||||
postHandlers := handlers.Post{Post: postService}
|
postHandlers := handlers.Post{Post: postService}
|
||||||
authHandlers := handlers.AuthHandler{UserService: userService}
|
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 := html.NewFileSystem(http.FS(templates.FS), ".html")
|
||||||
tmplEngine.Funcmap["markdown"] = func(s string) (template.HTML, error) {
|
tmplEngine.Funcmap["markdown"] = func(s string) (template.HTML, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
Loading…
Reference in a new issue