add dockerfile on starter template

This commit is contained in:
maddalax 2024-09-24 15:03:29 -05:00
parent 9acab64380
commit 78fbf7be38
6 changed files with 59 additions and 7 deletions

View file

@ -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)

View file

@ -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()
}

View file

@ -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

View file

@ -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"]

View file

@ -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

View file

@ -1,5 +1,5 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["**/*.go", "**/*.js"],
content: ["**/*.go"],
plugins: [],
};