-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.client
More file actions
73 lines (56 loc) · 2.66 KB
/
Dockerfile.client
File metadata and controls
73 lines (56 loc) · 2.66 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
################################################################################
# BUILDER IMAGE
################################################################################
FROM golang:1.24 AS builder
ARG VERSION
ARG TARGETPLATFORM
ARG BUILDPLATFORM
# ------------------------------------------------------------------------------
# Define and create working directory
# ------------------------------------------------------------------------------
ENV APP_HOME=/app
RUN mkdir -p ${APP_HOME}
WORKDIR ${APP_HOME}
# ------------------------------------------------------------------------------
# Copy source code
# ------------------------------------------------------------------------------
COPY . .
# ------------------------------------------------------------------------------
# Build client
# ------------------------------------------------------------------------------
# Set target architecture based on TARGETPLATFORM
RUN case "$TARGETPLATFORM" in \
"linux/amd64") export GOARCH=amd64 ;; \
"linux/arm64") export GOARCH=arm64 ;; \
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac && \
CGO_ENABLED=0 GOOS=linux GOARCH=$GOARCH go build -a -o /outerspace-client \
-ldflags "-s -w -X main.Version=${VERSION} -X main.BuildTime=$(TZ=UTC date +%Y-%m-%dT%H:%M:%S%z)" \
./cmd/client
################################################################################
# RELEASE IMAGE
################################################################################
FROM debian:bookworm-slim
# ------------------------------------------------------------------------------
# Install persistent dependencies
# ------------------------------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# ------------------------------------------------------------------------------
# Define working directory & user
# ------------------------------------------------------------------------------
ENV APP_HOME=/app
ARG APP_USER=1001
WORKDIR ${APP_HOME}
# ------------------------------------------------------------------------------
# Copy built application
# ------------------------------------------------------------------------------
COPY --from=builder --chown=${APP_USER} /outerspace-client ./outerspace-client
RUN chmod +x ./outerspace-client
# ------------------------------------------------------------------------------
# Define user, exposed ports, additional env vars, entrypoint and cmd
# ------------------------------------------------------------------------------
USER ${APP_USER}
CMD ["/app/outerspace-client"]