Our staging site is hosted on Heroku, and can be reach at https://dialupstuff.herokuapp.com/.
Preparation: If you haven't already, download Heroku's CLI. Afterwards, run 'heroku login', and enter in the login info.
How It Works:
Our Heroku server can be treated like a remote repository. Similar to Github, we can git push
code to the Heroku server. Any time we push to our Heroku server, it will essentially wipe all the code it previously stored, store the new code that was pushed, run npm install
, and then use the command listed in our Procfile to start the project's server.
Steps:
- Switch to the
staging
branch and merge in your development branch. - Add a new remote for Heroku to your local Git repo by running
heroku git:remote -a dialupstuff
. - Run
git push heroku staging:master
. This will push the contents of your localstaging
branch to themaster
branch on the Heroku server. - Watch the build process for errors. Run
heroku logs
to ensure that the server started, or to see what specifc errors occured. - Use
heroku open
to open the webpage for the site and see it live on staging.
Our production site is hosted on Digital Ocean, and can be reach at http://dialupstuff.com/.
How It Works:
Any time someone pushes to the prod
branch, our Docker images repository on Docker Hub builds a new that matches the code that has just been pushed. On our Digital Ocean server, a service called Watchtower pulls down the latest image on the repository every 5 minutes, and compares it to the image that is currently being run on the server. If it's different, it gracefully shutdowns the container running the old image, and starts a new one using the new image. configured using docker-machine
, and runs a Docker container for our project. In short, pushes to the prod
branch result in live changes to the website in about 5 minutes.
Steps:
- Merge code from
staging
(or another branch) toprod
.
For those curious about how to configure this Docker + Digital Ocean setup.
Steps:
- Download the Docker Toolbox, and verify that it's successfully installed [using this guide](https://docs.docker. com/engine/getstarted/step_one/). Once the toolbox has started, ensure you've open the Docker application (Docker daemon) that should now be present on your computer.
- Run
eval "$(docker-machine env default)"
to configure your local CLI to utilizedocker-machine
commands. More details on why this is necessary can be found here. cd
into the root directory of your project and rundocker build -t <image_name> .
to create an image of the project on your system. Check that the image was successfully by runningdocker images
.- Do a test run of the image using
docker run --name <name> -p 8080:3000 -d <image_name>
. This starts a Docker container that is running the image of the project we just created. Since this container is actually a virtual machine, we need to forward the exposed container port (3000) to our system's host port (8080, as specified) so that we can pull up the project with localhost. You can view the project at http://localhost:8080/ to verify that it is working correctly. - In a separate terminal tab, run
docker stop <name>
to stop the container. Afterwards, remove the container withdocker rm <name>
. Usedocker ps -a
to ensure that the container has now been removed. - Setup an Automated Build project on DockerHub. Link this to your GitHub account, and configure the
prod
branch to build with Docker taglatest
in Build Settings. Save changes and trigger a build to test. - Once the build is complete, reconfigure your local
docker-machine
CLI to utilize point at the Digital Ocean Docker machine usingeval $(docker-machine env <machine_name>)
. - Pull the image produced by the Automated Build on Docker Hub onto the Digital Ocean Docker Machine using
docker pull <docker_repo_name>
. - Run
docker run --name <name> -p 80:3000 -d <image_name>
. This will start a Docker container on the Digital Ocean machine that will run the specified image. At this point, the project should be up and running publicly. Check the public URL (the server's IP address or the domain name) to verify. - Next, install Watchtower by running
docker pull v2tec/watchtower
. - Start Watchtower with...
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
v2tec/watchtower --cleanup
- That's it. This will automatically check for new versions of images that are being used in active containers running on the server. The
--cleanup
flag tells Watchtower to remove old versions of the image when it sees a new one.