Dockerizing godoc for private repositories

If you have private libraries, then you will want to run a private godoc instance to make the documentation more accessible.

Recommended next steps:

  • Add AuthN/AuthZ directly or with an auth proxy.
  • Trigger CI jobs from master branch merges of documented projects.


SSH_PRIVATE_KEY_FILE=$(find ~/.ssh | grep id_ | grep -v pub | head -n1)

docker build -t org/godoc --build-arg SSH_PRIVATE_KEY="$(cat ${SSH_PRIVATE_KEY_FILE})" 


FROM golang:1.11-alpine3.8 as build

# Pass the SSH_PRIVATE_KEY as an ARG
RUN mkdir /root/.ssh/ \
&&  echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa \
&&  chmod 400 /root/.ssh/id_rsa \
&&  touch /root/.ssh/known_hosts \
&&  apk add --update \
    openssh-client \
    git \
&&  git config --global --add url."".insteadOf "" \
&&  ssh-keyscan >> /root/.ssh/known_hosts \
&&  go get

# Organization projects in a separate layer.
RUN go get \ \

# Separate build stage to not leak the SSH key.
FROM golang:1.11-alpine3.8
COPY --from=build /go/bin /go/bin
# Copying only the organization repos.
COPY --from=build /go/src/ /go/src/

CMD ["godoc", "-http", ":8080"]