hvanu commited on
Commit
8549d8b
·
1 Parent(s): faedb74
Files changed (3) hide show
  1. Dockerfile +17 -9
  2. go.mod +3 -0
  3. main.go +10 -0
Dockerfile CHANGED
@@ -1,13 +1,21 @@
1
- FROM python:3.9-slim
 
2
 
3
- RUN useradd -m -u 1000 user
4
- USER user
5
- ENV PATH="/home/user/.local/bin:$PATH"
 
6
 
7
- WORKDIR /app
 
 
 
8
 
9
- COPY --chown=user ./requirements.txt requirements.txt
10
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
 
12
- COPY --chown=user . /app
13
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
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
+ }