Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
148 lines (127 loc) · 6.06 KB
/
Copy pathDockerfile
File metadata and controls
148 lines (127 loc) · 6.06 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
###############################################################################
# Soliplex frontend client
###############################################################################
# Usage:
#
# 1. Build the image (from the frontend directory):
#
# $ docker build . -t soliplex-frontend:latest
#
# 2. Run the Soliplex front-end client:
#
# $ docker run --rm -p 9000:9000 soliplex-frontend:latest
#
# To cache-bust the web assets (see scripts/post-build-cache-bust.sh), pass a
# release tag or commit SHA when building:
#
# $ docker build . -t soliplex-frontend:latest \
# --build-arg RELEASE_HASH=$(git rev-parse --short HEAD)
#
# To build only the web tree, as an image for other images to 'COPY --from='
# (what .github/workflows/image.yaml publishes on each release):
#
# $ docker build . --target web -t soliplex-frontend-web:latest \
# --build-arg RELEASE_HASH=$(git rev-parse --short HEAD)
#
###############################################################################
###############################################################################
# Build stage
###############################################################################
# The web build is platform-independent static files, so build it on the
# builder's own platform: a multi-platform build then runs Flutter once, not
# under emulation for each target.
#
# Base images are pinned by digest (multi-platform index) so a rebuild of a
# release is reproducible; Dependabot's docker ecosystem bumps the digests.
FROM --platform=$BUILDPLATFORM ubuntu:noble@sha256:534baea6a22c03a63003dbc8dbe78fe34bc0d7e595d9a9dc9834884ff530eb55 AS builder
#------------------------------------------------------------------------------
# Install system utilities / prereqs.
#------------------------------------------------------------------------------
RUN apt-get update && \
apt-get install \
--no-install-recommends -y \
ca-certificates \
git \
curl \
wget \
unzip \
xz-utils \
jq && \
rm -rf /var/lib/apt/lists/*
#------------------------------------------------------------------------------
# Download and install flutter. The version comes from .fvmrc, which is also
# what CI reads; copy it alone so a version bump invalidates this layer and
# nothing earlier.
#------------------------------------------------------------------------------
COPY .fvmrc /tmp/.fvmrc
RUN export FLUTTER=flutter_linux_$(jq -r '.flutter' /tmp/.fvmrc)-stable.tar.xz && \
mkdir -p /opt && \
cd /opt && \
curl -fL -o $FLUTTER https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/$FLUTTER && \
tar xf $FLUTTER && \
rm $FLUTTER
#------------------------------------------------------------------------------
# Copy local source into the build context.
#------------------------------------------------------------------------------
COPY . /app
#------------------------------------------------------------------------------
# Build flutter web app. '--no-web-resources-cdn' bundles CanvasKit rather
# than loading it from Google's CDN. Text fonts still come from Google Fonts
# (the engine's 'fontFallbackBaseUrl'): the build bundles only MaterialIcons.
#------------------------------------------------------------------------------
ARG FLUTTER_BUILD_ARGS="--release --no-tree-shake-icons --no-web-resources-cdn"
RUN cd /app && \
export FLUTTER=/opt/flutter/bin/flutter && \
git config --global --add safe.directory /opt/flutter && \
$FLUTTER --disable-analytics && \
$FLUTTER clean && \
$FLUTTER pub get && \
$FLUTTER build web $FLUTTER_BUILD_ARGS
#------------------------------------------------------------------------------
# Optionally cache-bust the web assets. The hash has to come in as a build arg:
# .dockerignore excludes .git, so the build cannot derive it. Declared after
# the build so a new hash reruns only this step.
#------------------------------------------------------------------------------
ARG RELEASE_HASH=""
RUN if [ -n "$RELEASE_HASH" ]; then \
/app/scripts/post-build-cache-bust.sh /app/build/web; \
fi
###############################################################################
# Web stage — only the built web tree, at /build/web
###############################################################################
# Published as ghcr.io/soliplex/frontend-web, for images that serve the client
# with their own web server:
#
# COPY --from=ghcr.io/soliplex/frontend-web:<version> /build/web <dest>
#
FROM scratch AS web
COPY --from=builder /app/build/web /build/web
###############################################################################
# Dev stage — flutter web dev server with hot reload
###############################################################################
FROM builder AS dev
WORKDIR /app
ENV FLUTTER=/opt/flutter/bin/flutter
ENV PATH="/opt/flutter/bin:${PATH}"
EXPOSE 9000
# Source is bind-mounted at /app; pub get runs at startup to pick up changes.
# --web-port matches the exposed port; --web-hostname 0.0.0.0 makes it
# reachable from outside the container.
CMD git config --global --add safe.directory /opt/flutter && \
git config --global --add safe.directory /app && \
flutter pub get && \
flutter run -d web-server --web-port=9000 --web-hostname=0.0.0.0
###############################################################################
# Production stage with nginx
###############################################################################
FROM nginx:alpine@sha256:72aeb3308ef6cb3118242fb16389518923916dfa206e32d1a8377acc328b9870
#------------------------------------------------------------------------------
# Copy built flutter web app to nginx html directory
#------------------------------------------------------------------------------
COPY --from=builder /app/build/web /app/build/web
#------------------------------------------------------------------------------
# Copy nginx configuration
#------------------------------------------------------------------------------
COPY nginx/nginx.conf /etc/nginx/nginx.conf
EXPOSE 9000
CMD ["nginx", "-g", "daemon off;"]