This commit is contained in:
maddalax 2024-09-22 22:08:56 -05:00
parent dc9476786b
commit e34b8fe141
2 changed files with 10 additions and 10 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/maddalax/htmgo/cli/htmgo/tasks/copyassets" "github.com/maddalax/htmgo/cli/htmgo/tasks/copyassets"
"github.com/maddalax/htmgo/cli/htmgo/tasks/css" "github.com/maddalax/htmgo/cli/htmgo/tasks/css"
"github.com/maddalax/htmgo/cli/htmgo/tasks/process" "github.com/maddalax/htmgo/cli/htmgo/tasks/process"
"os"
) )
func Build() { func Build() {
@ -19,8 +20,13 @@ func Build() {
process.RunOrExit("rm -rf ./dist") process.RunOrExit("rm -rf ./dist")
process.RunOrExit("mkdir -p ./dist") process.RunOrExit("mkdir -p ./dist")
process.RunOrExit("env go build -o ./dist .") flags := ""
process.RunOrExit("go build -o ./dist/app .") if os.Getenv("CGO_ENABLED") == "1" {
flags = `-a -ldflags '-linkmode external -extldflags "-static"' `
}
process.RunOrExit(fmt.Sprintf("go build -o ./dist/app %s.", flags))
process.RunOrExit(fmt.Sprintf("go build -o ./dist/app %s.", flags))
fmt.Printf("Executable built at %s\n", process.GetPathRelativeToCwd("dist")) fmt.Printf("Executable built at %s\n", process.GetPathRelativeToCwd("dist"))
} }

View file

@ -1,9 +1,5 @@
# Stage 1: Build the Go binary # Stage 1: Build the Go binary
FROM golang:1.23-alpine AS builder FROM golang:1.23 AS builder
RUN apk update
RUN apk add git
RUN apk add curl
# Set the working directory inside the container # Set the working directory inside the container
WORKDIR /app WORKDIR /app
@ -20,9 +16,7 @@ RUN go get github.com/maddalax/htmgo/framework@latest
# Copy the source code into the container # Copy the source code into the container
COPY . . COPY . .
# Build the Go binary for Linux RUN CGO_ENABLED=1 GOPRIVATE=github.com/maddalax LOG_LEVEL=debug go run github.com/maddalax/htmgo/cli/htmgo@latest build
RUN GOPRIVATE=github.com/maddalax LOG_LEVEL=debug go run github.com/maddalax/htmgo/cli/htmgo@latest build
# Stage 2: Create the smallest possible image # Stage 2: Create the smallest possible image
FROM gcr.io/distroless/base-debian11 FROM gcr.io/distroless/base-debian11