From b11c867db6a492948c4b4ec7d25ec748a062c0cc Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Sat, 10 Aug 2024 18:31:37 -0700 Subject: [PATCH] feat: add Dockerfile for cli --- compose.yaml | 8 +++++++- packages/cli/Dockerfile | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 packages/cli/Dockerfile diff --git a/compose.yaml b/compose.yaml index 44dff922..724deff2 100644 --- a/compose.yaml +++ b/compose.yaml @@ -2,4 +2,10 @@ services: web: build: ./packages/ui ports: - - "8080:80" \ No newline at end of file + - "8080:80" + cli: + build: + context: ./packages + dockerfile: ./cli/Dockerfile + args: + - BIN=cli diff --git a/packages/cli/Dockerfile b/packages/cli/Dockerfile new file mode 100644 index 00000000..0f1b704b --- /dev/null +++ b/packages/cli/Dockerfile @@ -0,0 +1,33 @@ +# This is expected to be invoked with /packages as the context. +# Example: +# cd packages +# docker build -t cli -f cli/Dockerfile . +FROM dart:stable AS build +ARG BIN=cli + +# Resolve app dependencies. +WORKDIR /app +COPY openapi/pubspec.* ./openapi/ +COPY types/pubspec.* ./types/ +COPY db/pubspec.* ./db/ +COPY cli/pubspec.* ./cli/ +WORKDIR /app/cli +RUN dart pub get + +# Copy all packages and build them. +WORKDIR /app +COPY . . + +WORKDIR /app/cli +RUN dart pub get --offline + +RUN mkdir -p /app/bin +RUN dart compile exe bin/${BIN}.dart -o /app/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/ + +CMD ["/app/bin/server"] \ No newline at end of file