Build and Download Keyhole

Keyhole is an open source project and the source codes are available at GitHub.  It is recommended to build your own Keyhole executables from the source codes.  Alternatively, Keyhole executables can be downloaded from Docker Hub, and available executables are for Linux, macOS, and Windows.

Build from GitHub

Golang has to be installed before you can build.  The commands below show how to clone from GitHub and build a Keyhole executable:

mkdir -p $GOPATH/src/github.com/simagix
cd $GOPATH/src/github.com/simagix
git clone --depth 1 https://github.com/simagix/keyhole.git
cd keyhole
go build main/keyhole.go

I provide a build.sh script to build Keyhole on macOS or Linux.  Simply run the script:

./build.sh

I encourage you to use the script to build.  It’s easier for me to debug based on the included version number if a reported bug ever comes to me.

Cross Platform Builds

To my surprise, it was not as easy as I thought for many users to build Keyhole executables.  How about Windows executable?  So, I improved the script to build for three different platforms, and they are macOS, Linux, and Windows, respectively.  The command is:

./build.sh cross-platform

The outputs are created under the dist directory.

$ ls dist

keyhole-linux-x64     keyhole-osx-x64       keyhole-win-x64.exe

Build on Windows

Below is the command to build Keyhole v1.0.5 from a Windows command terminal.

go build -ldflags "-X main.version=v1.0.5" main/keyhole.go

The above command will output an executable, keyhole, in the current directory.  The version number is stored in a file, named version.

> type version

1.0.5

Download Executables

I used to make Keyhole executables available to download from GitHub.  After I retired my Jenkins, I began using Docker Hub for my CI pipeline and no more executables were available from GiHub.

Use Docker to Download

If you have Docker installed, the latest Keyhole executables can be downloaded from Docker Hub using the scripts/download-from-docker.sh script.  The script only has a few lines, see below:

#!/bin/bash

docker rmi -f simagix/keyhole

id=$(docker create simagix/keyhole)

docker cp $id:/dist - | tar vx

docker rm $id

Docker on Windows

Nothing is straightforward on Windows if it can’t be double-clicked.  To download from a Windows computer, it’s not as simple as I first thought.  First of all, after installing the Docker engine, switch to Linux containers mode.  The switching to Linux containers may fail if your hypervisor doesn’t support it.  Once you pass the Docker installation and configuration, creating a Keyhole instance before copying the file.  Below is an example of the commands I ran:

> docker rmi -f simagix/keyhole

> docker create simagix/keyhole

...

cd5c557a56a928bb7b9d8358ed0c4a47aec48a5d2d40dc03901d

> set id=cd5c557a56a928bb7b9d8358ed0c4a47aec48a5d2d40dc03901d

> docker cp %id%:/dist/keyhole-win-x64.exe keyhole.exe

> docker rm %id%


The above commands can be summarized as 1) remove the existing Keyhole image, 2) create a new instance of Keyhole, 3) use the instance id to copy a file, and 4) remove the instance.  If you don’t understand the above commands, call for professional help.

What's Next?

The build and download steps are simple enough if one can overcome the prerequisites such as installing Golang and/or Docker.  Short blogs about the uses of Keyhole come next following this post.  Keyhole was actively developed and thus made previous posts somewhat outdated.   Check out Survey Your Mongo Land and Maobi - Reports Generator for Keyhole next to begin evaluating MongoDB performance using Keyhole.

Comments

Torsten said…
This powershell ps1 script saves some copy/paste and stores the keyhole exe in C:\MongoDB:


docker rmi -f simagix/keyhole
$id = docker create simagix/keyhole | select -Last 1
docker cp ${id}:/dist/keyhole-win-x64.exe C:\MongoDB\keyhole.exe
Anonymous said…
add this line to the PS1:
$Env:PATH += $(pwd)

Popular posts from this blog

MongoPush - Push-Based MongoDB Atlas Migration Tool

Survey Your Mongo Land