KaThaNg commited on
Commit
989152d
·
verified ·
1 Parent(s): 5881998

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +4 -53
Dockerfile CHANGED
@@ -1,53 +1,4 @@
1
- # Stage 1: Build the Go application
2
- # Gợi ý: Sử dụng phiên bản Go mới hơn để các bản vá bảo mật và cải tiến hiệu năng
3
- FROM golang:1.22-alpine AS builder
4
-
5
- # Set necessary environment variables
6
- ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
7
-
8
- WORKDIR /build
9
-
10
- # Copy only the module definition file first
11
- COPY go.mod ./
12
- # Download dependencies and ensure go.sum is consistent
13
- RUN go mod download
14
-
15
- # Copy the rest of the source code AFTER initial download
16
- COPY . .
17
- # Now run tidy to ensure go.mod and go.sum match the code [cite: 5]
18
- RUN go mod tidy
19
-
20
- # Verify dependencies (optional but good practice)
21
- RUN go mod verify
22
-
23
- # Build the Go application statically linked
24
- # -ldflags="-w -s" reduces binary size by removing debug info
25
- RUN go build -ldflags="-w -s" -o /app/proxy-server .
26
-
27
- # Stage 2: Create the final minimal image
28
- FROM alpine:latest
29
-
30
- # Install ca-certificates for HTTPS calls and tzdata for timezone info
31
- RUN apk update && apk add --no-cache ca-certificates tzdata
32
-
33
- # Gợi ý: Kích hoạt non-root user để tăng cường bảo mật
34
- # Tạo group và user riêng cho ứng dụng
35
- RUN addgroup -S appgroup && adduser -S appuser -G appgroup
36
-
37
- # Set the working directory
38
- WORKDIR /app
39
-
40
- # Copy the built binary from the builder stage
41
- COPY --from=builder /app/proxy-server /app/proxy-server
42
-
43
- # Cấp quyền sở hữu thư mục và file cho user mới
44
- RUN chown -R appuser:appgroup /app
45
-
46
- # Chuyển sang user không phải root
47
- USER appuser
48
-
49
- # Expose the port the app runs on
50
- EXPOSE 7860
51
-
52
- # Set the entrypoint command to run the binary
53
- ENTRYPOINT ["/app/proxy-server"]
 
1
+ # Kéo (pull) image đã được build sẵn từ GitHub Container Registry.
2
+ # Hugging Face sẽ không cần build lại ứng dụng Go của bạn,
3
+ # chỉ cần sử dụng image này để chạy.
4
+ FROM ghcr.io/banquyy/go-proxy-app:latest