Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for [deploy] seed_command #4139

Merged
merged 1 commit into from
Jan 6, 2025
Merged

add support for [deploy] seed_command #4139

merged 1 commit into from
Jan 6, 2025

Conversation

rubys
Copy link
Contributor

@rubys rubys commented Dec 25, 2024

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.

npx try-prisma@latest --template orm/sveltekit
cd orm_sveltekit
npm install --save-dev fly-apps/dockerfile-node
sed -i.bak 's/sqlite/postgresql/;s/"file:.\/dev.db"/env("DATABASE_URL")/' prisma/schema.prisma
psql -c "DROP DATABASE IF EXISTS testdb"
export DATABASE_URL=postgres://$USER@localhost/testdb
npx prisma migrate dev --name init
~/path/flyctl/bin/flyctl launch

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.

```
npx try-prisma@latest --template orm/sveltekit
cd orm_sveltekit
npm install --save-dev fly-apps/dockerfile-node
sed -i.bak 's/sqlite/postgresql/;s/"file:.\/dev.db"/env("DATABASE_URL")/' prisma/schema.prisma
psql -c "DROP DATABASE IF EXISTS testdb"
export DATABASE_URL=postgres://$USER@localhost/testdb
npx prisma migrate dev --name init
~/path/flyctl/bin/flyctl launch
```
@rubys rubys marked this pull request as draft December 25, 2024 19:19
@rubys rubys marked this pull request as ready for review January 5, 2025 22:06
@rubys rubys merged commit 66b0d54 into master Jan 6, 2025
34 checks passed
@rubys rubys deleted the deploy_seed_command branch January 6, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant