Skip to content

Commit fe48203

Browse files
authored
feat(cloud_hub): Add fly deployment config (#301)
Adds configuration for building a Docker container of the Cloud Hub and deploying to Fly.io
1 parent 660dccd commit fe48203

File tree

15 files changed

+511
-16
lines changed

15 files changed

+511
-16
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.dockerignore
22
Dockerfile
33
build/
4+
example/
45
.dart_tool/
56
.git/
67
.github/
78
.gitignore
89
.idea/
910
.packages
11+
build.sh
Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,65 @@
11
FROM dart:stable AS build
22

3+
# Set the dependency versions
4+
ARG FLY_VERSION=0.3.98
5+
ARG YQ_VERSION=4.45.1
6+
7+
# Download and install flyctl based on architecture
8+
RUN arch=$(uname -m) && \
9+
if [ "$arch" = "x86_64" ]; then \
10+
curl -L "https://github.com/superfly/flyctl/releases/download/v${FLY_VERSION}/flyctl_${FLY_VERSION}_Linux_x86_64.tar.gz" -o flyctl.tar.gz; \
11+
curl -L "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64" -o /usr/local/bin/yq; \
12+
elif [ "$arch" = "aarch64" ]; then \
13+
curl -L "https://github.com/superfly/flyctl/releases/download/v${FLY_VERSION}/flyctl_${FLY_VERSION}_Linux_arm64.tar.gz" -o flyctl.tar.gz; \
14+
curl -L "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_arm64" -o /usr/local/bin/yq; \
15+
else \
16+
echo "Unsupported architecture: $arch" && exit 1; \
17+
fi && \
18+
mkdir -p /tmp/flyctl && \
19+
tar -xzf flyctl.tar.gz -C /tmp/flyctl && \
20+
mv /tmp/flyctl/flyctl /usr/local/bin/ && \
21+
chmod +x /usr/local/bin/flyctl && \
22+
chmod +x /usr/local/bin/yq && \
23+
rm -rf flyctl.tar.gz /tmp/flyctl
24+
25+
# Install sqlite3
326
WORKDIR /app
4-
COPY pubspec.* ./
27+
RUN apt update && apt install -y libsqlite3-0
28+
RUN cp $(find / -name libsqlite3.so* -type f | head -n1) /app/libsqlite3.so
29+
30+
# Fix pub cache
31+
WORKDIR /app
32+
COPY tool tool
33+
WORKDIR /app/tool
534
RUN dart pub get
35+
RUN dart run fix_pub_cache.dart
636

7-
COPY . .
8-
RUN dart compile exe bin/cloud_hub.dart -o bin/cloud_hub
37+
# Copy repo
38+
WORKDIR /app
39+
COPY pubspec.* ./
40+
COPY apps/cli apps/cli
41+
COPY packages packages
42+
COPY services services
43+
44+
WORKDIR /app/packages/celest_auth
45+
RUN yq eval 'del(.environment.flutter)' -i pubspec.yaml
46+
WORKDIR /app/packages/celest_core
47+
RUN yq eval 'del(.environment.flutter)' -i pubspec.yaml
48+
WORKDIR /app/packages/celest
49+
RUN yq eval 'del(.environment.flutter)' -i pubspec.yaml
50+
51+
WORKDIR /app/services/celest_cloud_hub
52+
RUN dart pub get
53+
RUN dart compile exe bin/cloud_hub.dart -o /app/cloud_hub
954

1055
FROM scratch
1156
COPY --from=build /runtime/ /
12-
COPY --from=build /app/bin/cloud_hub /app/bin/
57+
COPY --from=build /app/cloud_hub /app/cloud_hub
58+
COPY --from=build /app/libsqlite3.so /app/libsqlite3.so
59+
COPY --from=build /usr/local/bin/flyctl /usr/local/bin/fly
1360

1461
ENV PORT=8080
1562
EXPOSE $PORT
1663

17-
CMD ["/app/bin/cloud_hub"]
64+
WORKDIR /tmp
65+
CMD ["/app/cloud_hub"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
include: package:celest_lints/app.yaml
2+
23
analyzer:
34
errors:
45
avoid_print: ignore
56
implementation_imports: ignore
7+
exclude:
8+
- lib/src/proto

services/celest_cloud_hub/bin/cloud_hub.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:celest_cloud_hub/src/database/cloud_hub_database.dart';
1515
import 'package:celest_cloud_hub/src/database/db_functions.dart';
1616
import 'package:celest_cloud_hub/src/gateway/gateway.dart';
1717
import 'package:celest_cloud_hub/src/project.dart';
18+
import 'package:celest_cloud_hub/src/services/health_service.dart';
1819
import 'package:celest_cloud_hub/src/services/operations_service.dart';
1920
import 'package:celest_cloud_hub/src/services/project_environments_service.dart';
2021
import 'package:celest_core/_internal.dart';
@@ -25,6 +26,12 @@ Future<void> main() async {
2526
context.logger.level = Level.ALL;
2627
context.logger.onRecord.listen((record) {
2728
print('${record.level.name}: ${record.time}: ${record.message}');
29+
if (record.error != null) {
30+
print(record.error);
31+
}
32+
if (record.stackTrace != null) {
33+
print(record.stackTrace);
34+
}
2835
});
2936
context.put(ContextKey.project, project);
3037
context.put(
@@ -55,7 +62,11 @@ Future<void> main() async {
5562
);
5663

5764
final server = grpc.Server.create(
58-
services: [ProjectEnvironmentsService(), OperationsService(db, authorizer)],
65+
services: [
66+
ProjectEnvironmentsService(),
67+
OperationsService(db, authorizer),
68+
HealthService(),
69+
],
5970
interceptors: [
6071
(call, method) async {
6172
try {

services/celest_cloud_hub/build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# This script builds the Celest Cloud Hub Docker image.
4+
#
5+
# Usage:
6+
# ./build.sh [--push]
7+
8+
REPO_ROOT=$(git rev-parse --show-toplevel)
9+
10+
docker build \
11+
--platform linux/amd64,linux/arm64 \
12+
-t cloud-hub:latest \
13+
-t celestdev/cloud-hub:latest \
14+
-f "$REPO_ROOT/services/celest_cloud_hub/Dockerfile" \
15+
"$REPO_ROOT"
16+
17+
if [[ "$1" == "--push" ]]; then
18+
docker push celestdev/cloud-hub:latest
19+
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# This script deploys the Celest Cloud Hub to Fly.io
4+
#
5+
# Usage:
6+
# ./deploy.sh [--build]
7+
8+
if [[ "$1" == "--build" ]]; then
9+
./build.sh --push
10+
fi
11+
12+
fly deploy \
13+
--update-only \
14+
--config ./fly.yaml

services/celest_cloud_hub/fly.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# fly.yaml app configuration file generated for cloud-hub on 2025-04-07T11:42:36-07:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app: cloud-hub
7+
primary_region: lax
8+
9+
build:
10+
image: celestdev/cloud-hub:latest
11+
12+
env:
13+
CLOUD_HUB_DATABASE_HOST: "file::memory:"
14+
15+
http_service:
16+
internal_port: 8080
17+
force_https: true
18+
auto_stop_machines: true
19+
auto_start_machines: true
20+
min_machines_running: 0
21+
22+
processes:
23+
- app
24+
25+
vm:
26+
- size: performance-8x

services/celest_cloud_hub/lib/src/gateway/gateway.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:celest_cloud_auth/src/model/route_map.dart';
55
import 'package:celest_cloud_hub/src/gateway/gateway_handler.dart';
66
import 'package:celest_cloud_hub/src/model/type_registry.dart';
77
import 'package:celest_cloud_hub/src/project.dart';
8+
import 'package:celest_cloud_hub/src/services/health_service.dart';
89
import 'package:celest_cloud_hub/src/services/operations_service.dart';
910
import 'package:celest_core/celest_core.dart';
1011
import 'package:grpc/grpc.dart' as grpc;
@@ -37,7 +38,7 @@ final class Gateway {
3738
clientChannel: clientChannel,
3839
routeMap: routeMap,
3940
);
40-
router.mount('/v1alpha1/', grpcHandler.handle);
41+
router.mount('/', grpcHandler.handle);
4142

4243
return Gateway._(
4344
const shelf.Pipeline()
@@ -71,6 +72,7 @@ final class Gateway {
7172
final class _GrpcHandler {
7273
_GrpcHandler({required this.routeMap, required this.clientChannel}) {
7374
addTypes(OperationsService.apiId, OperationsService.$handlers);
75+
addTypes(HealthService.apiId, HealthService.$handlers);
7476
}
7577

7678
final grpc.ClientChannel clientChannel;

services/celest_cloud_hub/lib/src/project.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:celest_ast/celest_ast.dart';
2+
import 'package:celest_cloud_hub/src/services/health_service.dart';
23
import 'package:celest_cloud_hub/src/services/operations_service.dart';
34
import 'package:celest_cloud_hub/src/services/project_environments_service.dart';
45
import 'package:celest_core/_internal.dart';
@@ -14,5 +15,6 @@ final ResolvedProject project = ResolvedProject(
1415
apis: {
1516
OperationsService.apiId: OperationsService.api,
1617
ProjectEnvironmentsService.apiId: ProjectEnvironmentsService.api,
18+
HealthService.apiId: HealthService.api,
1719
},
1820
);

services/celest_cloud_hub/lib/src/proto/health/v1/health.pb.dart

Lines changed: 122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)