43 lines
		
	
	
		
			889 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			889 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| # Build stage
 | |
| FROM golang:bullseye as base
 | |
| 
 | |
| # Install iperf3
 | |
| RUN apt-get update && apt-get install -y iperf3 && apt-get clean
 | |
| 
 | |
| RUN adduser \
 | |
|   --disabled-password \
 | |
|   --gecos "" \
 | |
|   --home "/nonexistent" \
 | |
|   --shell "/sbin/nologin" \
 | |
|   --no-create-home \
 | |
|   --uid 65532 \
 | |
|   small-user
 | |
| 
 | |
| WORKDIR /app
 | |
| 
 | |
| COPY . .
 | |
| 
 | |
| # RUN go mod download
 | |
| # RUN go mod verify
 | |
| 
 | |
| RUN GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main .
 | |
| 
 | |
| # Final stage
 | |
| FROM alpine:latest
 | |
| 
 | |
| # Install iperf3 in Alpine
 | |
| RUN apk add --no-cache iperf3
 | |
| 
 | |
| # Copy the binary from the build stage
 | |
| COPY --from=base /app/main /main
 | |
| 
 | |
| # Copy necessary files from the build stage
 | |
| COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo
 | |
| COPY --from=base /etc/passwd /etc/passwd
 | |
| COPY --from=base /etc/group /etc/group
 | |
| 
 | |
| # Use the non-root user
 | |
| USER small-user
 | |
| EXPOSE 8090
 | |
| 
 | |
| CMD ["/main"] | 
