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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #/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

1
docker build . -t wschenk/clocviz

Do a run

1
2
3
4
5
6
7
8
  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:

1
(cd output;npx live-server)

Thoughts

The output HTML needs a bit of work on smaller screens but that's pretty neat.

Previously

cdkini/clocviz

2021-03-25

Next

Setting up emacs for typescript development If we are going to bother with static types, might as well use them

2021-04-13

howto

Previously

Emacs Blog Writing and Navigation Mode emacs and hugo sitting in a tree

2021-03-15

Next

Setting up emacs for typescript development If we are going to bother with static types, might as well use them

2021-04-13