Skip to content

Commit caa76b1

Browse files
authored
chore(cloud_hub): Updates to use distroless base images (#330)
- Updates cloud_hub to use distroless base images - Updates distroless Dart to use the `base` variant which includes ca-certs
1 parent 3fc4047 commit caa76b1

File tree

6 files changed

+22
-62
lines changed

6 files changed

+22
-62
lines changed

apps/distroless/bin/list_sdks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'dart:convert';
33
import 'package:distroless/src/sdk/sdk_manager.dart';
44
import 'package:pub_semver/pub_semver.dart';
55

6-
final Version minDartSdkVersion = Version(3, 5, 0);
6+
final Version minDartSdkVersion = Version(3, 7, 0);
77
final Version minFlutterSdkVersion = Version(3, 29, 0);
88

99
/// The last version of Flutter published under the old engine repo.

apps/distroless/dart/build/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ RUN CFLAGS='-DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1' \
117117
&& make install DESTDIR=/sqlite_install
118118

119119
# Copy just the parts of the Dart SDK we need to build an AOT snapshot
120-
FROM gcr.io/distroless/static-debian${DEBIAN_VERSION}:nonroot AS builder
120+
FROM gcr.io/distroless/static-debian${DEBIAN_VERSION} AS builder
121121

122122
COPY --from=sdk /runtime/ /
123123
COPY --from=sdk /usr/lib/dart/bin/utils/gen_snapshot /usr/lib/dart/bin/utils/gen_snapshot
@@ -127,7 +127,7 @@ ENTRYPOINT ["/usr/lib/dart/bin/utils/gen_snapshot", "--snapshot_kind=app-aot-elf
127127
CMD ["--elf=/app/main.aot", "/app/main.aot.dill"]
128128

129129
# Copy the Dart runtime and AOT runtime into a minimal runtime image
130-
FROM gcr.io/distroless/static-debian${DEBIAN_VERSION}:nonroot AS runtime
130+
FROM gcr.io/distroless/base-debian${DEBIAN_VERSION} AS runtime
131131

132132
COPY --from=dart /runtime/ /
133133
COPY --from=dart /usr/lib/dart/bin/dartaotruntime /usr/lib/dart/bin/dartaotruntime

apps/distroless/flutter/build/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ RUN sed -i 's/libdart_jit/libdart_aotruntime_product/g' shell/testing/BUILD.gn
3636
WORKDIR /flutter/engine/src
3737
RUN ./flutter/bin/et build --no-rbe --config=host_release
3838

39-
FROM gcr.io/distroless/cc-debian${DEBIAN_VERSION}:nonroot AS engine
39+
FROM gcr.io/distroless/cc-debian${DEBIAN_VERSION} AS engine
4040

4141
COPY --from=build-engine /flutter/engine/src/out/host_release /engine
4242
ENV DART_SDK="/flutter/engine/dart-sdk"
4343

4444
WORKDIR /engine
4545
ENV LD_LIBRARY_PATH="/engine"
4646

47-
FROM gcr.io/distroless/cc-debian${DEBIAN_VERSION}:nonroot AS builder
47+
FROM gcr.io/distroless/cc-debian${DEBIAN_VERSION} AS builder
4848

4949
COPY --from=engine /engine/dart-sdk/bin/utils/gen_snapshot /usr/lib/dart/bin/utils/gen_snapshot
5050
COPY --from=engine /engine/dart-sdk/bin/utils/gen_snapshot.sym /usr/lib/dart/bin/utils/gen_snapshot.sym
Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,4 @@
1-
# Builds SQLite from Source
2-
#
3-
# The version shipped with apt is very outdated (3.40.1). This is the only way
4-
# it seems to get anything newer.
5-
FROM debian:bookworm-slim AS sqlite
6-
7-
# Install build dependencies
8-
RUN apt-get update && apt-get install -y \
9-
build-essential \
10-
tcl-dev \
11-
libreadline-dev \
12-
wget \
13-
unzip \
14-
&& rm -rf /var/lib/apt/lists/*
15-
16-
# Set up build directory
17-
WORKDIR /sqlite_build
18-
19-
# Download the latest SQLite source
20-
ARG SQLITE_VERSION=3490100
21-
RUN wget https://www.sqlite.org/2025/sqlite-autoconf-${SQLITE_VERSION}.tar.gz \
22-
&& tar xzf sqlite-autoconf-${SQLITE_VERSION}.tar.gz \
23-
&& cd sqlite-autoconf-${SQLITE_VERSION}
24-
25-
# Build SQLite with default options
26-
WORKDIR /sqlite_build/sqlite-autoconf-${SQLITE_VERSION}
27-
RUN CFLAGS='-DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1' \
28-
./configure --prefix=/usr \
29-
--enable-threadsafe \
30-
&& make -j$(nproc) \
31-
&& make install DESTDIR=/sqlite_install
32-
33-
FROM dart:stable AS build
1+
FROM dart:3.7.2 AS build
342

353
# Set the dependency versions
364
ARG FLY_VERSION=0.3.98
@@ -77,29 +45,14 @@ RUN yq eval 'del(.environment.flutter)' -i pubspec.yaml
7745

7846
WORKDIR /app/services/celest_cloud_hub
7947
RUN dart pub get
80-
RUN dart compile exe bin/cloud_hub.dart -o /app/cloud_hub
81-
82-
FROM debian:bookworm-slim
83-
84-
# Configure SQLite
85-
COPY --from=sqlite /sqlite_install /
86-
87-
# Install dependencies
88-
RUN apt-get update && apt-get install -y \
89-
ca-certificates \
90-
libreadline8 \
91-
&& rm -rf /var/lib/apt/lists/*
48+
RUN dart compile aot-snapshot bin/cloud_hub.dart -o /app/main.aot
9249

93-
# Verify SQLite installation
94-
RUN sqlite3 --version && \
95-
ldconfig && \
96-
ldd $(which sqlite3)
50+
FROM celestdev/dart-runtime:3.7.2
9751

9852
COPY --from=build /usr/local/bin/flyctl /usr/local/bin/flyctl
99-
COPY --from=build /app/cloud_hub /app/cloud_hub
53+
COPY --from=build /app/main.aot /app/main.aot
10054

10155
ENV PORT=8080
10256
EXPOSE $PORT
10357

10458
WORKDIR /tmp
105-
CMD ["/app/cloud_hub"]

services/celest_cloud_hub/bin/cloud_hub.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,5 @@ Future<void> _run() async {
182182
await gateway.close();
183183
await db.close();
184184
context.logger.fine('Server stopped');
185+
exit(0);
185186
}

services/celest_cloud_hub/lib/src/deploy/fly/fly_deployment_engine.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,18 @@ final class FlyDeploymentEngine {
188188
}
189189

190190
String _generateFlyAppName() {
191-
var projectId = projectAst.projectId;
192-
// Restricted to 30 characters total.
193-
if (projectId.length > 24) {
194-
projectId = projectId.substring(0, 24);
191+
var projectId = projectAst.projectId.toLowerCase();
192+
193+
// Only lowercase letters, numbers, and dashes are allowed.
194+
projectId = projectId.replaceAll(RegExp(r'[^a-z0-9]'), '-');
195+
196+
// Restricted to 63 characters total.
197+
final suffix = _randomSuffix;
198+
final maxLength = 63 - suffix.length;
199+
if (projectId.length > maxLength) {
200+
projectId = projectId.substring(0, maxLength);
195201
}
196-
return '$projectId-$_randomSuffix';
202+
return '$projectId-$suffix';
197203
}
198204

199205
Future<ProjectEnvironmentState> _deployProjectEnvironment() async {
@@ -244,7 +250,7 @@ final class FlyDeploymentEngine {
244250
// Deploy using `flyctl deploy`
245251
await _withTempDirectory((dir) async {
246252
// Write the kernel file to disk
247-
final kernelFile = dir.childFile('celest.aot.dill');
253+
final kernelFile = dir.childFile('main.aot.dill');
248254
await kernelFile.writeAsBytes(kernelAsset);
249255

250256
// Write celest.json to disk

0 commit comments

Comments
 (0)