-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (59 loc) · 3.31 KB
/
Copy pathDockerfile
File metadata and controls
81 lines (59 loc) · 3.31 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Build stage
FROM golang:1.26-alpine AS builder
# Set up build arguments
ARG VERSION=dev
ARG COMMIT=unknown
# Set working directory
WORKDIR /app
# Install necessary packages for building (including gcc for CGO)
RUN apk update && apk --no-cache add git ca-certificates wget gcompat gcc musl-dev sqlite-dev
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy the source code including .git for submodule access
COPY . .
# Download third_party dependencies directly instead of using git submodules
# This is more reliable in cloud build environments
RUN mkdir -p third_party/iam-dataset/aws third_party/iam-dataset/azure third_party/iam-dataset/gcp && \
wget -O third_party/iam-dataset/aws/docs.json https://raw.githubusercontent.com/iann0036/iam-dataset/main/aws/docs.json && \
wget -O third_party/iam-dataset/aws/managed_policies.json https://raw.githubusercontent.com/iann0036/iam-dataset/main/aws/managed_policies.json && \
wget -O third_party/iam-dataset/azure/built-in-roles.json https://raw.githubusercontent.com/iann0036/iam-dataset/main/azure/built-in-roles.json && \
wget -O third_party/iam-dataset/azure/provider-operations.json https://raw.githubusercontent.com/iann0036/iam-dataset/main/azure/provider-operations.json && \
wget -O third_party/iam-dataset/gcp/role_permissions.json https://raw.githubusercontent.com/iann0036/iam-dataset/main/gcp/role_permissions.json && \
wget -O third_party/iam-dataset/gcp/predefined_roles.json https://raw.githubusercontent.com/iann0036/iam-dataset/main/gcp/predefined_roles.json
# Verify the required files are present
RUN ls -la third_party/iam-dataset/aws/ && ls -la third_party/iam-dataset/azure/ && ls -la third_party/iam-dataset/gcp/
# Build the application with CGO enabled for sqlite3 support
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
GOEXPERIMENT=jsonv2 CGO_ENABLED=1 GOOS=linux go build -a \
-ldflags "-X github.com/thand-io/agent/internal/common.Version=${VERSION} -X github.com/thand-io/agent/internal/common.GitCommit=${COMMIT}" \
-o bin/thand .
# Final stage
FROM alpine:3.20
LABEL org.opencontainers.image.source=https://github.com/thand-io/agent
LABEL org.opencontainers.image.description="Thand Agent - Open-source agent for AI-ready privilege access management (PAM) and just-in-time access (JIT) to cloud infrastructure, SaaS applications and local systems."
LABEL org.opencontainers.image.licenses=BSL-1.1
# Install ca-certificates for HTTPS calls
RUN apk update && apk --no-cache add ca-certificates gcompat
# Create a non-root user
RUN addgroup -S thand && adduser -S thand -G thand
# Set working directory
WORKDIR /app
# Copy the binary from builder stage
COPY --from=builder /app/bin/thand ./thand
# Copy configuration example file if it exists
COPY config.example.yaml ./
# Change ownership to non-root user
RUN chown -R thand:thand /app
# Switch to non-root user
USER thand
# Expose the default port (adjust if your server uses a different port)
EXPOSE 8080
# Health check (adjust the endpoint as needed)
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
ENV THAND_SERVER_PORT=8080
# Default command is to run the server
CMD ["./thand", "server"]