| 1 |
#!/bin/bash |
| 2 |
#emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- |
| 3 |
#ex: set sts=4 ts=4 sw=4 noet: |
| 4 |
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## |
| 5 |
# |
| 6 |
# See COPYING file distributed along with the datalad package for the |
| 7 |
# copyright and license terms. |
| 8 |
# |
| 9 |
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## |
| 10 |
# |
| 11 |
# Helper to generate a Docker instance mapping user uder docker into your USER/UID/GID |
| 12 |
# and allowing to run tox within that clean automatically generated according to |
| 13 |
# README.md's apt-get lines environment |
| 14 |
# |
| 15 |
set -e |
| 16 |
export PS4=+ |
| 17 |
#set -x |
| 18 |
set -u |
| 19 |
|
| 20 |
DL_DIST=${1:-jessie} |
| 21 |
|
| 22 |
topdir=$(readlink -f `dirname $0`) |
| 23 |
cd `dirname $0` |
| 24 |
dockerfile=$topdir/start_website_in_docker-Dockerfile |
| 25 |
# echo "D: $DL_APT" |
| 26 |
sed -e "s,DL_DIST,$DL_DIST,g" \ |
| 27 |
-e "s,DL_USER,$USER,g" \ |
| 28 |
-e "s,DL_UID,`id -u`,g" \ |
| 29 |
-e "s,DL_GID,`id -g`,g" \ |
| 30 |
-e "s,DL_GIT_USER_EMAIL,`git config --get user.email`,g" \ |
| 31 |
-e "s,DL_GIT_USER_NAME,`git config --get user.name`,g" \ |
| 32 |
$dockerfile.in >| $dockerfile |
| 33 |
|
| 34 |
#DL_APT=$(grep '^\(apt-get\|pip\)' ./../../README.md) |
| 35 |
|
| 36 |
{ |
| 37 |
# grep '^apt-get ' $topdir/../../README.md | sed -e 's|python-{|python{,3}-{|g'; \ |
| 38 |
echo "eatmydata apt-get install -q -y build-essential datalad python-pip python-virtualenv;" |
| 39 |
echo "eatmydata apt-get install -q -y libffi-dev libssl-dev python-dev;" |
| 40 |
# Install dependencies and remove system wide datalad |
| 41 |
echo "eatmydata dpkg --purge datalad python-datalad;" |
| 42 |
} | while read aptline; do |
| 43 |
sed -i -e "s|\(\(.*\)DL_APT\(.*\)\)|\2$aptline\3\n\1|g" $dockerfile |
| 44 |
: |
| 45 |
done |
| 46 |
sed -e '/DL_APT/d' -i $dockerfile |
| 47 |
|
| 48 |
echo "I: copy authorized keys so they become avail inside" |
| 49 |
cp ~/.ssh/authorized_keys $topdir/conf/ |
| 50 |
|
| 51 |
tag_=website_${USER}_${DL_DIST} |
| 52 |
tag=datalad:${tag_} |
| 53 |
echo "I: tag $tag" |
| 54 |
if docker images | grep -q datalad.*${tag_}; then |
| 55 |
echo "I: tag already exists -- skipping rebuilding" |
| 56 |
else |
| 57 |
docker build -t $tag -f $dockerfile . #&& rm Dockerfile |
| 58 |
#docker build --no-cache=True -t $tag -f $dockerfile . #&& rm Dockerfile |
| 59 |
fi |
| 60 |
|
| 61 |
topgitdir=`readlink -f ${topdir}/../..` |
| 62 |
echo "I: top git dir $topgitdir" |
| 63 |
|
| 64 |
#set -x |
| 65 |
docker_id=`docker ps | awk "/\\<$tag\\>/{print \\$1}"` |
| 66 |
echo "D: looking for a docker with tag '$tag': $docker_id" |
| 67 |
if [ -z "$docker_id" ]; then |
| 68 |
stopped_docker_id=`docker ps -a | awk "/\\<$tag\\>/{print \\$1}"` |
| 69 |
if [ -z "$stopped_docker_id" ]; then |
| 70 |
echo "I: Starting new container with apache running" |
| 71 |
docker_id=`docker run -d \ |
| 72 |
-v $topgitdir:/home/$USER/datalad \ |
| 73 |
-p 127.0.0.1:8081:80 \ |
| 74 |
-p 127.0.0.1:2221:22 \ |
| 75 |
$tag` |
| 76 |
echo "Started container $docker_id" |
| 77 |
|
| 78 |
# ATM pip freaks out with obnoxious message |
| 79 |
# of parse error at "'__placeh'". So we better upgrade pip while at it |
| 80 |
# see https://github.com/pypa/pip/issues/3659 |
| 81 |
echo "I: upgrading pip to avoid obnoxious problems" |
| 82 |
docker exec $docker_id bash -c "pip install -U pip --force-reinstall" |
| 83 |
|
| 84 |
echo "I: installing datalad inside (in development mode)" |
| 85 |
# crap -- in sid image finishes with |
| 86 |
# Segmentation fault (core dumped) |
| 87 |
# yoh@8c3178bd7ea7:~/datalad$ echo $? |
| 88 |
# 139 |
| 89 |
docker exec $docker_id bash -c "cd datalad; pip install -e ." |
| 90 |
else |
| 91 |
echo "I: starting previous docker container $stopped_docker_id" |
| 92 |
docker_id=`docker start $stopped_docker_id` |
| 93 |
echo "Started container $docker_id" |
| 94 |
fi |
| 95 |
else |
| 96 |
echo "Using running container $docker_id" |
| 97 |
fi |
| 98 |
|
| 99 |
docker_git_version=`docker exec $docker_id git --version 2>&1 | cut -d ' ' -f 3` |
| 100 |
if dpkg --compare-versions $docker_git_version lt 2.4; then |
| 101 |
echo "I: too old of a git, let's symlink the one from git-annex-standalone" |
| 102 |
for f in git git-receive-pack git-upload-pack; do |
| 103 |
docker exec $docker_id ln -sf /usr/lib/git-annex.linux/$f /usr/local/bin/$f |
| 104 |
done |
| 105 |
fi |
| 106 |
|
| 107 |
cat <<EOF |
| 108 |
------------------------- |
| 109 |
You now should be able to upload to this host under ssh://localhost:2221:/var/www/html, |
| 110 |
which should then be made available under http://localhost:8081 . |
| 111 |
It is recommended to create ~/.ssh/config entry |
| 112 |
|
| 113 |
Host dataladlocalhost |
| 114 |
Port 2221 |
| 115 |
Hostname localhost |
| 116 |
StrictHostKeyChecking no |
| 117 |
|
| 118 |
EOF |