diff --git a/cli/htmgo/tasks/downloadtemplate/main.go b/cli/htmgo/tasks/downloadtemplate/main.go index 27aebca..4ef6286 100644 --- a/cli/htmgo/tasks/downloadtemplate/main.go +++ b/cli/htmgo/tasks/downloadtemplate/main.go @@ -83,7 +83,7 @@ func DownloadTemplate(outPath string) { fmt.Sprintf("module %s", newModuleName)) _ = util.ReplaceTextInDirRecursive(newDir, templateName, newModuleName, func(file string) bool { - return strings.HasSuffix(file, ".go") + return strings.HasSuffix(file, ".go") || strings.HasPrefix(file, "Dockerfile") }) fmt.Printf("Setting up the project in %s\n", newDir) diff --git a/framework/h/render.go b/framework/h/render.go index dbf9a50..aa37dd5 100644 --- a/framework/h/render.go +++ b/framework/h/render.go @@ -1,9 +1,7 @@ package h import ( - "fmt" "strings" - "time" ) type Ren interface { @@ -11,13 +9,10 @@ type Ren interface { } func Render(node Ren) string { - start := time.Now() builder := &strings.Builder{} context := &RenderContext{ builder: builder, } node.Render(context) - duration := time.Since(start) - fmt.Printf("render took %d microseconds\n", duration.Microseconds()) return builder.String() } diff --git a/templates/starter/.dockerignore b/templates/starter/.dockerignore new file mode 100644 index 0000000..fb47686 --- /dev/null +++ b/templates/starter/.dockerignore @@ -0,0 +1,11 @@ +# Project exclude paths +/tmp/ +node_modules/ +dist/ +js/dist +js/node_modules +go.work +go.work.sum +.idea +!framework/assets/dist +__htmgo \ No newline at end of file diff --git a/templates/starter/Dockerfile b/templates/starter/Dockerfile new file mode 100644 index 0000000..eeb3943 --- /dev/null +++ b/templates/starter/Dockerfile @@ -0,0 +1,42 @@ +# Stage 1: Build the Go binary +FROM golang:1.23-alpine AS builder + +RUN apk update +RUN apk add git +RUN apk add curl + +# Set the working directory inside the container +WORKDIR /app + +# Copy go.mod and go.sum files +COPY go.mod go.sum ./ + +# Download and cache the Go modules +RUN go mod download + +# Copy the source code into the container +COPY . . + +# Always download the latest version of the framework +RUN go get github.com/maddalax/htmgo/framework@latest +RUN go mod tidy + +# Build the Go binary for Linux +RUN GOPRIVATE=github.com/maddalax GOPROXY=direct go run github.com/maddalax/htmgo/cli/htmgo@latest build + + +# Stage 2: Create the smallest possible image +FROM gcr.io/distroless/base-debian11 + +# Set the working directory inside the container +WORKDIR /app + +# Copy the Go binary from the builder stage +COPY --from=builder /app/dist . + +# Expose the necessary port (replace with your server port) +EXPOSE 3000 + + +# Command to run the binary +CMD ["./starter-template"] \ No newline at end of file diff --git a/templates/starter/Taskfile.yml b/templates/starter/Taskfile.yml index 8ed7363..695006f 100644 --- a/templates/starter/Taskfile.yml +++ b/templates/starter/Taskfile.yml @@ -10,6 +10,10 @@ tasks: cmds: - go run github.com/maddalax/htmgo/cli/htmgo@latest build + docker: + cmds: + - docker build . + watch: cmds: - go run github.com/maddalax/htmgo/cli/htmgo@latest watch diff --git a/templates/starter/tailwind.config.js b/templates/starter/tailwind.config.js index b60fb37..b18125c 100644 --- a/templates/starter/tailwind.config.js +++ b/templates/starter/tailwind.config.js @@ -1,5 +1,5 @@ /** @type {import('tailwindcss').Config} */ module.exports = { - content: ["**/*.go", "**/*.js"], + content: ["**/*.go"], plugins: [], };