Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (68 loc) · 3.34 KB
/
Copy pathDockerfile
File metadata and controls
84 lines (68 loc) · 3.34 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
82
83
84
# ----------------------------------------
# Stage 1: Build Application
# ----------------------------------------
FROM golang:1.27-alpine AS builder
# Install build tools and dependencies
RUN apk add --no-cache git gcc musl-dev make protoc protobuf protobuf-dev
# Install required Go tools (pinned versions)
RUN go install github.com/google/wire/cmd/wire@v0.7.0 && \
go install go.uber.org/mock/mockgen@latest && \
go install github.com/swaggo/swag/cmd/swag@v1.16.6 && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.12 && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest && \
go install github.com/favadi/protoc-go-inject-tag@latest
# Set working directory and enable module caching
WORKDIR /app
ENV GOPATH=/go
RUN mkdir -p /go/pkg/mod && chmod -R 777 /go
# Copy dependency files and download modules
COPY go.mod go.sum Makefile ./
RUN go mod download
# Copy source code and build
COPY . .
ARG APP_VERSION=
ARG APP_GIT_COMMIT=
ARG APP_BUILD_TIME=
RUN make generate
RUN make build-docker-with-tag APP_VERSION=${APP_VERSION} APP_GIT_COMMIT=${APP_GIT_COMMIT} APP_BUILD_TIME=${APP_BUILD_TIME}
# ----------------------------------------
# Stage 2: Runtime Image
# ----------------------------------------
FROM alpine:3.21
# Install minimal runtime dependencies and healthcheck tools
RUN apk add --no-cache ca-certificates tzdata && \
apk add --no-cache curl wget && \
# Install grpcurl - adjust version and architecture as needed
GRPCURL_VERSION=1.9.3 && \
wget "https://github.com/fullstorydev/grpcurl/releases/download/v${GRPCURL_VERSION}/grpcurl_${GRPCURL_VERSION}_linux_x86_64.tar.gz" -O /tmp/grpcurl.tar.gz && \
tar -xzf /tmp/grpcurl.tar.gz -C /usr/local/bin grpcurl && \
rm /tmp/grpcurl.tar.gz && \
update-ca-certificates
# Create non-root user and group
ARG APP_USER=resik-user
ARG APP_GROUP=resik-group
ARG APP_UID=15001
ARG APP_GID=15001
RUN addgroup -g ${APP_GID} -S ${APP_GROUP} && \
adduser -u ${APP_UID} -S -D -H -G ${APP_GROUP} ${APP_USER} && \
mkdir -p /opt/resik/app && \
chown -R ${APP_USER}:${APP_GROUP} /opt/resik
WORKDIR /opt/resik
# Copy artifacts from builder stage
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /app/resik .
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /app/app/rest/docs ./app/rest/docs
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /app/static ./static
# Copy .proto files needed for grpcurl health checks
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /app/app/grpc/handler/health/health.proto ./app/grpc/handler/health/health.proto
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /app/core/common/status.proto ./core/common/status.proto
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /app/core/health/response/healthz.proto ./core/health/response/healthz.proto
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /app/core/health/response/readyz.proto ./core/health/response/readyz.proto
# Add OCI labels for GitHub Package linking.
LABEL org.opencontainers.image.source="https://github.com/dedyf5/resik" \
org.opencontainers.image.title="Resik" \
org.opencontainers.image.description="Clean Architecture implementation in Golang for building REST and gRPC applications." \
org.opencontainers.image.licenses="MIT"
# Switch to non-root user and set entrypoint
USER ${APP_USER}
EXPOSE 8081 8071
ENTRYPOINT ["./resik"]