feat: simple shelf server and Docker
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
.dockerignore
|
||||
Dockerfile
|
||||
build/
|
||||
.dart_tool/
|
||||
.git/
|
||||
.github/
|
||||
.gitignore
|
||||
.idea/
|
||||
.packages
|
||||
@@ -0,0 +1,27 @@
|
||||
# Official Dart image: https://hub.docker.com/_/dart
|
||||
# Specify the Dart SDK base image version using dart:<version> (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"]
|
||||
@@ -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<void> 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}');
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user