DEV Community

lbonanomi
lbonanomi

Posted on

Your Own Gravatar.com

The Problem

After a a few years of running Jira as a pool of federated servers, management decided to let us consolidate into a Jira Datacenter cluster. We provisioned extremely beefy VMs, allocated huge disks and got a dedicated Postgres cluster. Projects were imported, attachments migrated and we were pretty pleased with ourselves until the user feedback started: we hadn't imported the user's custom avatars correctly and rapid boards looked like hot garbage.

Broken Jira avatars

The vendor's instructions are geared toward moving whole instances from one platform to another, which didn't fit our model of merging multiple Jiras together. After some deliberation we decided to try hosting avatars on an independent server.

Hosting your own Gravatar server

After experiments with the API, and a discussion about making changes directly in the database we decided to try using a custom avatar server. After a surprisingly frustrating day trying to get Libravatar on RHEL7, we settled on the comparatively simpler Go project intravatar. Intravatar offers binaries that work beautifully right out of the box, but we made a few simple changes to accommodate our MitM SSL and Internet proxying. Now that we have a place to serve them from, let's get avatars!

Grabbing Jira avatars

Jira stores avatar files under $JIRA_HOME/data/avatars in the format of $ID_$name, so we used the REST API to associate usernames and avatar files. The below bash script will get a list of users from the Jira database, parse details from the user endpoint and scrape the instance's avatar URL to get a file.

#!/usr/bin/bash

# Database connection string is intentionally vague.
psql -tc "select lower_user_name from cwd_user;" | while read USER
do
    curl -snk "https://$OLD-JIRA/rest/api/2/user?username=$USER" | jq .avatarUrls | grep 48 | grep -q $OLD-JIRA && (
        # Get old avatar
        FILE=$(curl -snk "https://$OLD-JIRA/rest/api/2/user?username=$USER" | jq ."emailAddress" | tr -d '"' | tr -d "\n" | md5sum - | awk '{ print $1 }')
        URL=$(curl -snk  "https://$OLD-JIRA/rest/api/2/user?username=$USER" | jq .avatarUrls | grep 48 | awk -F"\"" '{ print $4 }')

        echo "$URL" | grep gravatar && (
            curl -snk $URL > $FILE
        )

        echo "$URL" | grep gravatar || (
            curl -snk > $FILE
        )
    )
done

My team <3s Bert Baron and intravatar

Top comments (0)