-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
153 lines (107 loc) · 3.56 KB
/
Dockerfile
File metadata and controls
153 lines (107 loc) · 3.56 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright (c) 2025 AccelByte Inc. All Rights Reserved.
# This is licensed software from AccelByte Inc, for limitations
# and restrictions contact your company contract manager.
# ----------------------------------------
# Stage 1: Protoc Code Generation
# ----------------------------------------
FROM --platform=$BUILDPLATFORM rvolosatovs/protoc:4.1.0 AS proto-builder
# Set working directory.
WORKDIR /build
# Copy proto sources and generator script.
COPY proto.sh .
COPY proto/ proto/
# Make script executable and run it.
RUN chmod +x proto.sh && \
./proto.sh
# ----------------------------------------
# Stage 2: gRPC Gateway Builder
# ----------------------------------------
FROM --platform=$BUILDPLATFORM golang:1.24 AS grpc-gateway-builder
ARG TARGETOS
ARG TARGETARCH
ARG GOOS=$TARGETOS
ARG GOARCH=$TARGETARCH
ARG CGO_ENABLED=0
# Set working directory.
WORKDIR /build
# Copy gateway go module files.
COPY gateway/go.mod gateway/go.sum ./
# Download dependencies.
RUN go mod download
# Copy application code.
COPY gateway/ .
# Copy generated protobuf files from stage 1.
RUN rm -rf pkg/pb
COPY --from=proto-builder /build/gateway/pkg/pb ./pkg/pb
# Build application code.
RUN go build -v -o /output/$TARGETOS/$TARGETARCH/grpc_gateway .
# ----------------------------------------
# Stage 3: gRPC Server Builder
# ----------------------------------------
FROM ubuntu:22.04 AS grpc-server-builder
ARG TARGETOS
ARG TARGETARCH
# Keeps Python from generating .pyc files in the container.
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging.
ENV PYTHONUNBUFFERED=1
# Install Python.
RUN apt update && \
apt install -y --no-install-recommends \
python3-venv && \
apt clean && \
rm -rf /var/lib/apt/lists/*
RUN useradd user
# Set working directory.
WORKDIR /build
# Create and activate virtual environment.
RUN python3 -m venv venv
ENV PATH="/build/venv/bin:$PATH"
# Install Python dependencies.
COPY requirements.txt .
RUN python3 -m pip install \
--no-cache-dir \
--requirement requirements.txt
# Copy apidocs code from stage 1.
COPY --from=proto-builder /build/gateway/apidocs ./apidocs
# Copy gateway code from stage 2.
COPY --from=grpc-gateway-builder /output/$TARGETOS/$TARGETARCH/grpc_gateway ./
# Copy other gateway code.
COPY gateway/third_party third_party/
# Copy application code.
COPY src/ .
# Copy generated protobuf files from stage 1.
COPY --from=proto-builder /build/src/ .
# Copy entrypoint script.
COPY wrapper.sh .
RUN chmod +x wrapper.sh
# Fix up python3 symlink for use in chiseled Ubuntu.
RUN ln -sf /usr/bin/python3 /build/venv/bin/python3
# ----------------------------------------
# Stage 4: Runtime Container
# ----------------------------------------
FROM ubuntu/python:3.10-22.04_stable
# Keeps Python from generating .pyc files in the container.
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging.
ENV PYTHONUNBUFFERED=1
# Set working directory.
WORKDIR /app
# Copy build from stage 2.
COPY --from=grpc-server-builder /usr/bin/bash /usr/bin/bash
COPY --from=grpc-server-builder /usr/bin/kill /usr/bin/kill
COPY --from=grpc-server-builder /usr/bin/sleep /usr/bin/sleep
COPY --from=grpc-server-builder /etc/passwd /etc/passwd
COPY --from=grpc-server-builder /etc/group /etc/group
COPY --from=grpc-server-builder /build/ .
USER user
# Activate virtual environment.
ENV PATH="/app/venv/bin:$PATH"
# Plugin Arch gRPC Server Port.
EXPOSE 6565
# gRPC Gateway Port.
EXPOSE 8000
# Prometheus /metrics Web Server Port.
EXPOSE 8080
# Entrypoint.
ENTRYPOINT ["bash", "/app/wrapper.sh"]