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 thatis the name assigned to your group, e.g., "mansfield". - Push the
main
branch 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.local
file, executeπ» ssh git@csci312.dev secrets <project name> KEY=value
, where again<project name>
is the name assigned to your group.KEY=value
is 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.dev
would set theNEXTAUTH_URL
key for thesimplepedia
project. If your value has special characters, like the β?β in some database URLs, you may need to surround theKEY=value
with 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=value
argument, e.g.,π» ssh git@csci312.dev secrets simplepedia
, thesecrets
command 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--lines
argument, e.g.,--lines 50
to look at more lines. - Typically a new deployment will also involve changes to your database schema and or seeding. If you are using the RDBMS configuration from the practical you can migrate and seed the production database from your local computer by setting the node environment to production before your
knex
commands, e.g., on OSX/Linux or if you are using BASH on Windows (less common):π» NODE_ENV=production npx knex migrate:latest π» NODE_ENV=production npx knex seed:run
For Windows (and to create scripts that can be used across platforms) I recommend installing the cross-env package (
π» npm install -g cross-env
installs it globally, independent of any particular project). You can usecross-env
to specify environment variables in a platform-independent way. Specifically the commands above would be implemented asπ» cross-env NODE_ENV=production npx knex migrate:latest π» cross-env NODE_ENV=production npx knex seed:run
I encourage you to test the production version of your application locally before deploying to the server. You can do with:
π» npm run build
π» npm 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!