Skip to content

Instantly share code, notes, and snippets.

@justynroberts
Last active September 8, 2023 03:44
Show Gist options
  • Save justynroberts/f6978bea1172464277d84cb603115bdf to your computer and use it in GitHub Desktop.
Save justynroberts/f6978bea1172464277d84cb603115bdf to your computer and use it in GitHub Desktop.
Sample Deploy/Customise/Create Runner

Automating and customising Runner Builds.

A simple example of creating, customising and deploying a containerised runner in Process Automation. This serves as an outline, and could be improved with error checking, externalisation of variables, secrets etc.

Shopping list. As a minimum you will need installed

  • curl (for API calls)
  • jq (to parse responses)
  • docker-compose to build the custom container

Usage. You will need to create two files: the main script, and the Dockerfile for the custom container creation

TLDR: use https://gist.github.com/justynroberts/f6978bea1172464277d84cb603115bdf#file-create-sh

Overview

The variables below serve as configuration items, and should be self explanatory

Variables

#Set Variables
URL=myenv.runbook.pagerduty.cloud
APITOKEN=myapitoken
PROJECT=myproject
TAG="mytag"
NAME="myrunnername"
DESCRIPTION="myrunnerdescription"

Create Runner, with tags in Runbook Automation

response=$(curl --location --request POST "https://${URL}/api/42/runnerManagement/runners" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: ${APITOKEN}" \
--header "Content-Type: application/json" \
--data "{\"name\": \"${NAME}\",\"description\": \"${DESCRIPTION}\",\"assignedProjects\": {\"${PROJECT}\": \".*\"},\"tagNames\": \"${TAG}\"}")

Will result in a json response, indicating success, with a number of return parameters ID/DownloadTK is required to download java archive, with Token required to start container.

ID=$(echo $response | jq -r '.runnerId')
DLTOKEN=$(echo $response | jq -r '.downloadTk')
TOKEN=$(echo $response | jq -r '.token')
echo "ID : $ID"
echo "DLTOKEN : $DLTOKEN"

downloadTK gives me a temporary token to allow the java archive download

curl --location -o runner.jar --request GET "https://${URL}/api/41/runnerManagement/download/${DLTOKEN}" \
--header "Accept: application/java-archive" \
--header "X-Rundeck-Auth-Token: ${APITOKEN}"

Building a custom docker file, Based on instructions here:- here is a a sample docker file, saved locally as Dockerfile

ARG RUNNER_VERSION=latest
FROM rundeckpro/runner:${RUNNER_VERSION}
USER root

RUN apt-get update && \
    apt-get upgrade -y && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
    curl \
    python3-pip && \
    pip3 install --upgrade pip && \
    pip3 install kubernetes
# include any other apt packages
# Kubectl
RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-relea>
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin/kubectl
# Add user runner
USER runner

Included in the sample DockerFile is the core runner (using the latest version). Installed

  • Python3
  • curl
  • pip3
  • pip 3 Kubernetes module.
  • Kubectl

The above file shows the approach, and these techniques can be easily modified to add extra applications, files or python modules

Build and deploy This command builds a custom container to a local container repository

docker build . -t rundeck/customrunner

Then finally to deploy the container to my local docker instance.

docker run -it -d \
        -e RUNNER_RUNDECK_SERVER_TOKEN=${TOKEN} \
        -e RUNNER_RUNDECK_SERVER_URL=https://${URL} \
        -e RUNNER_RUNDECK_CLIENT_ID=${ID} \
         rundeck/customrunner
#!/bin/bash
#Sample Creation, customisation and deployment of RBA Runner.
#Set Variables
URL=myenv.runbook.pagerduty.cloud
APITOKEN=myapitoken
PROJECT=myproject
TAG="mytag"
NAME="myrunnername"
DESCRIPTION="myrunnerdescription"
#use API to create Runner in RBA
response=$(curl --location --request POST "https://${URL}/api/42/runnerManagement/runners" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: ${APITOKEN}" \
--header "Content-Type: application/json" \
--data "{\"name\": \"${NAME}\",\"description\": \"${DESCRIPTION}\",\"assignedProjects\": {\"${PROJECT}\": \".*\"},\"tagNames\": \"${TAG}\"}")
#Parse Response with JQ
ID=$(echo $response | jq -r '.runnerId')
DLTOKEN=$(echo $response | jq -r '.downloadTk')
TOKEN=$(echo $response | jq -r '.token')
echo "ID : $ID"
echo "DLTOKEN : $DLTOKEN"
#Download Java Runner
curl --location -o runner.jar --request GET "https://${URL}/api/41/runnerManagement/download/${DLTOKEN}" \
--header "Accept: application/java-archive" \
--header "X-Rundeck-Auth-Token: ${APITOKEN}"
#Build Container
docker build . -t rundeck/customrunner
#Deploy container
docker run -it -d \
-e RUNNER_RUNDECK_SERVER_TOKEN=${TOKEN} \
-e RUNNER_RUNDECK_SERVER_URL=https://${URL} \
-e RUNNER_RUNDECK_CLIENT_ID=${ID} \
rundeck/customrunner
ARG RUNNER_VERSION=latest
FROM rundeckpro/runner:${RUNNER_VERSION}
USER root
RUN apt-get update && \
apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
curl \
python3-pip && \
pip3 install --upgrade pip && \
pip3 install kubernetes
# include any other apt packages
# Kubectl
RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-relea>
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin/kubectl
# Add user runner
USER runner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment