diff --git a/packages/shorebird_code_push_api/.dockerignore b/packages/shorebird_code_push_api/.dockerignore new file mode 100644 index 00000000..5ff18b62 --- /dev/null +++ b/packages/shorebird_code_push_api/.dockerignore @@ -0,0 +1,9 @@ +.dockerignore +Dockerfile +build/ +.dart_tool/ +.git/ +.github/ +.gitignore +.idea/ +.packages \ No newline at end of file diff --git a/packages/shorebird_code_push_api/Dockerfile b/packages/shorebird_code_push_api/Dockerfile new file mode 100644 index 00000000..6907fdc3 --- /dev/null +++ b/packages/shorebird_code_push_api/Dockerfile @@ -0,0 +1,27 @@ +# Official Dart image: https://hub.docker.com/_/dart +# Specify the Dart SDK base image version using dart: (ex: dart:2.19) +FROM dart:stable AS build + +# Resolve app dependencies. +WORKDIR /app + +# package:shorebird_code_push_api +COPY pubspec.* ./ +RUN dart pub get + +# Copy app source code and AOT compile it. +COPY . . + +# Ensure packages are still up-to-date if anything has changed +RUN dart pub get --offline +RUN dart compile exe bin/server.dart -o bin/server + +# Build minimal serving image from AOT-compiled `/server` and required system +# libraries and configuration files stored in `/runtime/` from the build stage. +FROM scratch +COPY --from=build /runtime/ / +COPY --from=build /app/bin/server /app/bin/ + +# Start server. +EXPOSE 8080 +CMD ["/app/bin/server"] \ No newline at end of file diff --git a/packages/shorebird_code_push_api/bin/server.dart b/packages/shorebird_code_push_api/bin/server.dart new file mode 100644 index 00000000..1fa9db67 --- /dev/null +++ b/packages/shorebird_code_push_api/bin/server.dart @@ -0,0 +1,20 @@ +import 'dart:io'; + +import 'package:shelf/shelf.dart'; +import 'package:shelf/shelf_io.dart' as shelf_io; +import 'package:shelf_router/shelf_router.dart' as shelf_router; + +Future main() async { + final port = int.parse(Platform.environment['PORT'] ?? '8080'); + final router = shelf_router.Router() + ..all('/', (_) => Response.ok('Hello, world!')); + + final server = await shelf_io.serve( + logRequests().addHandler(router.call), + InternetAddress.anyIPv6, + port, + ); + + // ignore: avoid_print + print('Serving at http://${server.address.host}:${server.port}'); +} diff --git a/packages/shorebird_code_push_api/pubspec.yaml b/packages/shorebird_code_push_api/pubspec.yaml index ddd80613..32c2c027 100644 --- a/packages/shorebird_code_push_api/pubspec.yaml +++ b/packages/shorebird_code_push_api/pubspec.yaml @@ -6,6 +6,10 @@ publish_to: none environment: sdk: ">=2.19.0 <3.0.0" +dependencies: + shelf: ^1.4.0 + shelf_router: ^1.1.3 + dev_dependencies: mocktail: ^0.3.0 test: ^1.19.2