Skip to content

Commit

Permalink
Fix bugs in Dart Dockerfile and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
owensdj committed Apr 21, 2024
1 parent 2c1f9bd commit 1e025a7
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions dart_grpc_bench/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
FROM dart:3.3.4 AS build

WORKDIR /app
COPY dart_grpc_bench/pubspec.yaml /app/pubspec.yaml
COPY proto /app/proto

RUN dart pub get
COPY dart_grpc_bench /app
# Ensure packages are still up-to-date if anything has changed
RUN dart pub get --offline
RUN apt update && apt install -y protobuf-compiler
RUN dart pub global activate protoc_plugin
RUN mkdir -p lib/src/generated
RUN protoc --plugin=protoc-gen-dart=$HOME/.pub-cache/bin/protoc-gen-dart --proto_path=/app/proto/helloworld --dart_out=grpc:lib/src/generated -Iproto /app/proto/helloworld/helloworld.proto

RUN dart compile exe bin/server.dart -o bin/server

# ENTRYPOINT [ "/usr/bin/dart", "/app/bin/server.dart" ]

# 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 50051
FROM dart:3.3.4 AS build

# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
COPY proto ./proto
RUN dart pub get

# Copy app source code
COPY . .

# Ensure packages are still up-to-date if anything has changed
RUN dart pub get --offline

# Setup protobuf compiler
RUN apt update && apt install -y protobuf-compiler
RUN dart pub global activate protoc_plugin

# Generate protobuf files
RUN mkdir -p lib/src/generated
RUN protoc --plugin=protoc-gen-dart=$HOME/.pub-cache/bin/protoc-gen-dart --proto_path=/app/proto/helloworld --dart_out=grpc:lib/src/generated -Iproto /app/proto/helloworld/helloworld.proto

# AOT compile the binary
RUN dart compile exe bin/server.dart -o bin/server

# ENTRYPOINT [ "/usr/bin/dart", "/app/bin/server.dart" ]

# 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 50051
CMD ["/app/bin/server"]

0 comments on commit 1e025a7

Please sign in to comment.