I have a DockerFile as follows:
FROM dart:stable AS build
WORKDIR /app
# Copy Dependencies
COPY packages/shared ./packages/shared
# Install Dependencies
RUN dart pub get -C packages/shared
# Resolve app dependencies.
COPY pubspec.* ./
RUN dart pub get
RUN dart run build_runner build --delete-conflicting-outputs
RUN dart run stormberry migrate --no-ssl --db=postgres --host=localhost --port=5432 --username=postgres --password=postgres --apply-changes
# 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.
CMD ["/app/bin/server"]
This is for a server app built using dart_frog
. I have used stormberry
package as an ORM for postgres db. Now, stormberry requires me to run build_runner
for generating the schemas before migrating it to the database.
The issue is that, the code generation is not generating the schemas.g.dart
files which is required for the migration to happen. This container is deployed to Google CloudRun. This is the log which I get from the CloudRun logs:
Step 7/15 : RUN dart run build_runner build --delete-conflicting-outputs
---> Running in 3a5efb6b628b
[INFO] Generating build script...
[INFO] Generating build script completed, took 612ms
[INFO] Precompiling build script......
[INFO] Precompiling build script... completed, took 14.0s
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 1.3s
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms
[INFO] Running build...
[INFO] Running build completed, took 7ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 60ms
[INFO] Succeeded after 81ms with 0 outputs (0 actions)
Removing intermediate container 3a5efb6b628b
---> e92can43b7d7
Step 8/15 : RUN dart run stormberry migrate --no-ssl --db=postgres --host=localhost --port=5432 --username=postgres --password=postgres --apply-changes
---> Running in 09c17e19f518
Could not run migration, because there are no models found. Did you run the build?
The command '/bin/sh -c dart run stormberry migrate --no-ssl --db=postgres --host=localhost --port=5432 --username=leoncoeur --password=AlphaOmega@1727 --apply-changes' returned a non-zero code: 1
This results in stormberry throwing the following error:
Could not run migration, because there are no models found. Did you run the build?
How do I fix this?
EDIT:
This runs fine in my local machine however.
This is the expecting output for generating one schema.g.dart
file.
dart run build_runner build --delete-conflicting-outputs
[INFO] Generating build script completed, took 811ms
[INFO] Reading cached asset graph completed, took 122ms
[INFO] Checking for updates since last build completed, took 749ms
[INFO] Running build completed, took 6.9s
[INFO] Caching finalized dependency graph completed, took 69ms
[INFO] Succeeded after 7.0s with 0 outputs (8 actions)