Compare commits

..

4 Commits

Author SHA1 Message Date
史悦
862304ad31 重写 Dockerfile 2025-08-13 10:32:54 +08:00
史悦
0563c4b4c3 创建了 go.mod 文件。
修改了 Dockerfile 以在构建期间复制 go.mod 并整理依赖。
2025-08-13 10:22:20 +08:00
史悦
337952dc1f Merge branch 'master' of https://git.01061220.xyz/shiyue/gemini-antiblock 2025-08-13 10:15:38 +08:00
史悦
452fa4c2f4 Initial commit 2025-08-13 10:12:12 +08:00
3 changed files with 34 additions and 19 deletions

View File

@@ -1,34 +1,40 @@
# Stage 1: Build the Go binary
# Stage 1: Build the application
# Use a specific version of the golang alpine image for reproducibility
FROM golang:1.22-alpine AS builder
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
# COPY go.mod go.sum ./
# RUN go mod download
# Copy go.mod and go.sum files to leverage Docker cache
COPY go.mod ./
# The go.sum file is not present, but it's a good practice to copy it if it were.
# COPY go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod file is not changed
RUN go mod download
# Copy the source code into the container
COPY main.go .
COPY . .
# Build the Go app
# CGO_ENABLED=0 is needed for a static build
# GOOS=linux is to specify the target OS
# -a installs all packages to be rebuilt
# -installsuffix cgo is used with CGO_ENABLED=0
# -o main specifies the output file name
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
# Build the Go application as a static binary
# -ldflags="-w -s" strips debug information, reducing the binary size
# CGO_ENABLED=0 is crucial for creating a static binary that can run in a minimal container like alpine
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags="-w -s" -o /gemini-proxy .
# Stage 2: Create the final, minimal image
# Stage 2: Create the final, small image
FROM alpine:latest
WORKDIR /root/
# Create a non-root user and group for security
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/main .
# Copy the pre-built binary from the builder stage
COPY --from=builder /gemini-proxy /gemini-proxy
# Expose port 8080 to the outside world
# Expose port 8080, which the application listens on
EXPOSE 8080
# Command to run the executable
CMD ["./main"]
# Switch to the non-root user
USER appuser
# The command to run when the container starts
CMD ["/gemini-proxy"]

6
compose.yaml Normal file
View File

@@ -0,0 +1,6 @@
services:
gemini-proxy:
build: .
ports:
- "9090:8080"
restart: always

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module gemini-proxy
go 1.22