Deploying on Coolify

It dawned on me. If I can’t set the build time network for my app with docker-compose, why don’t I just add the postgres container to the bridge network? SUCCESS.

docker network connect bridge <postgres container>

Now I can finally connect to the database during deployment. It’s a workaround but it really works! :joy: Now onto the next issue. My log now looks like this:

... yarn prisma migrate deploy --schema /app/api/db/schema.prisma
#23 2.952 Datasource "db": PostgreSQL database "postgres", schema "public" at "172.17.0.2:5432" <--- Notice the bridge subnet IP! I used this to show explicitly without using dns that it works
#23 3.046
#23 3.046 No migration found in prisma/migrations <---- I think that's what you meant with your comments above

And of course my seed fails since the tables aren’t created:

#24 [api api_build 5/5] RUN yarn rw prisma db seed
#24 2.144 Running Prisma CLI...
#24 2.144 $ yarn prisma db seed
#24 3.248 Running seed command `yarn rw exec seed` ...
#24 6.899 [COMPLETED] Generating Prisma client
#24 6.900 [STARTED] Running script


[OUTPUT]
#24 9.103 {"level":50,"time":1719247374324,"pid":102,"hostname":"buildkitsandbox","prisma":{"clientVersion":"5.14.0"},"message":"\nInvalid `db.role.count()` invocation in\n/app/scripts/seed.ts:775:24\n\n 772 },\n 773 ]\n 774 \n→ 775 if ((await db.role.count(\nThe table `public.Role` does not exist in the current database.","target":"role.count","timestamp":"2024-06-24T16:42:54.324Z","msg":"\nInvalid `db.role.count()` invocation in\n/app/scripts/seed.ts:775:24\n\n 772 },\n 773 ]\n 774 \n→ 775 if ((await db.role.count(\nThe table `public.Role` does not exist in the current database."}
... multiple of these for each record

This shouldn’t be too big of an issue to fix, though.

Solution: I wasn’t copying scripts since it wasn’t in the Dockerfile

COPY --chown=node:node scripts ./scripts/

# RUN yarn rw prisma migrate reset (remove seed)
RUN yarn rw prisma migrate deploy
RUN yarn rw prisma db seed