Skip to content

Commit

Permalink
build(dockerfile): explicitly disable cgo
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadNews committed Feb 18, 2024
1 parent 469f6e1 commit 9acff34
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Build the application from source.
FROM golang:1.22.0-alpine@sha256:8e96e6cff6a388c2f70f5f662b64120941fcd7d4b89d62fec87520323a316bd9 AS go-builder

ENV GOCACHE="/cache/go-build"

WORKDIR /app

ENV \
# Maunt as dedicated RUN cache.
GOCACHE="/cache/go-build" \
# Disable CGO to build a static binary.
CGO_ENABLED=0

COPY go.mod go.sum cmd ./
RUN --mount=type=cache,target=${GOCACHE} \
go build -o /app/dist/deadnews-template-go ./...
Expand Down
2 changes: 1 addition & 1 deletion cmd/deadnews-template-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func makeServer() *echo.Echo {

// handleRoot handles the "/" route and returns an HTML response.
func handleRoot(c echo.Context) error {
return c.HTML(http.StatusOK, "Hello, World!")
return c.HTML(http.StatusOK, "Hello, World!\n")
}

// handleHealth handles the "/health" route and returns a JSON response.
Expand Down
2 changes: 1 addition & 1 deletion cmd/deadnews-template-go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestServerResponseRoot(t *testing.T) {
assert.Equal(t, expectedStatus, rec.Code)

// Check the actual response body against the expected response body.
expectedBody := "Hello, World!"
expectedBody := "Hello, World!\n"
assert.Equal(t, expectedBody, rec.Body.String())

// Check the response content type header.
Expand Down

0 comments on commit 9acff34

Please sign in to comment.