add dockerfile on starter template
This commit is contained in:
parent
9acab64380
commit
78fbf7be38
6 changed files with 59 additions and 7 deletions
|
|
@ -83,7 +83,7 @@ func DownloadTemplate(outPath string) {
|
||||||
fmt.Sprintf("module %s", newModuleName))
|
fmt.Sprintf("module %s", newModuleName))
|
||||||
|
|
||||||
_ = util.ReplaceTextInDirRecursive(newDir, templateName, newModuleName, func(file string) bool {
|
_ = 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)
|
fmt.Printf("Setting up the project in %s\n", newDir)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package h
|
package h
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Ren interface {
|
type Ren interface {
|
||||||
|
|
@ -11,13 +9,10 @@ type Ren interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Render(node Ren) string {
|
func Render(node Ren) string {
|
||||||
start := time.Now()
|
|
||||||
builder := &strings.Builder{}
|
builder := &strings.Builder{}
|
||||||
context := &RenderContext{
|
context := &RenderContext{
|
||||||
builder: builder,
|
builder: builder,
|
||||||
}
|
}
|
||||||
node.Render(context)
|
node.Render(context)
|
||||||
duration := time.Since(start)
|
|
||||||
fmt.Printf("render took %d microseconds\n", duration.Microseconds())
|
|
||||||
return builder.String()
|
return builder.String()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
templates/starter/.dockerignore
Normal file
11
templates/starter/.dockerignore
Normal 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
|
||||||
42
templates/starter/Dockerfile
Normal file
42
templates/starter/Dockerfile
Normal 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"]
|
||||||
|
|
@ -10,6 +10,10 @@ tasks:
|
||||||
cmds:
|
cmds:
|
||||||
- go run github.com/maddalax/htmgo/cli/htmgo@latest build
|
- go run github.com/maddalax/htmgo/cli/htmgo@latest build
|
||||||
|
|
||||||
|
docker:
|
||||||
|
cmds:
|
||||||
|
- docker build .
|
||||||
|
|
||||||
watch:
|
watch:
|
||||||
cmds:
|
cmds:
|
||||||
- go run github.com/maddalax/htmgo/cli/htmgo@latest watch
|
- go run github.com/maddalax/htmgo/cli/htmgo@latest watch
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: ["**/*.go", "**/*.js"],
|
content: ["**/*.go"],
|
||||||
plugins: [],
|
plugins: [],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue