Deployment
Deployment
To support deployment without requiring you to enter a credit card or running into limits on team sizes, etc. we have our own simple cloud deployment platform csci312.dev. In short, you will push your code to a deployment repository at csci312.dev, which will then build and deploy your application at https://<project name>.csci312.dev, e.g, https://simplepedia.csci312.dev.
As a prerequisite, you should have added an SSH key to GitHub as described in the getting started instructions. Doing so is necessary to obtain deploy permissions. If you attempt the below and get permission-related errors, contact the instructor to make sure your key has been added to the deployment server.
Add the deployment repository as a remote in your repository:
git remote add deploy git@csci312.dev:<project name>, e.g.,git remote add deploy git@csci312.dev:simplepedia. Note that <project name> is the name assigned to your group, e.g., “mansfield”.Push the
mainbranch to the deploy repository:git push deploy main. This should automatically build and deploy your application athttps://<project name>.csci312.dev. Any errors should hopefully be reported on in the terminal as the push proceeds.To add entries to the
.env.localfile on csci312.dev, executessh git@csci312.dev secrets <project name> KEY=value, where again<project name>is the name assigned to your group.KEY=valueis the value you want to add or update in the file (without any spaces). For example,ssh git@csci312.dev secrets simplepedia NEXTAUTH_URL=https://simplepedia.csci312.devwould set theNEXTAUTH_URLkey for thesimplepediaproject. If your value has special characters, like the ‘?’ in some database URLs, you may need to surround theKEY=valuewith single quotes, e.g.,'KEY=value', so that your shell doesn’t try to interpret the special characters for its own purposes. If you don’t provide aKEY=valueargument, e.g.,ssh git@csci312.dev secrets simplepedia, thesecretscommand will print out the current secrets.To view the most recent logs from your application execute
ssh git@csci312.dev logs <project name>. You can optionally add a--linesargument, e.g.,--lines 50to look at more lines.For Windows (and to create scripts that can be used across platforms) I recommend installing the cross-env package (
pnpm install -g cross-envinstalls it globally, independent of any particular project). You can usecross-envto specify environment variables in a platform-independent way. Specifically the commands above would be implemented ascross-env NODE_ENV=production pnpm exec knex migrate:latest cross-env NODE_ENV=production pnpm exec knex seed:run
I encourage you to test the production version of your application locally before deploying to the server. You can do with:
pnpm run build
pnpm run start
This will build the production version of your application and start if the same way as the server (e.g., setting the production environment so you use the production database). If this doesn’t work locally, it is unlikely to work remotely!
Supabase
To deploy your Supabase backed project, you will need an account on Supabase.com. Once you have your account, create a project for you After you have created your account, you can log in to your account from your project on the command line with
supabase loginThis will ask to open a browser and have you log into your Supabase account.
Next, you will link your project with
supabase linkThis will ask you to pick your project. Once it is complete, you should have a connection between your local development environment and the remote database.
To run your migration files against the remote database, you can run
supabase db pushProduction keys
To get the keys to access this Supabase project, go to the dashboard and look for the Connect button at the top of the page. This will bring up dialog box. Select App Frameworks and set the Franmeworks to Next.js and the Using to Pages Router. This will give you the URL and Anonymous keys for accessing the database. These are the values you will want to set with the ssh git@csci312.dev secrets command outlined above.
Secret keys
When we seeded the database in the practical, we used the Secret key to bypass Row Level Security. Unlike your development environment, production databases rarely get seeded in the same way. You want them to develop organically. However, since we are primarily creating demos, you may still want to seed the database. You may also want to have sever based database access instead of client side access. In which case you need the secret key.
Go into Project Settings (gear icon on the left), and then find the API Keys menu option. You can use the service_role key, though Supabase is phasing those out. They would prefer that you switch to the API keys tab and click “Create API Keys”. This will generate a new secret key for you.