This repo will serve as a quickstart template for express servers with built-in CI/CD workflow that deploys via Docker and Heroku.
In order to create a new project using this template, you can follow these steps:
There are two ways you can use this repo as starter code for your own project. You can use as template
which will make the process quicker with a few less steps, but will mean you do not have access to any future updates that are made to this template. If you would like to be able to recieve updates that are made to the template, then you will have to clone the repo
instead.
-
Click the
use as template
button at the top of this repo -
Select the account you want to own the new repo
-
Choose a name for your repo, and optionally write a short description
-
Choose if your repo should be public or private
-
Click
Create Repository from Template
-
Create your own repo on GitHub
-
Clone the repo
git clone [email protected]:Dino-Martinez/express-quickstart.git
-
Enter the directory
cd express-quickstart
-
Set the origin to your new repo
git remote set-url origin http://github.com/YOUR_USERNAME/YOUR_REPO
Run the Express Server on your local machine
npm start
Install Docker Desktop Create a Docker Hub Account
Build the Docker Image
docker build . -t your-username/express-quickstart
Run the Image on a Docker Container
docker run -p 49160:8080 -d your-username/express-quickstart
The first step to deployment is choosing your method. This template currently offers these methods:
- Deploy straight to Heroku
- Publish to Docker Hub
This is the default method for this template, because it involves the least overhead. You just need to know how to create an express server, nothing else.
- Create a Heroku Account
- Once logged in, copy and save your Heroku API Key
- Create a Heroku App
- Navigate to your repositories
secrets
. This can be found via Settings -> Secrets. - Create 3
secrets
:
- HEROKU_EMAIL -> The email address for your Heroku account.
- HEROKU_APP_NAME -> The name of the app you created in step 3.
- HEROKU_API_KEY -> The API key associated with your Heroku account, found in step 2.
Once you have completed these steps, you're done with setup. Next, all you need to do is make any push to a branch named production
and GitHub will handle the rest. Your code will be run through any tests (files named <something>.test.js
). Then it will be linted based on the .eslintrc.json (default is Standard JS). If both of those pass, the code will be dockerized and pushed straight to Heroku for you.
Once this build is complete you can access your app at HEROKU_APP_NAME.herokuapp.com
For this method, you will have to go through a bit of external setup in order to get your Image from Docker Hub to be deployed to your actual server. Full instructions coming soon.