contrib/docker/apache-server/entrypoint.sh
changeset 23399 fd5247a88e63
equal deleted inserted replaced
23398:9da5a7413eb8 23399:fd5247a88e63
       
     1 #!/bin/bash
       
     2 
       
     3 # This script gets executed on container start. Its job is to set up
       
     4 # the Mercurial environment and invoke the server.
       
     5 
       
     6 # Mercurial can be started in two modes.
       
     7 # If the MERCURIAL_SOURCE environment variable is set and it points to a
       
     8 # Mercurial source directory, we will install Mercurial from that directory.
       
     9 # Otherwise, we download the Mercurial source and install it manually.
       
    10 
       
    11 set -e
       
    12 
       
    13 SOURCE_DIR=/var/hg/source
       
    14 INSTALL_DIR=/var/hg/install
       
    15 REPOS_DIR=/var/hg/repos
       
    16 HTDOCS_DIR=/var/hg/htdocs
       
    17 
       
    18 if [ ! -d ${SOURCE_DIR} ]; then
       
    19   echo "Mercurial source not available at ${SOURCE_DIR}"
       
    20   echo "You need to mount a volume containing the Mercurial source code"
       
    21   echo "when running the container. For example:"
       
    22   echo ""
       
    23   echo "  $ docker run -v ~/src/hg:/${SOURCE_DIR} hg-apache"
       
    24   echo ""
       
    25   echo "This container will now stop running."
       
    26   exit 1
       
    27 fi
       
    28 
       
    29 echo "Installing Mercurial from ${SOURCE_DIR} into ${INSTALL_DIR}"
       
    30 pushd ${SOURCE_DIR}
       
    31 /usr/bin/python2.7 setup.py install --root=/ --prefix=${INSTALL_DIR} --force
       
    32 popd
       
    33 
       
    34 mkdir -p ${HTDOCS_DIR}
       
    35 
       
    36 # Provide a default config if the user hasn't supplied one.
       
    37 if [ ! -f ${HTDOCS_DIR}/config ]; then
       
    38   cp /defaulthgwebconfig ${HTDOCS_DIR}/config
       
    39 fi
       
    40 
       
    41 if [ ! -f ${HTDOCS_DIR}/hgweb.wsgi ]; then
       
    42   cat >> ${HTDOCS_DIR}/hgweb.wsgi << EOF
       
    43 config = '${HTDOCS_DIR}/config'
       
    44 
       
    45 import sys
       
    46 sys.path.insert(0, '${INSTALL_DIR}/lib/python2.7/site-packages')
       
    47 
       
    48 from mercurial import demandimport
       
    49 demandimport.enable()
       
    50 
       
    51 from mercurial.hgweb import hgweb
       
    52 application = hgweb(config)
       
    53 EOF
       
    54 fi
       
    55 
       
    56 mkdir -p ${REPOS_DIR}
       
    57 
       
    58 if [ ! -d ${REPOS_DIR}/repo ]; then
       
    59   ${INSTALL_DIR}/bin/hg init ${REPOS_DIR}/repo
       
    60   chown -R www-data:www-data ${REPOS_DIR}/repo
       
    61 fi
       
    62 
       
    63 # This is necessary to make debuginstall happy.
       
    64 if [ ! -f ~/.hgrc ]; then
       
    65   cat >> ~/.hgrc << EOF
       
    66 [ui]
       
    67 username = Dummy User <nobody@example.com>
       
    68 EOF
       
    69 fi
       
    70 
       
    71 echo "Verifying Mercurial installation looks happy"
       
    72 ${INSTALL_DIR}/bin/hg debuginstall
       
    73 
       
    74 . /etc/apache2/envvars
       
    75 
       
    76 echo "Starting Apache HTTP Server on port 80"
       
    77 echo "We hope you remembered to publish this port when running the container!"
       
    78 echo "If this is an interactive container, simply CTRL^C to stop."
       
    79 
       
    80 exec "$@"