add support for [deploy] seed_command #4139
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The motivation here is to support fly launch (from either the CLI or web UI) getting an application completely up and running. In general, this not only involves creating of databases and running of migrations, but also seeding the database.
The timing of the run of the seed command is after the first migration is run, and before any prerendering/SSG or deploy. This is awkward/impossible with the current flow.
Seed support has been available in Rails for quite some time, and for the popular prisma ORM, the seed command can be determined from the
package.json
file:https://github.com/prisma/prisma-examples/blob/7a74fc64c82037f15b23e189a241bc643023f957/orm/nextjs-trpc/package.json#L36-L38
This implementation add [deploy] seed_command to fly.toml. Launch will insert that value (if present) into the ctx. . Deploy will only run that command if it is found in the context. The guarantees that the seed command is only run when deploy is called by Launch.
At the moment, this is accomplished by launching new ephemeral machines for each command. Perhaps that could be optimized to reuse a single machine. Also perhaps, that could be generalized to support a series of post-build, pre-deploy commands.
This depends on an unreleased change to dockerfile_node:
fly-apps/dockerfile-node@eebcf1e
If is possible to test this change against dockerfile-node from github, using a Prisma ORM Fullstack example:
https://github.com/prisma/prisma-examples?tab=readme-ov-file#prisma-orm
This involves downloading the example, installing dockerfile-node, modifying the example to use PostgreSQL as the database, creating migrations, and finally, launching.