install/Dockergit-annexhttp://git-annex.branchable.com/install/Docker/git-annexikiwiki2016-06-03T18:48:11ZA more detailed walkthroughhttp://git-annex.branchable.com/install/Docker/comment_1_909e3b2da0050ce1102c289cc5aac522/matei.david2016-06-03T18:48:11Z2016-06-03T18:48:11Z
<p>I want to use a recent <code>git-annex</code> version, and I prefer a Docker solution to a binary. There wasn't much documentation on how to do that, so here are the steps I took, just in case anybody finds this information useful. This is not a complete guide, just more than I was able to find so far.</p>
<ul>
<li><p>Install Docker so that you can access it (eg, <code>docker info</code>) without <code>sudo</code>. (Beyond the scope in here.)</p></li>
<li><p>Create a git-annex image as follows:</p></li>
</ul>
<p>Dockerfile:</p>
<pre><code>FROM debian:unstable
RUN apt-get update && apt-get install -y ssh git man git-annex=6.20160511-1
# maybe install gpg2, other remotes, etc
#RUN apt-get install -y gnupg2 && ln -s /usr/bin/gpg2 /usr/local/bin/gpg
#RUN apt-get install -y golang-go && GOPATH=/usr/local go get github.com/encryptio/git-annex-remote-b2
VOLUME /data
WORKDIR /data
</code></pre>
<p>Build image and run basic test:</p>
<pre><code>docker build -t git-annex-6.20160511-1 .
docker run -it --rm git-annex-6.20160511-1 git-annex version
</code></pre>
<ul>
<li><p>You still need to:</p>
<ul>
<li>On host: Replace <code>git-annex</code> by a script that invokes the Dockerized version.</li>
<li>In container:
<ul>
<li>Use non-root uids, otherwise you end up creating files with uid 0.</li>
<li>Access <code>ssh</code> and <code>gpg</code> credentials on host.</li>
<li>Access <code>~/.gitconfig</code> on host.</li>
<li>Mount <code>git</code> repository root as a volume, not just the current dir.</li>
<li>Access AWS/B2 credentials, if applicable.</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Here is a sample script that achieves these. Name it <code>git-annex</code>, and place it in your <code>PATH</code> before the host <code>git-annex</code> (or just uninstall the latter).</p>
<pre><code>#!/bin/bash
CONT_NAME=${CONT_NAME:-git-annex-6.20160511-1}
# if in git repo, mount root as /data, and cd into relative subdir
# if not, mount cwd as /data
abs_dir=$(readlink -e .)
root_dir=$(git rev-parse --show-toplevel 2>/dev/null || true)
root_dir=${root_dir:-$abs_dir}
rel_dir=${abs_dir#$root_dir}
# if run by git, assume command is git-annex
# otherwise, don't assume, to allow other uses
cmd=
! [ "$(basename "$(readlink -e /proc/$PPID/exe)")" = "git" ] || cmd=git-annex
exec docker run -it --rm \
-u $(id -u):$(id -g) \
-v /etc/passwd:/etc/passwd:ro \
-v $HOME/.ssh:$HOME/.ssh \
-v $HOME/.gnupg:$HOME/.gnupg \
-v $HOME/.gitconfig:$HOME/.gitconfig \
-v "$root_dir":/data \
${AWS_ACCESS_KEY_ID:+-e AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID"} \
${AWS_SECRET_ACCESS_KEY:+-e AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY"} \
${B2_ACCOUNT_ID:+-e B2_ACCOUNT_ID="$B2_ACCOUNT_ID"} \
${B2_APP_KEY:+-e B2_APP_KEY="$B2_APP_KEY"} \
-w /data"$rel_dir" \
$CONT_NAME $cmd "$@"
</code></pre>