I've been looking at small tools that we could combine together to get a better sense of a repository. clocviz is a nifty on that puts a front end on top of cloc, so I packaged up a docker container that lets you pass in a url and will generate some static html for you.
First we package up clocviz
We'll build this using go 1.16.2
and then install a few dependancies,
specifically cloc
, wget
, and git
.
FROM golang:1.16.2-buster
RUN apt-get update && apt-get install -y cloc wget git
WORKDIR /app
RUN git clone https://github.com/cdkini/clocviz clocviz
RUN cd clocviz && go get && go build
COPY *sh ./
RUN chmod +x *sh
RUN chmod 777 /app
ENTRYPOINT /app/entry_point.sh
Script to pull down the repo and generate the html
This script expects the REPO
environment variable to be set to a URI
that git
can clone. It will pull down the repo, then run clocviz, and
then scrape the html into the /output
directory (presumably mounted as
a volume.)
#/bin/bash
REPO_WORK_DIR=/app/repository
WORK_DIR=/output
if [ -d ${REPO_WORK_DIR} ]; then
echo Using repo in ${REPO_WORK_DIR}
else
if [ -z "$REPO" ]; then
echo Please set the REPO env variable or mount ${REPO_WORK_DIR}
exit 1
fi
git clone $REPO ${REPO_WORK_DIR}
fi
if [ ! -d ${WORK_DIR} ]; then
echo Creating ${WORK_DIR}
mkdir -p ${WORK_DIR}
fi
# clocviz serves static files from its filesystem, so we need to run it from there
(cd /app/clocviz; clocviz $REPO_WORK_DIR &)
cd $(mktemp -d)
wget --recursive \
--page-requisites \
--convert-links \
--no-parent \
http://localhost:8080
cp -r localhost:8080/* $WORK_DIR
Build the container
docker build . -t wschenk/clocviz
Do a run
export REPO=https://github.com/ruby-git/ruby-git
mkdir -p output
docker run --rm -it \
-v $PWD/output:/output \
--env REPO \
-u $(id -u) \
wschenk/clocviz
Then test:
(cd output;npx live-server)
Thoughts
The output HTML needs a bit of work on smaller screens but that's pretty neat.