-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
125 lines (101 loc) · 3.37 KB
/
Dockerfile
File metadata and controls
125 lines (101 loc) · 3.37 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
# 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 ubuntu:22.04 AS proto-builder
# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
ARG PROTOC_VERSION=21.9
ARG GO_VERSION=1.24.10
# Configure apt and install packages
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
#
# Install essential development tools
build-essential \
ca-certificates \
git \
unzip \
wget \
#
# Detect architecture for downloads
&& ARCH_SUFFIX=$(case "$(uname -m)" in \
x86_64) echo "x86_64" ;; \
aarch64) echo "aarch_64" ;; \
*) echo "x86_64" ;; \
esac) \
&& GOARCH_SUFFIX=$(case "$(uname -m)" in \
x86_64) echo "amd64" ;; \
aarch64) echo "arm64" ;; \
*) echo "amd64" ;; \
esac) \
#
# Install Protocol Buffers compiler
&& wget -O protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${ARCH_SUFFIX}.zip \
&& unzip protoc.zip -d /usr/local \
&& rm protoc.zip \
&& chmod +x /usr/local/bin/protoc \
#
# Install Go
&& wget -O go.tar.gz https://go.dev/dl/go${GO_VERSION}.linux-${GOARCH_SUFFIX}.tar.gz \
&& tar -C /usr/local -xzf go.tar.gz \
&& rm go.tar.gz \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Set up Go environment
ENV GOROOT=/usr/local/go
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
# Install protoc Go tools and plugins
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Set working directory
WORKDIR /build
# Copy proto sources and generator script
COPY proto.sh .
COPY pkg/proto/ pkg/proto/
# Generate protobuf files.
RUN chmod +x proto.sh && \
./proto.sh
# ----------------------------------------
# Stage 2: gRPC Server Builder
# ----------------------------------------
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG TARGETOS
ARG TARGETARCH
ARG GOOS=$TARGETOS
ARG GOARCH=$TARGETARCH
ARG CGO_ENABLED=0
# Set working directory
WORKDIR /build
# Copy and download the dependencies for application
COPY go.mod go.sum ./
RUN go mod download
# Copy application code
COPY . .
# Copy generated protobuf files from stage 1
COPY --from=proto-builder /build/pkg/pb pkg/pb
# Build the Go application binary for the target OS and architecture
RUN go build -v -modcacherw -o /output/$TARGETOS/$TARGETARCH/challenge-assignment-plugin-server-go .
# ----------------------------------------
# Stage 3: Runtime Container
# ----------------------------------------
FROM alpine:3.22
# Set the value for the target OS and architecture.
ARG TARGETOS
ARG TARGETARCH
# Set working directory.
WORKDIR /app
# Copy build from builder stage
COPY --from=builder /output/$TARGETOS/$TARGETARCH/challenge-assignment-plugin-server-go challenge-assignment-plugin-server-go
# Plugin Arch gRPC Server Port
EXPOSE 6565
# Prometheus /metrics Web Server Port
EXPOSE 8080
# Entrypoint
CMD [ "/app/challenge-assignment-plugin-server-go" ]