Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Recipes

Anthony Steele edited this page Feb 17, 2019 · 16 revisions

NuKeeper Logo

Recipes for running NuKeeper

The other pages give examples of running NuKeeper on your command line. But Nukeeper is most useful as automation that can make pull requests or calculate metrics unattended. Here are examples.

NuKeeper in Azure Devops

The Azure Devops extension for runing Nukeeper is here, with source here.

NuKeeper in a docker container

Our docker image is here. It is based on this dockerfile.

Inside the dockerfile you will want to do something like this:

RUN git config --global user.email $GIT_USER_EMAIL
RUN git config --global user.name $GIT_USER_NAME
RUN nukeeper ....

It may also be useful to keep your token in the environment var NuKeeper_github_token or NuKeeper_azure_devops_token in this case.

NuKeeper on an AWS EC2 machine

Preparing the machine

Sign into AWS console, go to EC2.
Launch a new instance. I use a the .NET Core 2.1 with Ubuntu Server 18.04 - Version 1.0 - ami-14fb1073 machine image, and t2 micro type.
Take care to save a new key or use an existing key pair, as you will need to connect over ssh. We can call this e.g. awskeypair.pem, saved locally.
The machine has a "Public DNS" in the form ec2-serial.region.compute.amazonaws.com.
When it starts, I can connect to it with ssh (in WSL) using e.g. ssh -i ~/.ssh/awskeypair.pem ubuntu@ec2-serial.region.compute.amazonaws.com. In fact I make a local batch file for this.

When I log in for the first time, I see text like this on the command line:

119 packages can be updated.
17 updates are security updates.

*** System restart required ***

So we will first apply updates. Execute:

# updates
sudo apt-get update
sudo apt-get upgrade

This process can take several minutes, and you will have to confirm with Y a few times. But there are no tricky choices - just confirm everything. Continue with setting up NuKeeper:

# install necessary dependencies
sudo apt-get install libcurl4
sudo apt-get install logrotate

# necessary global git config
git config --global user.name "NuKeeper Bot"
git config --global user.email "NuKeeper@MyEmailDomain.com"

# install nukeeper
dotnet tool install --global nukeeper

And then restart the machine as requested, for the first, and hopefully last time.

# restart
sudo shutdown -r now

And then the machine restarts. After connecting again, I can check for NuKeeper's successful install with:

# is dotnet installed?
dotnet --version
# is nukeeper installed in dotnet?
dotnet tool list --global
# can nukeeper run and show help?
nukeeper

NuKeeper self-update

pwd shows that I am in the user's home directory, i.e. /home/ubuntu. I will keep bash script files here.

First I set up a daily check for an update to NuKeeper. It is in the file ~/toolupdate. I use nano toolupdate to edit this file. Use your favourite editor if you have a preference. The contents are

#!/bin/bash
dotnet tool update --global nukeeper

Then I make it executable: chmod ugo+x toolupdate. I confirm that it can run with ./toolupdate. The output should be something like:

Tool 'nukeeper' was reinstalled with the latest stable version (version '0.10.0').

Then I schedule this to run first thing daily: crontab -e and replace the contents of the cron schedule with:

MAILTO=""
0 01 * * * /home/ubuntu/toolupdate

We will need a place to store log file for the output, and we use a directory in the standard place, under /var/log/. so I create it and make it writable with

sudo mkdir /var/log/nukeeper
sudo touch /var/log/nukeeper/nukeeper.log
sudo chmod ugo+rw /var/log/nukeeper/nukeeper.log

NuKeeper runs

Now I can finally make NuKeeper run to keep my code new.

e.g. I make a file called awswatchmanupdateaws, to check the AwsWatchman project for updates to AWSSDK.* libraries and make a consolidated PR for these. It contains:

#!/bin/bash
/home/ubuntu/.dotnet/tools/nukeeper repo https://github.com/justeat/AwsWatchman mygithubtoken --include ^AWSSDK. --maxpackageupdates 100 --consolidate --logfile /var/log/nukeeper/nukeeper.log

The batch file is marked executable with chmod ugo+x awswatchmanupdateaws. Note that I output to the log file. It also gets a line in the crontab to run it daily:

0 02 * * * /home/ubuntu/awswatchmanupdateaws

I do another one called awswatchmanupdate which does updates to all other packages:

#!/bin/bash
/home/ubuntu/.dotnet/tools/nukeeper repo https://github.com/justeat/AwsWatchman mygithubtoken --exclude ^AWSSDK.  --logfile /var/log/nukeeper/nukeeper.log

It is also marked executable with chmod ugo+x awswatchmanupdate. And it also has a crontab for a daily run at a different time:

0 03 * * * /home/ubuntu/awswatchmanupdate

You can of course test these by running them, e.g.

 ./awswatchmanupdateaws
 cat /var/log/nukeeper/nukeeper.log

I also do the "self-maintenance" on NuKeeper like this:

#!/bin/bash
/home/ubuntu/.dotnet/tools/nukeeper repo https://github.com/NuKeeperDotNet/NuKeeper.git mygithubtoken --logfile /var/log/nukeeper/nukeeper.log

And more along scheduled jobs these lines.