comparison contrib/docker/apache-server/entrypoint.sh @ 23399:fd5247a88e63

docker: add Docker files for running an Apache mod_wsgi server I frequently find myself wanting to run hgweb in a production-like environment, with a real HTTP server and multiple WSGI workers. This patch introduces a Docker environment for running Mercurial under Apache + mod_wsgi. With just a few command executions, it is possible to spin up a Docker container running hgweb. The container is tailored for Mercurial developers wanting to run Mercurial from a source checkout. It is **not** meant to be something suitable for production use. The container provides a default hgweb environment with an empty repository that allows pushes. You can thus start a container and push your favorite repository there for quick testing. The container is designed to allow customizations. Users can provide their own hgweb configurations and mount existing directories containing repositories into the container. The behavior of the container and how to control things is documented in the README.rst file.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 11 Nov 2014 20:32:10 -0800
parents
children
comparison
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 "$@"