Build using Travis CI/CD & Deploy using Nife

To deploy to Travis we essentially need four things.
  1. The application you want to deploy.
  2. A runnable copy of nifectl.
  3. A nife.toml file.
  4. Your Nife API Token.

On Travis, the CI/CD system takes care of the first requirement for you. The CI/CD process is all driven by a .travis-ci.yml files.

Lets walk through the .travis-ci.yml.

To configure Travis, we need to create a file named .travis.yml in the root folder of your project. This is where we'll describe the actions that will be executed by Travis.

The steps to create the .travis.yml file for the back end application are the following:

1. Choose Language and Version: in this case we are going to choose nodejs (other entries available: ruby, java, python...).

2. Docker Service: indicate Travis that we are going to make use of Docker (travis CI can run, build docker images and push images to a container registry).

3. Install Dependencies: like in a local environment, we can just execute npm install.& nifectl.

4. Test Application: in our case we will run the unit tests that have been implemented for the application.

5. Build Docker Image: if tests pass, we just create the container image (this will search for a Dockerfile file at the root of your repository and follow the instructions from that file to create a production build, storing it in a Docker image container).

6. Log into Docker Hub: before pushing the generated image to the Docker Hub Registry we need to login into Docker Hub.

7. Tag Docker Images: We need to identify the container image with a given tag.

8. Push Docker Images: push the generated image to the Docker Hub registry.

A summary of this build process:
build process using Travis CI/CD
Configuring for Nife
Prerequisite:#
  • Before proceeding further we install nifectl with the command in the github actions.
  • We need nife.toml file and an auth token.
The nife.toml file will be needed to create using nife init so you will likely to do this locally and then add to the repository, for nifectl to find when it is run in deployment.

For the API token use nifectl, using the token previously logged with.

Run nifectl auth token and this will display the token your session. Use this token value into NIFE_ACCESS_TOKEN environment variables inside the deployment.

For Travis you will need to go to the repository settings, select CI/CD then expand the variable.

After creating the new variable copy the auth token value into the value field.

Then turn on the protected and masked switches so that it is not leaked through the logs.

Ready to Deploy

Now we are ready to commit the .travis-ci.yml to the repository and install their CI/CD pipeline. On the Travis web UI, head to CI/CD, then jobs, after which you should see the deployment job running. Click on the running badges to see the progress.

Job’s Done
That’s pretty much for deploying with Travis CI/CD system. There’s lot more functionality in there allowing you to structure the pipeline as you want and trigger different jobs at different times.