Skip to content

Commit 2df1ddb

Browse files
committed
Add Dockerfile
1 parent 239bfc8 commit 2df1ddb

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ---- Build stage ----
2+
FROM golang:1.24-alpine AS builder
3+
4+
# Install CA certificates (needed for HTTPS requests)
5+
RUN apk add --no-cache ca-certificates
6+
7+
WORKDIR /app
8+
9+
COPY go.mod .
10+
RUN go mod download
11+
12+
COPY main.go .
13+
14+
# Build static binary
15+
RUN CGO_ENABLED=0 GOOS=linux go build -o proxy .
16+
17+
# ---- Runtime stage ----
18+
FROM scratch
19+
20+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
21+
COPY --from=builder /app/proxy /proxy
22+
23+
# Run proxy
24+
ENTRYPOINT ["/proxy"]

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module myproxy
2+
3+
go 1.24

main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ func callAndLogError(f func() error) {
140140
}
141141

142142
func main() {
143+
port := os.Getenv("PORT")
144+
if port == "" {
145+
port = "8080"
146+
}
147+
143148
server := &http.Server{
144-
Addr: ":8080", // listen on port 8080
149+
Addr: ":" + port, // listen on port 8080
145150
Handler: http.HandlerFunc(HandleProxy),
146151
}
147152

0 commit comments

Comments
 (0)