Repository navigation
Expand file tree
/
Copy pathDockerfile.agent
More file actions
67 lines (52 loc) · 1.98 KB
/
Copy pathDockerfile.agent
File metadata and controls
67 lines (52 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Production Dockerfile for GoLangGraph Agent
FROM golang:1.25.13-alpine AS builder
# Set working directory
WORKDIR /app
# Install dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies. The public Go proxy occasionally drops an HTTP/2
# stream; retry the deterministic module download before failing the build.
RUN for attempt in 1 2 3; do \
go mod download && exit 0; \
if [ "$attempt" = 3 ]; then exit 1; fi; \
sleep "$attempt"; \
done
# Copy source code
COPY . .
# Build the binary
ARG VERSION=production
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-w -s -X main.version=${VERSION}" \
-a -installsuffix cgo \
-o golanggraph-agent \
./cmd/golanggraph
# Production stage
FROM alpine:3.20.3
# Install ca-certificates for HTTPS requests and create non-root user
RUN apk --no-cache add ca-certificates tzdata && \
addgroup -g 1001 -S golanggraph && \
adduser -u 1001 -S golanggraph -G golanggraph
WORKDIR /app
# Copy the binary from builder stage
COPY --from=builder /app/golanggraph-agent .
# Create the directories the server may use. These were previously COPY'd from
# configs/ and static/, which do not exist in the repository, so this image
# could not be built at all. Mount or bake in real configuration as needed.
RUN mkdir -p ./configs ./static ./logs ./data && \
chown -R golanggraph:golanggraph /app
# Switch to non-root user
USER golanggraph
# Expose port
EXPOSE 8080
# Health check.
#
# Probes the server's own endpoint: the container is healthy when it is
# serving. A local dependency scan is a different question and would mark a
# perfectly serving container unhealthy whenever an optional service is absent.
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD ["./golanggraph-agent", "health", "--server", "http://127.0.0.1:8080"]
# Run the agent
ENTRYPOINT ["./golanggraph-agent"]
CMD ["serve", "--host", "0.0.0.0", "--port", "8080"]