Skip to content

Commit

Permalink
Add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxantron committed Apr 29, 2017
1 parent e59e3a5 commit 65fc882
Show file tree
Hide file tree
Showing 16 changed files with 1,447 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src/config.php
*.lock
proxies/
.vagrant
mysql_db
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ For every story the Scrum Master will than start a poll and each member of the s
* Mobile apps with watch support. Imagine voting on Android Wear or Apple Watch. Wouldn't that be cool? :D

## Contribute
If you want to contribute you can just clone the repository and follow the deployment instructions. Any changes must be commited to a fork and then merged by issuing a pull request. For information on the REST API or ticketing plugins please have a look at the [wiki documentation](https://github.com/Toxantron/scrumonline/blob/master/doc/).
If you want to contribute you can just clone the repository and follow the deployment instructions. We also offer support for [Vagrant](doc/Vagrant.md) and [Docker](doc/Docker.md). Any changes must be commited to a fork and then merged by issuing a pull request. For information on the REST API or ticketing plugins please have a look at the [wiki documentation](https://github.com/Toxantron/scrumonline/blob/master/doc/).

You could also use the [REST API](https://github.com/Toxantron/scrumonline/blob/master/doc/Developer-Documentation.md) to build a mobile for iOS or Android. In that case I am happy to link your app in the README and on the page.
You can also use the [REST API](https://github.com/Toxantron/scrumonline/blob/master/doc/Developer-Documentation.md) to build a mobile for iOS or Android. In that case I am happy to link your app in the README and on the page.
2 changes: 2 additions & 0 deletions doc/Deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The app requires a couple of packages you need to install on your system. Those
- PHP >= 5.6
- MySQL, MySQL-PDO

or alternatively you can use [Vagrant](Vagrant.md) or [Docker](Docker.md).

# Webservers
- [Nginx Deployment](Deployment-Nginx.md)
- [Apache Deployment](Deployment-Apache.md)
Expand Down
56 changes: 56 additions & 0 deletions doc/Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Docker Image

based on [tutum/lamp](https://github.com/tutumcloud/lamp). It was specialized for scrumonline.

## Software Stack
The image creates a basic container of debian jessie and the standard LAMP stack.

* Apache2
* PHP5.6
* MySQL 5

## Build
The image needs to be build once on every machine before using it. Using the *docker* command may require root access.

```sh
cd docker
docker build -t scrum-lamp .
```

**Note:** When rebuilding the image the old one is not replaced. To avoid wasting disk space you should delete the old image before
running `docker build` again. Delete the old image by running:

```sh
docker rmi scrum-lamp
docker build -t scrum-lamp .
```

## Usage
While you can use the standard docker commands it is recommended to use the `docker.sh` script in the root directory.

```sh
# Prepare repository and database. This must be called before calling start for the first time
docker.sh prepare

# All other commands might require root access, e.g. 'sudo ./docker.sh start'
# Start container instance on localhost:8080 using empty database from image
docker.sh start
# Start container, but initialize and reuse database in directory 'mysql_db'
docker.sh start mysql_db

# Enter bash
docker.sh bash
# Access logs
docker.sh readlog error
docker.sh readlog access

# Access db
docker.sh db
# Start myadmin graphical UI on localhost:8081 with credentials myadmin:myadmin
docker.sh myadmin
# Stop myadmin
docker.sh myadmin stop

# Kill the running container
docker.sh stop
```
70 changes: 70 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
command=$1
current_dir=$(pwd)
container_name=scrumonline
image=scrum-lamp

case $command in
"prepare")
echo "Preparing repository for usage with docker"
php bin/composer install
cp src/sample-config.php src/config.php
# Overwrite host
echo '$host = "localhost:8080";' >> src/config.php
;;
"start")
running=$(docker ps -a -q)
if [ -n "$running" ]; then
echo "Stopping running containers"
docker stop $running
docker rm $running
fi

echo "Starting container $container_name..."
mysql_dir=$2
if [ -n "$mysql_dir" ]; then
docker run -d --name $container_name -p 8080:80 -p 3306:3306 \
-v $current_dir:/var/www/scrumonline -v $current_dir/$mysql_dir:/var/lib/mysql \
$image
else
docker run -d --name $container_name -p 8080:80 -p 3306:3306 \
-v $current_dir:/var/www/scrumonline $image
fi
echo "...done!"
;;
"stop")
echo "Stopping container $container_name..."
docker stop $container_name
docker rm $container_name
echo "...done"
;;
"readlog")
log_name=$2
if [ -n "$log_name" ]; then
docker exec -it $container_name tail -f /var/log/apache2/$log_name.log
else
echo "No log name specified"
fi
;;
"db")
docker exec -it $container_name mysql scrum_online -u root --password=passwd
;;
"myadmin")
mycommand=$2
case $mycommand in
"stop")
docker stop myadmin
docker rm myadmin
;;
*)
docker run --name myadmin -d --link $container_name:db -p 8081:80 phpmyadmin/phpmyadmin
;;
esac
;;
"bash")
docker exec -it $container_name bash
;;
"")
echo "No command specified!"
;;
esac
51 changes: 51 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM debian:jessie

# Install packages
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get -y install supervisor \
apache2 libapache2-mod-php5 \
mysql-server mysql-client php5-mysql \
php5-xdebug php5-curl php5-imagick \
curl wget vim

# Prepare apache/php config and directory
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
ADD php_config /etc/php5/apache2/php.ini
ADD php_config /etc/php5/cli/php.ini

# Utils folder
RUN mkdir /utils
RUN mkdir /utils/custom

# Run script
ADD run.sh /utils/run.sh
RUN chmod 755 /utils/run.sh

# MySQL configuration
ADD my.cnf /etc/mysql/conf.d/my.cnf
ADD mysql_init.sh /utils/mysql_init.sh
RUN chmod 755 /utils/mysql_init.sh

# Supervisor configurations
ADD supervisord-apache2.conf /etc/supervisor/conf.d/supervisord-apache2.conf
ADD supervisord-mysqld.conf /etc/supervisor/conf.d/supervisord-mysqld.conf
ADD start-apache2.sh /utils/start-apache2.sh
ADD start-mysqld.sh /utils/start-mysqld.sh

# Config with mod_rewrite
ADD apache_default /etc/apache2/sites-available/000-default.conf
ADD xdebug.ini /etc/php5/mods-available/xdebug.ini
RUN a2enmod rewrite
# Allow modification of http headers (needed for CORS)
RUN a2enmod headers

#Environment variables to configure php
ENV PHP_UPLOAD_MAX_FILESIZE 20M
ENV PHP_POST_MAX_SIZE 10M

# Add volumes for MySQL and webroot
VOLUME ["/var/lib/mysql", "/var/www/scrumonline"]

EXPOSE 80 3306
CMD ["/utils/run.sh"]
9 changes: 9 additions & 0 deletions docker/apache_default
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<VirtualHost *:80>
DocumentRoot /var/www/scrumonline/src

RewriteEngine on
RewriteRule ^/api/(\w+)/(\w+) /api.php?c=$1&m=$2 [QSA]

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
122 changes: 122 additions & 0 deletions docker/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#slow_query_log_file = /var/log/mysql/mysql-slow.log
#slow_query_log = 1
#long_query_time = 2
#log_queries_not_using_indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer = 16M
24 changes: 24 additions & 0 deletions docker/mysql_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

/usr/bin/mysqld_safe > /dev/null 2>&1 &

RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MySQL service startup"
sleep 5
mysql -uroot -e "status" > /dev/null 2>&1
RET=$?
done

# Create user for myadmin
mysql -uroot -e "CREATE USER 'myadmin'@'%' IDENTIFIED BY 'myadmin'"
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'myadmin'@'%'"
# Create database and set root password to match config
mysql -uroot -e "CREATE DATABASE scrum_online"
mysql -uroot -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('passwd');"

# Create database schema
pushd /var/www/scrumonline
./vendor/bin/doctrine orm:schema-tool:create
./vendor/bin/doctrine orm:generate-proxies
popd
Loading

0 comments on commit 65fc882

Please sign in to comment.