Fix dev image: seed the default admin and pre-build assets - #243
Fix dev image: seed the default admin and pre-build assets#243junkerderprovinz wants to merge 1 commit into
Conversation
|
Thanks for the PR. The pre-build commands aren’t needed: |
| USER root | ||
| WORKDIR /app | ||
| ENTRYPOINT ["bash", "-c", "mix deps.get && mix ecto.migrate && cd assets && npm i && cd .. && mix phx.server"] | ||
| ENTRYPOINT ["bash", "-c", "mix deps.get && mix ecto.setup && cd assets && npm i && cd .. && mix esbuild default && mix tailwind default && mix tailwind admin && mix sass default && mix phx.server"] |
There was a problem hiding this comment.
| ENTRYPOINT ["bash", "-c", "mix deps.get && mix ecto.setup && cd assets && npm i && cd .. && mix esbuild default && mix tailwind default && mix tailwind admin && mix sass default && mix phx.server"] | |
| ENTRYPOINT ["bash", "-c", "mix deps.get && mix ecto.setup && cd assets && npm i && cd .. && mix phx.server"] |
There was a problem hiding this comment.
Thanks @alxlion, you're right. Pushed, the PR is now just mix ecto.migrate -> mix ecto.setup.
I checked the watcher claim before dropping the pre-build and it holds: config/dev.exs starts all four (esbuild, tailwind default, tailwind_admin, sass) through install_and_run, so phx.server builds everything itself and the pre-build was just repeating that work on every start.
Measured it on a fresh clone with an empty _build:
- Cold first boot: endpoint listening at
15:07:54.042, all four outputs built at15:07:58.94. Roughly 5s, and essentially all of it is the standalone binary downloads (tailwind's is 120 MB). - Warm restart: endpoint at
15:10:19.532, builds done at15:10:19.776. 244 ms, no downloads, and the previous run's CSS is still on disk.
So the race I originally hit is real, but far smaller than my description made it sound, and it only happens on the first run of a fresh checkout. The 45-60s I saw was the download on a slower line, which pre-building didn't avoid either. It just moved it ahead of the listener and added a duplicate build to every boot after that.
If you ever want that first boot tightened, the download-only version would be mix tailwind.install --if-missing && mix sass.install --if-missing && mix esbuild.install --if-missing, which skips the second build and is a no-op once the binaries are cached. Happy to leave it out though, live reload covers it fine.
Verified on the simplified branch: seeds run, admin@claper.co logs in, /admin returns 200 when logged in and redirects to /users/log_in when logged out, and all four asset files are built and served by the watchers alone.
Dockerfile.dev's ENTRYPOINT (used by compose.dev.yml's app service) ran `mix ecto.migrate` instead of `mix ecto.setup`, so priv/repo/seeds.exs never ran and the dev container came up with no default admin user to log in with. Switch to `mix ecto.setup` (create + migrate + seeds, per the alias already in mix.exs) so the seeded admin@claper.co account is created. Fixes ClaperCo#230
4322577 to
752323a
Compare
Summary
#230 reports that the dev setup produces a running server with no admin account to log in with.
What this changes
One line in
Dockerfile.dev'sENTRYPOINT(used bycompose.dev.yml'sappservice):mix ecto.migrate->mix ecto.setupecto.setupis the alias already defined inmix.exs(ecto.create+ecto.migrate+run priv/repo/seeds.exs), so the seeds actually run and the defaultadmin@claper.coaccount gets created.Verification
Ran the dev image against a Postgres 15 container using the repo's own
.env.samplevalues, on a fresh clone with an empty_build:Then logged in as
admin@claper.coand confirmed/adminreturns 200, while the same request logged out redirects to/users/log_in. So the admin role assignment works too, not just the user row.Assets are left to the dev watchers configured in
config/dev.exs, which build all four outputs (app.css,admin.css,app.js,custom.css) without any help from the entrypoint.Notes
userstable is empty. If you already have aclaper-dbvolume from hitting this bug, rundocker compose -f compose.dev.yml down -vfirst, ormix ecto.resetinside the container.docker compose -f compose.dev.yml up --build.&&chain, where a migrate-only entrypoint could not be taken down by a seed bug.compose.dev.yml'sappservice hasdepends_on: dbwithout waiting on the db healthcheck, so a cold start can still race Postgres accepting connections. Pre-existing, out of scope here.Fixes #230