Build using Bitbucket & Deploy using Nife

To deploy to Bitbucket 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 Bitbucket, the CI/CD system takes care of the first requirement for you. The CI/CD process is all driven by a .bitbucket-ci.yml files. Lets walk through the .bitbucket-ci.yml I used to deploy from Bitbucket to Nife.

Step 1- Create a new file in Bitbucket repository with name .bitbucket-ci.yml. In this file write down the stage. Inside stage write build and Package.

Once you have selected the image, the deployment process begins. Bitbucket’s CI/CD engine will automatically copy the contents of the repository over to the Runner image.

Step 2 - Next is installation process of nifectl into our runner. For Bitbucket we want to do this before it runs our deployment scripts, so we will add it to the default section as the before_script. Then it uses curl to download the nifectl install script and runs that. Using the script ensure that the right version of the nifectl is installed. This covers requirement two.

Step 3 - Build the sample docker file and log in to nifectl using nifectl auth login and deploy using .

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 Bitbucket 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 bitbucket-ci.yml to the repository and install their CI/CD pipeline. On the Bitbucket web UI, head to CI/CD and then jobs, and 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 Bitbucket 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.