Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

consoledotdev/bc-totorobot

Repository files navigation

Console Basecamp Totorobot

A bot designed to run on Azure Functions and post things into the Console Basecamp chat room. Runs using a Custom Request Handler which receives HTTP requests and responds like a web app.

Methods

  • post_mailchimp_stats: posts the latest stats from Mailchimp.

Development

Uses Rocket so requires Rust nightly. Set up a nightly override on the directory once cloned:

rustup override set nightly

Set environment variables (see below) with the relevant config then run:

cargo run

to start the web server. Issue requests to the endpoints e.g.:

curl -i -X POST -H "Content-Type:application/json" -d "{}" http://localhost:3000/post_mailchimp_stats

Unit tests

cargo test

Testing with Azure Functions

Requirements:

# Create the local.settings.json file which will set the environment variables
# Only required on a fresh clone when the file doesn't exist
func azure functionapp fetch-app-settings bc-totorobot
func start

Trigger timer function

curl -i -X POST -H "Content-Type:application/json" -d "{}" http://localhost:7071/admin/functions/post_mailchimp_stats

Environment variables

  • TOTORO_MAILCHIMP_APIKEY: Mailchimp API key.
  • TOTORO_MAILCHIMP_LIST_ID: Mailchimp list ID string.
  • TOTORO_BASECAMP_BOTURL: URL to post to in Basecamp.
  • TOTORO_PRODUCTION: Set to any value when running in production.

Deployment

Create a new tag with the name format release-vx.y.z where x.y.z is a semantic versioning formatted version string e.g. release-v0.1.4

Azure uses the x86_64-unknown-linux-musl platform. Builds are done through a dedicated Docker container that has various C libraries built against musl.

Azure resources defined in main.bicep.

Manual

Requirements:

docker pull clux/muslrust
docker run -v $PWD:/volume --rm -t clux/muslrust cargo build --release
mkdir bin # host.json configured to expect binary here
cp target/x86_64-unknown-linux-musl/release/totorobot bin/
bicep build ./main.bicep # generates main.json
az login
az deployment group create -f ./main.json -g bc-totorobot
func azure functionapp publish bc-totorobot

Automatic

Uses Azure ARM and Login GitHub actions to deploy.

AZURE_CREDENTIALS created as per the service principal instructions.

az ad sp create-for-rbac --name "bc-totorobot - GitHub" --sdk-auth --role contributor \
    --scopes /subscriptions/SUBSCRIPTIONID/resourceGroups/bc-totorobot