Skip to content

Commit

Permalink
Add support for building Freeciv-web using Docker. See the README.md …
Browse files Browse the repository at this point in the history
…and Dockerfile for more info.
  • Loading branch information
andreasrosdal committed Sep 14, 2015
1 parent cb00251 commit 28e5517
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ python:
before_script:
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('vagrant') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root

script: "sudo bash ./scripts/freeciv-web-travis.sh"
script: "sudo bash ./scripts/travis-build.sh"


26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Freeciv-web docker file
FROM ubuntu:14.04

MAINTAINER The Freeciv Project version: 2.5

RUN apt-get update && apt-get -y upgrade && apt-get install -y maven mysql-server openjdk-7-jdk libcurl4-openssl-dev nginx libjansson-dev subversion pngcrush python3-pillow libtool automake autoconf autotools-dev language-pack-en python3.4-dev python3-setuptools libbz2-dev imagemagick python3-pip dos2unix liblzma-dev firefox xvfb libicu-dev pkg-config zlib1g-dev wget curl

RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en

RUN useradd -ms /bin/bash freeciv

ADD freeciv /docker/freeciv
ADD freeciv-proxy /docker/freeciv-proxy
ADD freeciv-web /docker/freeciv-web
ADD publite2 /docker/publite2
ADD scripts /docker/scripts
ADD tests /docker/tests
ADD LICENSE.txt /docker/LICENSE.txt

RUN sudo /docker/scripts/docker-build.sh


EXPOSE 80

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ The Vagrant guest machine will mount the Freeciv-web source repository in the /v
Note that running Freeciv-web using Vagrant requires about 4Gb of memory
and 3 Gb of harddisk space.

Running Freeciv-web with Docker
-------------------------------
Freeciv-web can be built automatically using Docker https://www.docker.com/
This was tested using Docker 1.8.2 with Ubuntu 14.04 as the base image.
Also see the [Dockerfile](Dockerfile) for more information.

1. Install Docker, then get the Freeciv-web source code like this:
```bash
git clone https://github.com/freeciv/freeciv-web.git --depth=10
```

2. Build the Freeciv-web docker container by giving the following command:
```bash
docker build -t="freeciv-web" .
```
3. Then run the Freeciv-web docker container with this command:
```bash
docker run -d -p 80:80 -t freeciv-web
```

System Requirements for manual install
--------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end

# run the Freeciv bootstrap script on startup
config.vm.provision :shell, :path => "scripts/freeciv-web-vagrant.sh"
config.vm.provision :shell, :path => "scripts/vagrant-build.sh"


end
124 changes: 124 additions & 0 deletions scripts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash

# Freeciv-web Docker Bootstrap Script - play.freeciv.org
# 2015-09-12 - Andreas Rosdal
#
basedir="/docker"
logfile="/docker/freeciv-web-docker.log"

# Redirect copy of output to a log file.
exec > >(tee ${logfile})
exec 2>&1
set -e

echo "================================="
echo "Running Freeciv-web setup script."
echo "================================="

uname -a
echo basedir $basedir
echo logfile $logfile

# User will need permissions to create a database
mysql_user="root"
mysql_pass=""

resin_version="4.0.44"
resin_url="http://www.caucho.com/download/resin-${resin_version}.tar.gz"
tornado_url="https://pypi.python.org/packages/source/t/tornado/tornado-4.2.1.tar.gz"
slimerjs_url="https://download.slimerjs.org/nightlies/0.10.0pre/slimerjs-0.10.0pre.zip"
casperjs_url="https://github.com/n1k0/casperjs/archive/1.1-beta3.zip"


## Setup
mkdir -p ${basedir}
chmod -R 777 ${basedir}
cd ${basedir}

## dependencies
echo "==== Installing Updates and Dependencies ===="
export DEBIAN_FRONTEND=noninteractive
echo "mysql setup..."
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password ${mysql_pass}"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${mysql_pass}"

## build/install resin
echo "==== Fetching/Installing Resin ${resin_version} ===="
wget ${resin_url}
tar xvfz resin-${resin_version}.tar.gz
rm -Rf resin
mv resin-${resin_version} resin
mkdir -p resin/log
touch resin/log/watchdog-manager.log
chmod -R 777 resin


echo "==== Fetching/Installing Tornado Web Server ===="
cd /tmp
wget ${tornado_url}
tar xvfz tornado-4.2.1.tar.gz
cd tornado-4.2.1
python3.4 setup.py install

pip3 install wikipedia

## mysql setup
echo "==== Setting up MySQL ===="
service mysql start
echo "create database freeciv_web" | mysql --socket=/var/run/mysqld/mysqld.sock -u ${mysql_user}
mysql --socket=/var/run/mysqld/mysqld.sock -u ${mysql_user} freeciv_web < ${basedir}/freeciv-web/src/main/webapp/meta/private/metaserver.sql

# configuration files
dos2unix ${basedir}/scripts/configuration.sh.dist
sed -e "s/MYSQL_USER=root/MYSQL_USER=${mysql_user}/" -e "s/MYSQL_PASSWORD=changeme/MYSQL_PASSWORD=${mysql_pass}/" ${basedir}/scripts/configuration.sh.dist > ${basedir}/scripts/configuration.sh
cp ${basedir}/publite2/settings.ini.dist ${basedir}/publite2/settings.ini

echo "==== Building freeciv ===="
dos2unix ${basedir}/freeciv/freeciv-web.project
cd ${basedir}/freeciv && ./prepare_freeciv.sh
cd freeciv && make install

echo "==== Building freeciv-web ===="
sed -e "s/user>root/user>${mysql_user}/" -e "s/password>changeme/password>${mysql_pass}/" ${basedir}/freeciv-web/src/main/webapp/WEB-INF/resin-web.xml.dist > ${basedir}/freeciv-web/src/main/webapp/WEB-INF/resin-web.xml
cd ${basedir}/scripts/freeciv-img-extract/ && ./setup_links.sh && ./sync.sh
cd ${basedir}/scripts && ./sync-js-hand.sh
cd ${basedir}/freeciv-web && sudo ./setup.sh

echo "=============================="

service nginx stop
rm /etc/nginx/sites-enabled/default
cp ${basedir}/publite2/nginx.conf /etc/nginx/

# add Freeciv-web scripts to path
export PATH=$PATH:/docker/scripts

if [ -d "/docker/" ]; then
echo "Starting Freeciv-web..."
service nginx start
mkdir -p ${basedir}/logs
chmod 777 ${basedir}/logs
cd ${basedir}/scripts/ && sudo -u freeciv ./start-freeciv-web.sh
else
echo "Freeciv-web installed. Please start it manually."
fi

echo "============================================"
echo "Installing SlimerJS and CasperJS for testing"
export SLIMERJSLAUNCHER=/usr/bin/firefox
export SLIMERJS_EXECUTABLE=${basedir}/tests/slimerjs-0.10.0pre/slimerjs
cd ${basedir}/tests
wget --no-check-certificate ${slimerjs_url}
unzip -qo slimerjs-0.10.0pre.zip

wget ${casperjs_url}
unzip -qo 1.1-beta3.zip
cd casperjs-1.1-beta3
ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs

echo "Start testing of Freeciv-web using CasperJS:"
cd ${basedir}/tests/
xvfb-run casperjs --engine=slimerjs test freeciv-web-tests.js || (>&2 echo "Freeciv-web CasperJS tests failed!" && exit 1)

echo "Freeciv-web started! Now try to access Freeciv-web with the docker machine IP in your browser.."
/bin/bash
6 changes: 6 additions & 0 deletions scripts/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

service mysql start
service nginx start
cd /docker/scripts/
sudo -u freeciv ./start-freeciv-web.sh
File renamed without changes.
File renamed without changes.

0 comments on commit 28e5517

Please sign in to comment.