Now that we have our cluster up and running, lets look at how to build and deploy a NextJS app on it, including the database.
Create a NextJS app
We'll scaffold out a TypeScript app.
Fireup a local data
We'll add the npm packages to our project.
.env and change the url to be
primsa/schema.prisma add a model:
Run the migration
prisma studio to check it out
Write the post page and api
This is a basic demostration, so nothing fancy.
"baseUrl" : "." and
react-hook-form to make things simplier.
A couple points.
- We query the database in
- We are fetching our API from
- We are totally hacking the window reload, I'm just lazy
This is the api request to handle the post. It runs on the server.
postgres on your cluster
Eventually the database will be available on
We can get the password using
When we deploy the function we'll set the
DATABASE_URL to look something like:
You'll need to update that with your actual password of course.
Migrate the database
We are going to setup the database from our local enviornment. We'll
kubectl to forward the local postgres port to the remote install.
Remember to stop your local postgres container
Then, using the password that we found above, deploy the current migrations to the postgres that's being forwared on localhost. This is a different url then the previous one shown!:
You can also run
prisma studio that way, by the way.
Deploy the service
We need to tweaks the dockerfile from the official docs to add
generate to get the client code. So, copy over that
then, right after it copies the
node_modules over added
RUN npx prisma generate
For me it's on like 14, right before
Since I'm working off an M1 mac, I need to set the
--platform to make
sure that the image is built using the correct binaries. An example
of this is:
Create the service
Once this is up and running, you should be able to interact with your service and add messages.