Skip to content

Commit f404d19

Browse files
committed
chore: Add Dockerfiles for demo apps
Signed-off-by: Kemal Akkoyun <[email protected]>
1 parent f8d0bee commit f404d19

File tree

5 files changed

+144
-24
lines changed

5 files changed

+144
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ lint/dockerfile: hadolint
127127
elif [ -f /opt/homebrew/bin/hadolint ]; then \
128128
HADOLINT_CMD="/opt/homebrew/bin/hadolint"; \
129129
fi; \
130-
$$HADOLINT_CMD demo/grpc/client/Dockerfile demo/grpc/server/Dockerfile
130+
$$HADOLINT_CMD demo/grpc/client/Dockerfile demo/grpc/server/Dockerfile demo/http/client/Dockerfile demo/http/server/Dockerfile
131131

132132
lint/makefile: ## Lint Makefile
133133
lint/makefile: checkmake

demo/grpc/client/Dockerfile

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multi-stage Dockerfile for gRPC client with OpenTelemetry compile-time instrumentation
22
# Stage 1: Build the otel tool
3-
FROM golang:1.23-alpine AS otel-builder
3+
FROM golang:1.24-alpine AS otel-builder
44

55
WORKDIR /build
66

@@ -12,40 +12,31 @@ COPY go.mod go.sum ./
1212
COPY . .
1313

1414
# Build the otel tool
15-
RUN go build -o /otel ./cmd/otel
15+
RUN go build -o /otel ./tool/cmd
1616

1717
# Stage 2: Build the gRPC client with instrumentation
18-
FROM golang:1.23-alpine AS app-builder
18+
FROM golang:1.24-alpine AS app-builder
1919

2020
WORKDIR /app
2121

22-
# Install protobuf compiler and dependencies
23-
RUN apk add --no-cache git protobuf-dev protoc
24-
25-
# Install protoc-gen-go and protoc-gen-go-grpc
26-
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
27-
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
22+
# Install git for go mod download
23+
RUN apk add --no-cache git
2824

2925
# Copy the otel tool from previous stage
3026
COPY --from=otel-builder /otel /usr/local/bin/otel
3127

32-
# Copy demo app source
28+
# Copy both client and server to maintain the go.mod replace directive structure
29+
COPY demo/grpc/server /server
3330
COPY demo/grpc/client /app
3431

35-
# Generate protobuf code
36-
RUN mkdir -p pb && \
37-
protoc --go_out=pb --go_opt=paths=source_relative \
38-
--go-grpc_out=pb --go-grpc_opt=paths=source_relative \
39-
greeter.proto
40-
4132
# Download dependencies
4233
RUN go mod download
4334

4435
# Build the app with otel instrumentation
4536
RUN otel go build -o client .
4637

4738
# Stage 3: Runtime image
48-
FROM alpine:latest
39+
FROM alpine:3.21
4940

5041
# Install ca-certificates for TLS and timezone data
5142
RUN apk --no-cache add ca-certificates tzdata

demo/grpc/server/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multi-stage Dockerfile for gRPC server with OpenTelemetry compile-time instrumentation
22
# Stage 1: Build the otel tool
3-
FROM golang:1.23-alpine AS otel-builder
3+
FROM golang:1.24-alpine AS otel-builder
44

55
WORKDIR /build
66

@@ -12,19 +12,19 @@ COPY go.mod go.sum ./
1212
COPY . .
1313

1414
# Build the otel tool
15-
RUN go build -o /otel ./cmd/otel
15+
RUN go build -o /otel ./tool/cmd
1616

1717
# Stage 2: Build the gRPC server with instrumentation
18-
FROM golang:1.23-alpine AS app-builder
18+
FROM golang:1.24-alpine AS app-builder
1919

2020
WORKDIR /app
2121

2222
# Install protobuf compiler and dependencies
2323
RUN apk add --no-cache git protobuf-dev protoc
2424

2525
# Install protoc-gen-go and protoc-gen-go-grpc
26-
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
27-
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
26+
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.4 && \
27+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1
2828

2929
# Copy the otel tool from previous stage
3030
COPY --from=otel-builder /otel /usr/local/bin/otel
@@ -45,7 +45,7 @@ RUN go mod download
4545
RUN otel go build -o server .
4646

4747
# Stage 3: Runtime image
48-
FROM alpine:latest
48+
FROM alpine:3.21
4949

5050
# Install ca-certificates for TLS and timezone data
5151
RUN apk --no-cache add ca-certificates tzdata

demo/http/client/Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Multi-stage Dockerfile for HTTP client with OpenTelemetry compile-time instrumentation
2+
# Stage 1: Build the otel tool
3+
FROM golang:1.24-alpine AS otel-builder
4+
5+
WORKDIR /build
6+
7+
# Install build dependencies
8+
RUN apk add --no-cache git make gcc musl-dev
9+
10+
# Copy the entire project to build the otel tool
11+
COPY go.mod go.sum ./
12+
COPY . .
13+
14+
# Build the otel tool
15+
RUN go build -o /otel ./tool/cmd
16+
17+
# Stage 2: Build the HTTP client with instrumentation
18+
FROM golang:1.24-alpine AS app-builder
19+
20+
WORKDIR /app
21+
22+
# Install git for go mod download
23+
RUN apk add --no-cache git
24+
25+
# Copy the otel tool from previous stage
26+
COPY --from=otel-builder /otel /usr/local/bin/otel
27+
28+
# Copy HTTP client source
29+
COPY demo/http/client /app
30+
31+
# Download dependencies
32+
RUN go mod download
33+
34+
# Build the app with otel instrumentation
35+
RUN otel go build -o client .
36+
37+
# Stage 3: Runtime image
38+
FROM alpine:3.21
39+
40+
# Install ca-certificates for TLS and timezone data
41+
RUN apk --no-cache add ca-certificates tzdata
42+
43+
WORKDIR /app
44+
45+
# Copy the instrumented binary
46+
COPY --from=app-builder /app/client .
47+
48+
# Create non-root user
49+
RUN addgroup -g 1000 appuser && \
50+
adduser -D -u 1000 -G appuser appuser && \
51+
chown -R appuser:appuser /app
52+
53+
USER appuser
54+
55+
# Environment variables for OpenTelemetry
56+
ENV OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 \
57+
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
58+
OTEL_SERVICE_NAME=http-client \
59+
OTEL_RESOURCE_ATTRIBUTES="service.namespace=demo,service.version=1.0.0" \
60+
OTEL_LOG_LEVEL=info
61+
62+
ENTRYPOINT ["./client"]
63+
CMD ["-addr", "http://http-server:8080"]

demo/http/server/Dockerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Multi-stage Dockerfile for HTTP server with OpenTelemetry compile-time instrumentation
2+
# Stage 1: Build the otel tool
3+
FROM golang:1.24-alpine AS otel-builder
4+
5+
WORKDIR /build
6+
7+
# Install build dependencies
8+
RUN apk add --no-cache git make gcc musl-dev
9+
10+
# Copy the entire project to build the otel tool
11+
COPY go.mod go.sum ./
12+
COPY . .
13+
14+
# Build the otel tool
15+
RUN go build -o /otel ./tool/cmd
16+
17+
# Stage 2: Build the HTTP server with instrumentation
18+
FROM golang:1.24-alpine AS app-builder
19+
20+
WORKDIR /app
21+
22+
# Install git for go mod download
23+
RUN apk add --no-cache git
24+
25+
# Copy the otel tool from previous stage
26+
COPY --from=otel-builder /otel /usr/local/bin/otel
27+
28+
# Copy HTTP server source
29+
COPY demo/http/server /app
30+
31+
# Download dependencies
32+
RUN go mod download
33+
34+
# Build the app with otel instrumentation
35+
RUN otel go build -o server .
36+
37+
# Stage 3: Runtime image
38+
FROM alpine:3.21
39+
40+
# Install ca-certificates for TLS and timezone data
41+
RUN apk --no-cache add ca-certificates tzdata
42+
43+
WORKDIR /app
44+
45+
# Copy the instrumented binary
46+
COPY --from=app-builder /app/server .
47+
48+
# Create non-root user
49+
RUN addgroup -g 1000 appuser && \
50+
adduser -D -u 1000 -G appuser appuser && \
51+
chown -R appuser:appuser /app
52+
53+
USER appuser
54+
55+
# Expose HTTP port
56+
EXPOSE 8080
57+
58+
# Environment variables for OpenTelemetry
59+
ENV OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 \
60+
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
61+
OTEL_SERVICE_NAME=http-server \
62+
OTEL_RESOURCE_ATTRIBUTES="service.namespace=demo,service.version=1.0.0" \
63+
OTEL_LOG_LEVEL=info
64+
65+
ENTRYPOINT ["./server"]
66+
CMD ["-port", "8080"]

0 commit comments

Comments
 (0)