Deploying with CI CD - bommezijn/Dating-Shreks GitHub Wiki

This topic was worked on by Nathan.

TL;DR
I deployed the concept app to Heroku with Travis-CI and get slack messages about it.

What is CI / CD

A method to frequently deliver apps to customers by introducing automation into the stages of app development
-Red Hat

CI/CD stands for_continuous integration, continuous delivery, and continuous deployments. The solution to the problems integrating new code can cause development and operations teams. The meaning between the two (three terms) is multiple; CI is an automation process for developers; when done successfully, it means that the code is built, tested, and merged.

CD in CI/CD can, as highlighted before, meaning two things, Continuous delivery/ deployment, but they are almost identical; CD is the process of delivering it to the customer via deployments such as Heroku, Digital Ocean, or another hosting / VPS platform.

One job function that will be continuously working with CI/CD is DevOps.

So many solutions

CircleCI
Travis CI (com)
Travis CI (org)
Jenkins
Drone.io

Just to name a few.

But why Travis-ci.org instead of the others?

At first, I wanted to use CircleCi to build the application and host it, but I did not like its cloud pricing plan. image I can only run one job at a time, but with Travis-ci, I can run multiple builds, which for the current level of my programming skills is needed as I want to host my personal and team dating project.

The biggest name in the business is Jenkins, whereas Travis is the runner-up. But why?

The biggest reason to pick Travis over Jenkins is the initialization step; The latter has to be hosted internally, meaning I have to host it, while the other has a hosted solution that is easy to get started with and has a clear interface.

Both are free for open-source projects and is documented extensively. Jenkins is famous for anything from opensource to big enterprise projects as it is opensource thus, free. Travis is not.

Also, a fun fact but very important, Travis-CI, can be divided into two, travis-ci.com and travis-ci.org (There is a big but, see next line).

Travis-CI .com was originally for private paid repo's while .org is for free public repo's. But as of May 2018, Travis-CI announced they would be merging both variants into Travis-CI .com.

If I would want to migrate the build from one to another, I can simply follow the steps from docs.travis-ci.com, which in a nutshell explain the following;

  1. Log in travis-ci.com and go to my profile.
  2. If not already done already, integrate the new Github Apps.
  3. Give access to the repo's
  4. Go to the migrate tab and select the repo('s) you want to migrate.
  5. Confirm, and that's it.

How I have used Travis

prerequisites:

  • ruby 2.6 or later
  • Installed the Heroku CLI
  • account on Travis CI (org)
  • Make sure your Heroku app has the same name as your repository.*

First thing I did:

After reading, I saw that Travis has a CLI, installed it, and did the same for Heroku.

  1. Install the Travis CLI
    gem install Travis --no-document

  2. Get your Heroku API key:

Create a .travis.yml file

for a node application that you want to host on Heroku, you can use the following code. $YOUR_SECURE_KEY will be replaced with the generated key from the following command:
$ travis encrypt $(PASTE_YOUR_HEROKU_API_KEY) --add deploy.api_key --org

language: node_js
node_js:
- lts/*
cache: npm
deploy:
  name: <NAME_OF_APP> #when not specified will use repository name
  provider: heroku
  api_key:
    secure: <YOUR_SECURE_KEY>

Trouble I came across with

Issues with deploying to heroku
API request failed, Invalid credentials provided, failed to deploy.
Solution:
apparently, the Heroku token generated by the CLI was not correct. Get API key from Heroku account and paste it in the following command prompt:
$Travis encrypt pasteAPIKeyHere --add deploy.api_key --org
* ** Couldn't find that app.**** The problem was that whenever I tried to have Travis-ci set up continuous deployment, it fails. After a deep-dive, I found the issue, and that was that Travis-ci + Heroku does not like Capitalized repo names (see the joke?).
Solution:
Add a name parameter to the deploy:

deploy:
  provider: Heroku
  app: <THE_APP_NAME>

And then the building is a process of sipping a cup of coffee while you see it turn green☕️.

Extra Travis-CI gives the developer the option to add a status tag; this looks cool and allows the reader to see if a build is failing or successfully building...

Except it shows 'failing' more often than passing: Build Status Even though, as of today (June 23, 2020, 23:20), it is passing the build test. image

Sources

Beatngu13. (2017, May 18). What's the difference between travis-ci.org and travis-ci.com? DevOps Stack Exchange. https://devops.stackexchange.com/questions/1201/whats-the-difference-between-travis-ci-org-and-travis-ci-com

Castaño, N. B. (2018, August 20). Issues with Deploying to Heroku via Travis-CI. Stack Overflow. https://stackoverflow.com/questions/51925918/issues-with-deploying-to-heroku-via-travis-ci

CircleCI. (n.d.). Projects and Pipelines - CircleCI. Retrieved June 23, 2020, from https://circleci.com/docs/2.0/project-build/

CircleCI vs. Jenkins vs. Travis CI | 2020 Comparison. (n.d.). StackShare. Retrieved June 23, 2020, from https://stackshare.io/stackups/circleci-vs-jenkins-vs-travis-ci#pros

Gnanaprakasam, D. (2020a, May 25). Deploy a node app to Heroku using Travis CI. DEV Community. https://dev.to/theloneking/deploy-a-node-app-to-heroku-using-travis-ci-37bh

Gnanaprakasam, D. (2020b, May 25). Deploy a node app to Heroku using Travis CI - Dineshkumar Gnanaprakasam. Medium. https://medium.com/@DineshkumarGnanaprakasam/deploy-a-node-app-to-heroku-using-travis-ci-c8d7200a86de

Redhats😏. (n.d.). What is CI/CD? Redhat.Com. Retrieved June 23, 2020, from https://www.redhat.com/en/topics/devops/what-is-ci-cd

Soares, F. L. (2018, June 13). Automatically deploy with Travis CI and Heroku - Felipe Luiz Soares. Medium. https://medium.com/@felipeluizsoares/automatically-deploy-with-travis-ci-and-heroku-ddba1361647f

Travis-CI. (n.d.-a). Heroku Deployment. Docs.Travis-Ci.Com. Retrieved June 23, 2020, from https://docs.travis-ci.com/user/deployment/heroku/

Travis-CI. (n.d.-b). Travis CI Documentation. Docs.Travis-Ci.Com. Retrieved June 23, 2020, from https://docs.travis-ci.com/user/status-images/

Travis-CI. (n.d.-c). Travis CI Documentation. Docs.Travis-Ci.Com. Retrieved June 23, 2020, from https://docs.travis-ci.com/user/tutorial/

Travis-CI. (n.d.-d). Travis CI Documentation. Docs.Travis-Ci. Retrieved June 23, 2020, from https://docs.travis-ci.com/user/migrate/open-source-repository-migration#migrating-a-repository