Spaces:
Running
Running
Update
Browse files- Dockerfile +17 -9
- go.mod +3 -0
- main.go +10 -0
Dockerfile
CHANGED
@@ -1,13 +1,21 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
1 |
+
# syntax = docker/dockerfile:1-experimental
|
2 |
+
FROM golang:1.23-alpine AS builder
|
3 |
|
4 |
+
WORKDIR /home/appuser
|
5 |
+
COPY go.mod .
|
6 |
+
RUN go mod download
|
7 |
+
COPY main.go .
|
8 |
|
9 |
+
# -s disable symbol table, -w disable DWARF generation (smaller binary)
|
10 |
+
# cross compile for amd64
|
11 |
+
RUN --mount=type=cache,target=/root/.cache/go-build \
|
12 |
+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /bin/mock-server .
|
13 |
|
14 |
+
# Set platform to x64
|
15 |
+
FROM --platform=linux/amd64 gcr.io/distroless/static-debian12:nonroot as server
|
16 |
|
17 |
+
WORKDIR /home/appuser
|
18 |
+
COPY --from=builder --chown=nonroot:nonroot /bin/mock-server ./bin/mock-server
|
19 |
+
|
20 |
+
EXPOSE 3001/tcp
|
21 |
+
ENTRYPOINT ["./bin/mock-server"]
|
go.mod
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
module example.com/m/v2
|
2 |
+
|
3 |
+
go 1.23.5
|
main.go
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// print hello world
|
2 |
+
package main
|
3 |
+
|
4 |
+
import (
|
5 |
+
"fmt"
|
6 |
+
)
|
7 |
+
|
8 |
+
func main() {
|
9 |
+
fmt.Println("Hello, World!")
|
10 |
+
}
|