├── .gitignore ├── README.md ├── cron ├── Dockerfile └── cron-conf │ └── crontab ├── db ├── Dockerfile └── tutum │ └── tutum-docker-mysql │ ├── 5.5 │ ├── Dockerfile │ ├── create_db.sh │ ├── import_sql.sh │ ├── my.cnf │ ├── mysqld_charset.cnf │ └── run.sh │ ├── 5.6 │ ├── Dockerfile │ ├── create_db.sh │ ├── import_sql.sh │ ├── my.cnf │ ├── mysqld_charset.cnf │ └── run.sh │ ├── LICENSE │ ├── README.md │ └── circle.yml ├── figures └── brc-u-logos │ └── KHP_M_oneline_descriptor_strapline_hr_CMYK-e1409244956134.jpg ├── web-base ├── Dockerfile ├── a_logfile.sh ├── cron-conf.sh ├── parse_redcap_config.sh └── run └── web ├── Dockerfile ├── a_logfile.sh ├── cron-conf.sh ├── cron-conf └── crontab ├── database.php ├── download └── README ├── env.list ├── index.php ├── parse_redcap_config.sh └── tutum └── tutum-docker-php ├── Dockerfile ├── Dockerfile-tutum_ori ├── LICENSE ├── Makefile ├── README-mods.md ├── README.md ├── circle.yml ├── run └── sample ├── index.php └── logo.png /.gitignore: -------------------------------------------------------------------------------- 1 | web/download/redcap/ 2 | *.pwd 3 | *.sql 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #REDCAP DOCKER BUILD 2 | [Funded by Biomedical Research Centre](http://core.brc.iop.kcl.ac.uk): http://core.brc.iop.kcl.ac.uk 3 | 4 | *Institution: NIHR Maudsley Biomedical Research Centre For Mental Health and Dementia Unit (Denmark Hill), at The Institute of Psychiatry, Psychology & Neuroscience (IoPPN), Kings College London* 5 | 6 | Author(s): Amos Folarin 7 | 8 | Release Version: 9 | 10 | ## Redcap Dockerfiles 11 | With these instructions you should be able to build the redcap-docker images 12 | which should then be deployable relatively simply in any environment running Docker. We have found these containers useful for testing. 13 | 14 | ## Distributing Docker Image 15 | I'm not making a public image of this available on DockerHub, the licence for RedCap precludes this. 16 | Instead, if you want to use this building it from the docker files is straightforward, see below. 17 | You will need: 18 | 1. clone the git repository https://github.com/KHP-Informatics/redcap-docker 19 | 2. Get the web application from the redcap project at http://www.project-redcap.org/ 20 | and unzip it in to web/download/ dir (see the web/download/README) 21 | 3. [optional] Get the pdf fonts especially for international projects 22 | https://iwg.devguard.com/trac/redcap/browser/misc/webtools2-pdf.zip?format=raw unzip webtools2-pdf.zip and 23 | place the pdf directory replacing the existing web/download/redcap/webtools2/pdf dir. 24 | 4. build your containers (see below) 25 | 26 | 27 | ## Build instructions 28 | There are three components the database, the cron base-image and the redcap web application. 29 | ### Build containers locally from the Dockerfiles 30 | 31 | 1. cd into the web/ or db/ dir so we have the right build context: 32 | ```sh 33 | #build the database container 34 | $ cd db 35 | $ docker build --tag="afolarin/redcap:mysql" . 36 | 37 | #build the base-image for the web-app 38 | $ cd ../web-base 39 | $ docker build --tag="afolarin/cron-apache-php" . 40 | 41 | #build the redcap web-app 42 | $ cd ../web 43 | $ docker build --tag="afolarin/redcap:webapp" . 44 | 45 | #NOTE substitute the 'afolarin' for your dockerhub repo [optional] 46 | ``` 47 | 48 | ### Run the containers 49 | 1. Start the database. This is based on Tutum's mysql image. 50 | https://github.com/tutumcloud/tutum-docker-mysql 51 | https://registry.hub.docker.com/u/tutum/mysql/ 52 | ```sh 53 | #start the db container (default mounts vol /etc/mysql and /var/lib/mysql in volumes) 54 | $ docker run --name="redcap-db" -d -p 3306:3306 afolarin/redcap:mysql 55 | 56 | #wait till the container is created then get some information required for the redcap-docker/web/env.list file 57 | $ docker logs redcap-db &> mysql.pwd; 58 | $ docker inspect --format='{{.NetworkSettings.IPAddress}}' redcap-db &>> mysql.pwd; 59 | $ docker inspect --format='{{.NetworkSettings.Ports}}' redcap-db &>> mysql.pwd; 60 | 61 | #add the random generated password to the env file 62 | $ cat mysql.pwd 63 | $ vi ../web/env.list 64 | # change the MYSQL_PASS='' to the file password listed in mysql.pwd 65 | ``` 66 | 67 | 2. Start the webapplication, this will link to the MySQL database container. It is based on Tutum's 68 | Apache-PHP image. 69 | https://github.com/tutumcloud/tutum-docker-php 70 | https://registry.hub.docker.com/u/tutum/apache-php/ 71 | ```sh 72 | $ cd ../web 73 | $ docker run -d --name="redcap-web" -v $(pwd)/cron-conf/:/cron-conf/ --link="redcap-db:REDCAP_DB" --env-file="env.list" --publish="80:80" afolarin/redcap:webapp 74 | ``` 75 | 76 | ### Complete the installation via the browser 77 | ```sh 78 | #get the redcap:webapp host ip address (or use the public IP of your server) 79 | $ docker inspect --format='{{.NetworkSettings.IPAddress}}' redcap-web 80 | #point the browser to IP/redcap/install.php , req. if not port 80 81 | # e.g. http://172.17.0.12:/redcap/install.php 82 | ``` 83 | 84 | 1. Complete the registration. 85 | 86 | 2. Exec SQL statements to create the database 87 | * Copy the statements from the browser 88 | * save in a file e.g. redcap-tables.sql 89 | * $ mysql -h -uadmin -p'pwd-in-mysqsl.pwd' redcap < redcap-tables.sql 90 | **NOTE**: don't try to paste these sql statements into the terminal, it's pretty fragile. \ 91 | Pipe it instead as above. Or even better this little trick \ 92 | (docker exec -i redcap-db mysql -uadmin -padminDbUserPwd) < redcap-db-build.sql 93 | **NOTE** in more recent versions of Redcap, redcap database is now called "redcap_mysql", not "redcap" (and is db is created for you) 94 | 95 | 3. Check everything works? 96 | * see config testpage e.g.: http:///redcap/redcap_v6.0.12/ControlCenter/check.php?upgradeinstall=1 97 | * goto http:///redcap 98 | * go to "Control Centre>>File Upload Settings>>SET LOCAL FILE STORAGE LOCATION:" set to /edocs \ 99 | (you can change folder, but it should not be web accessible) 100 | * SEE HERE ON CREATING A SUPER-ADMIN: https://iwg.devguard.com/trac/redcap/wiki/ChangingAuthenticationMethod create and designate a superadmin before you switch from public authentication mode (or you'll be locked out) 101 | * Create a test project 102 | 103 | 4. Commit the image, for your future use, DO NOT PUBLISH IMAGE redcap is not opensource! 104 | 105 | 5. Use these images to deploy your redcap instances (remember to push in a new password for each client) 106 | 107 | 6. NOTE: there is no default authentication, and access remains open. The default user is side_admin 108 | To fix there are a variety of Authentication options see: 109 | https://iwg.devguard.com/trac/redcap/wiki/ChangingAuthenticationMethod 110 | But the simplest is "Table Based" instructions for setting up are below: 111 | 112 | * How to change from "None (Public)" to "Table-based" authentication 113 | 114 | * Before simply changing the authentication method, you will first need to create for yourself a new Table-based user that you yourself will use to log in to REDCap. Navigate to the Create New User page in the Control Center and create a new user (you will have to decide what your username will be). Once created, it will send an email to you with your username and a temporary password enclosed. 115 | * Before looking in your inbox, go to the Designate Super User page in the Control Center and add your user as a super user. This ensures that you will be able to access the Control Center again when you log in with your new Table-based user in a minute. 116 | * Now go to the Security & Authentication page in the Control Center and change the authentication method to Tabled-based (at top of page) and save your changes on that page. Now click on any link/tab on the page, which will now force you to log in with your new Table-based username. 117 | * Log in to REDCap with your new username and the password sent to you in the email. It will then ask you to set your password. 118 | Now that you have logged in with your new username, go back to the Designate Super User page and remove "site_admin" as a super user. 119 | * You're done and can now go and begin giving other users access to REDCap by creating them a username on the Create New User page. 120 | * You will also be required to change the Project Settings from "Public" to "Table Based" (in Control Centre>>Edit a PRoject's Settings) 121 | 122 | 7. You may want to also add some custom validations e.g. uk_postcode. (login to the mysql container (either with a mysql client either external or via docker-exec)) 123 | 8. run these SQL inserts for some additional validation types: 124 | * uk postcode validation: 125 | ```sql 126 | INSERT INTO `redcap_validation_types` (validation_name, validation_label, regex_js, regex_php, data_type, legacy_value, visible) VALUES ('uk_postcode', 'uk_postcode', '/^[A-Z]{1,2}\d{1,3}[ \t]+\d{1,2}[A-Z]{2}$/i', '/^[A-Z]{1,2}\d{1,3}[ \t]+\d{1,2}[A-Z]{2}$/i', 'text', \N , '1');` 127 | ``` 128 | * Should give you: 129 | 130 | validation_name: uk_postcode 131 | validation_label: UK Postcode 132 | regex_js: /^[A-Z]{1,2}\d{1,3}[ \t]+\d{1,2}[A-Z]{2}$/i 133 | regex_php: /^[A-Z]{1,2}\d{1,3}[ \t]+\d{1,2}[A-Z]{2}$/i 134 | data_type: text 135 | legacy_value: NULL 136 | visible: 1 137 | 138 | #Restarting the Redcap Containers 139 | If you restart the containers you'll probably see an error in the browser saying that the /app/redcap/database.php probably has the wrong ipaddress, username, password -- the problem will be the ipaddress. 140 | 141 | Note (until I have sorted deploying these with Compose and native networking) we are still stuck with ip addresses which change when you restart the container! The simple solution is to enter the container and change the /app/redcap/database.php file to the new database container's ip address. 142 | ```sh 143 | #from the host 144 | #get the new db IP address 145 | $ docker inspect -it redcap-db | grep IPAddress 146 | 147 | #enter the web-app container 148 | $ docker exec -it redcap-web /bin/bash 149 | 150 | #change $hostname = '172.17.0.3'; to the correct ip address 151 | vi /app/redcap/database.php 152 | 153 | 154 | #refresh the browser and you should be back in action 155 | 156 | ``` 157 | 158 | 159 | 160 | ![Kings Health Partners](figures/brc-u-logos/KHP_M_oneline_descriptor_strapline_hr_CMYK-e1409244956134.jpg) 161 | -------------------------------------------------------------------------------- /cron/Dockerfile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # Dockerized Redcap for deploying in a variety of environments 3 | #------------------------------------------------------------------------------ 4 | 5 | #The Containers in the System: 6 | # 1) [afolarin/redcap:mysql] 7 | # 2) [afolarin/redcap:webapp] 8 | # 3) [afolarin/redcap:cron] 9 | 10 | # USAGE: 11 | # docker run -d --name="redcap-cron" -v $(pwd)/cron-conf:/cron --volumes-from="redcap-web" afolarin/redcap:cron 12 | 13 | #------------------------------------------------------------------------------ 14 | # Cron Container -- redcap requires a cron process to run /app/redcap/cron.php 15 | # redcap folder is exposed as a volume by the redcap-web container, inside is 16 | # is /redcap/cron.php. The crontab file (crontab) is in the mounted host folder 17 | # cron/cron-conf this is passed to the containers devcron process 18 | # 19 | #------------------------------------------------------------------------------ 20 | 21 | FROM python:2.7 22 | 23 | MAINTAINER Amos Folarin 24 | 25 | # Need hg to download devcron 26 | RUN apt-get update && apt-get install -y mercurial 27 | 28 | #install devcron, there are issues running crontab in a docker container 29 | RUN pip install -e hg+https://bitbucket.org/dbenamy/devcron#egg=devcron 30 | 31 | #setup php alternatives to point to php5 32 | RUN ln -s -T /usr/bin/php5 /etc/alternatives/php 33 | 34 | # Setup defaults 35 | RUN mkdir /cron && \ 36 | echo "* * * * * /cron/sample.sh" > /cron/crontab && \ 37 | echo "echo hello world" > /cron/sample.sh && \ 38 | chmod a+x /cron/sample.sh 39 | 40 | #VOLUME ["/cron"] 41 | 42 | CMD ["devcron.py", "/cron/crontab"] 43 | -------------------------------------------------------------------------------- /cron/cron-conf/crontab: -------------------------------------------------------------------------------- 1 | # REDCap Cron Job (runs every minute) 2 | * * * * * /usr/bin/php /app/redcap/cron.php > /dev/null 3 | -------------------------------------------------------------------------------- /db/Dockerfile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # Dockerized Redcap for deploying in a variety of environments 3 | #------------------------------------------------------------------------------ 4 | 5 | #The Containers in the System: 6 | # 1) [afolarin/redcap:mysql] 7 | # 2) [afolarin/redcap:webapp] 8 | # 3) [afolarin/redcap:cron] 9 | 10 | #USAGE (from redcap-docker/db): 11 | # docker run --name="redcap-db" -d -p 3306:3306 afolarin/redcap:mysql; 12 | # docker logs redcap-db &> mysql.pwd; 13 | # docker inspect --format='{{.NetworkSettings.IPAddress}}' redcap-db &>> mysql.pwd; 14 | # docker inspect --format='{{.NetworkSettings.Ports}}' redcap-db &>> mysql.pwd; 15 | 16 | #------------------------------------------------------------------------------ 17 | # Database Container: MySQL 18 | #------------------------------------------------------------------------------ 19 | 20 | FROM tutum/mysql 21 | 22 | MAINTAINER Amos Folarin 23 | 24 | 25 | # Use the /run.sh script to create the redcap_admin db user -- should be easy 26 | # it may be necessary to remove the admin db user after all installation is done 27 | # they are required for initial table creation otherwise drop add then drop 28 | # CREAT grants for redcap_admin db user. 29 | 30 | 31 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.5/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | MAINTAINER Fernando Mayo , Feng Honglin 3 | 4 | # Install packages 5 | ENV DEBIAN_FRONTEND noninteractive 6 | RUN apt-get update && \ 7 | apt-get -yq install mysql-server-5.5 pwgen && \ 8 | rm -rf /var/lib/apt/lists/* 9 | 10 | # Remove pre-installed database 11 | RUN rm -rf /var/lib/mysql/* 12 | 13 | # Add MySQL configuration 14 | ADD my.cnf /etc/mysql/conf.d/my.cnf 15 | ADD mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf 16 | 17 | # Add MySQL scripts 18 | ADD import_sql.sh /import_sql.sh 19 | ADD run.sh /run.sh 20 | RUN chmod 755 /*.sh 21 | 22 | # Exposed ENV 23 | ENV MYSQL_USER admin 24 | ENV MYSQL_PASS **Random** 25 | 26 | # Replication ENV 27 | ENV REPLICATION_MASTER **False** 28 | ENV REPLICATION_SLAVE **False** 29 | ENV REPLICATION_USER replica 30 | ENV REPLICATION_PASS replica 31 | 32 | # Add VOLUMEs to allow backup of config and databases 33 | VOLUME ["/etc/mysql", "/var/lib/mysql"] 34 | 35 | EXPOSE 3306 36 | CMD ["/run.sh"] 37 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.5/create_db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -eq 0 ]]; then 4 | echo "Usage: $0 " 5 | exit 1 6 | fi 7 | 8 | /usr/bin/mysqld_safe > /dev/null 2>&1 & 9 | 10 | echo "=> Creating database $1" 11 | RET=1 12 | while [[ RET -ne 0 ]]; do 13 | sleep 5 14 | mysql -uroot -e "CREATE DATABASE $1" 15 | RET=$? 16 | done 17 | 18 | mysqladmin -uroot shutdown 19 | 20 | echo "=> Done!" 21 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.5/import_sql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -ne 3 ]]; then 4 | echo "Usage: $0 " 5 | exit 1 6 | fi 7 | 8 | echo "=> Starting MySQL Server" 9 | /usr/bin/mysqld_safe > /dev/null 2>&1 & 10 | PID=$! 11 | 12 | RET=1 13 | while [[ RET -ne 0 ]]; do 14 | echo "=> Waiting for confirmation of MySQL service startup" 15 | sleep 5 16 | mysql -u"$1" -p"$2" -e "status" > /dev/null 2>&1 17 | RET=$? 18 | done 19 | 20 | echo " Started with PID ${PID}" 21 | 22 | echo "=> Importing SQL file" 23 | mysql -u"$1" -p"$2" < "$3" 24 | 25 | echo "=> Stopping MySQL Server" 26 | mysqladmin -u"$1" -p"$2" shutdown 27 | 28 | echo "=> Done!" 29 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.5/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | bind-address=0.0.0.0 3 | #server-id 4 | #log-bin 5 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.5/mysqld_charset.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | character_set_server=utf8 3 | character_set_filesystem=utf8 4 | collation-server=utf8_general_ci 5 | init-connect='SET NAMES utf8' 6 | init_connect='SET collation_connection = utf8_general_ci' 7 | skip-character-set-client-handshake -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.5/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VOLUME_HOME="/var/lib/mysql" 4 | CONF_FILE="/etc/mysql/conf.d/my.cnf" 5 | LOG="/var/log/mysql/error.log" 6 | 7 | # Set permission of config file 8 | chmod 644 ${CONF_FILE} 9 | chmod 644 /etc/mysql/conf.d/mysqld_charset.cnf 10 | 11 | StartMySQL () 12 | { 13 | /usr/bin/mysqld_safe > /dev/null 2>&1 & 14 | 15 | # Time out in 1 minute 16 | LOOP_LIMIT=13 17 | for (( i=0 ; ; i++ )); do 18 | if [ ${i} -eq ${LOOP_LIMIT} ]; then 19 | echo "Time out. Error log is shown as below:" 20 | tail -n 100 ${LOG} 21 | exit 1 22 | fi 23 | echo "=> Waiting for confirmation of MySQL service startup, trying ${i}/${LOOP_LIMIT} ..." 24 | sleep 5 25 | mysql -uroot -e "status" > /dev/null 2>&1 && break 26 | done 27 | } 28 | 29 | CreateMySQLUser() 30 | { 31 | StartMySQL 32 | if [ "$MYSQL_PASS" = "**Random**" ]; then 33 | unset MYSQL_PASS 34 | fi 35 | 36 | PASS=${MYSQL_PASS:-$(pwgen -s 12 1)} 37 | _word=$( [ ${MYSQL_PASS} ] && echo "preset" || echo "random" ) 38 | echo "=> Creating MySQL user ${MYSQL_USER} with ${_word} password" 39 | 40 | mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '$PASS'" 41 | mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION" 42 | 43 | 44 | echo "=> Done!" 45 | 46 | echo "========================================================================" 47 | echo "You can now connect to this MySQL Server using:" 48 | echo "" 49 | echo " mysql -u$MYSQL_USER -p$PASS -h -P" 50 | echo "" 51 | echo "Please remember to change the above password as soon as possible!" 52 | echo "MySQL user 'root' has no password but only allows local connections" 53 | echo "========================================================================" 54 | 55 | mysqladmin -uroot shutdown 56 | } 57 | 58 | ImportSql() 59 | { 60 | StartMySQL 61 | 62 | for FILE in ${STARTUP_SQL}; do 63 | echo "=> Importing SQL file ${FILE}" 64 | mysql -uroot < "${FILE}" 65 | done 66 | 67 | mysqladmin -uroot shutdown 68 | } 69 | 70 | if [ ${REPLICATION_MASTER} == "**False**" ]; then 71 | unset REPLICATION_MASTER 72 | fi 73 | 74 | if [ ${REPLICATION_SLAVE} == "**False**" ]; then 75 | unset REPLICATION_SLAVE 76 | fi 77 | 78 | if [[ ! -d $VOLUME_HOME/mysql ]]; then 79 | echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME" 80 | echo "=> Installing MySQL ..." 81 | if [ ! -f /usr/share/mysql/my-default.cnf ] ; then 82 | cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf 83 | fi 84 | mysql_install_db > /dev/null 2>&1 85 | echo "=> Done!" 86 | echo "=> Creating admin user ..." 87 | CreateMySQLUser 88 | 89 | if [ -n "${STARTUP_SQL}" ]; then 90 | echo "=> Initializing DB with ${STARTUP_SQL}" 91 | ImportSql 92 | fi 93 | else 94 | echo "=> Using an existing volume of MySQL" 95 | fi 96 | 97 | 98 | # Set MySQL REPLICATION - MASTER 99 | if [ -n "${REPLICATION_MASTER}" ]; then 100 | echo "=> Configuring MySQL replication as master ..." 101 | if [ ! -f /replication_configured ]; then 102 | RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})" 103 | echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}" 104 | sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE} 105 | sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE} 106 | echo "=> Starting MySQL ..." 107 | StartMySQL 108 | echo "=> Creating a log user ${REPLICATION_USER}:${REPLICATION_PASS}" 109 | mysql -uroot -e "CREATE USER '${REPLICATION_USER}'@'%' IDENTIFIED BY '${REPLICATION_PASS}'" 110 | mysql -uroot -e "GRANT REPLICATION SLAVE ON *.* TO '${REPLICATION_USER}'@'%'" 111 | echo "=> Done!" 112 | mysqladmin -uroot shutdown 113 | touch /replication_configured 114 | else 115 | echo "=> MySQL replication master already configured, skip" 116 | fi 117 | fi 118 | 119 | # Set MySQL REPLICATION - SLAVE 120 | if [ -n "${REPLICATION_SLAVE}" ]; then 121 | echo "=> Configuring MySQL replication as slave ..." 122 | if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then 123 | if [ ! -f /replication_configured ]; then 124 | RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})" 125 | echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}" 126 | sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE} 127 | sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE} 128 | echo "=> Starting MySQL ..." 129 | StartMySQL 130 | echo "=> Setting master connection info on slave" 131 | mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT}, MASTER_CONNECT_RETRY=30" 132 | echo "=> Done!" 133 | mysqladmin -uroot shutdown 134 | touch /replication_configured 135 | else 136 | echo "=> MySQL replicaiton slave already configured, skip" 137 | fi 138 | else 139 | echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'" 140 | exit 1 141 | fi 142 | fi 143 | 144 | exec mysqld_safe 145 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.6/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | MAINTAINER Fernando Mayo , Feng Honglin 3 | 4 | # Install packages 5 | ENV DEBIAN_FRONTEND noninteractive 6 | RUN apt-get update && \ 7 | apt-get -yq install mysql-server-5.6 pwgen && \ 8 | rm -rf /var/lib/apt/lists/* 9 | 10 | # Remove pre-installed database 11 | RUN rm -rf /var/lib/mysql/* 12 | 13 | # Add MySQL configuration 14 | ADD my.cnf /etc/mysql/conf.d/my.cnf 15 | ADD mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf 16 | 17 | # Add MySQL scripts 18 | ADD import_sql.sh /import_sql.sh 19 | ADD run.sh /run.sh 20 | RUN chmod 755 /*.sh 21 | 22 | # Exposed ENV 23 | ENV MYSQL_USER admin 24 | ENV MYSQL_PASS **Random** 25 | 26 | # Replication ENV 27 | ENV REPLICATION_MASTER **False** 28 | ENV REPLICATION_SLAVE **False** 29 | ENV REPLICATION_USER replica 30 | ENV REPLICATION_PASS replica 31 | 32 | # Add VOLUMEs to allow backup of config and databases 33 | VOLUME ["/etc/mysql", "/var/lib/mysql"] 34 | 35 | EXPOSE 3306 36 | CMD ["/run.sh"] 37 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.6/create_db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -eq 0 ]]; then 4 | echo "Usage: $0 " 5 | exit 1 6 | fi 7 | 8 | /usr/bin/mysqld_safe > /dev/null 2>&1 & 9 | 10 | echo "=> Creating database $1" 11 | RET=1 12 | while [[ RET -ne 0 ]]; do 13 | sleep 5 14 | mysql -uroot -e "CREATE DATABASE $1" 15 | RET=$? 16 | done 17 | 18 | mysqladmin -uroot shutdown 19 | 20 | echo "=> Done!" 21 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.6/import_sql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -ne 3 ]]; then 4 | echo "Usage: $0 " 5 | exit 1 6 | fi 7 | 8 | echo "=> Starting MySQL Server" 9 | /usr/bin/mysqld_safe > /dev/null 2>&1 & 10 | PID=$! 11 | 12 | RET=1 13 | while [[ RET -ne 0 ]]; do 14 | echo "=> Waiting for confirmation of MySQL service startup" 15 | sleep 5 16 | mysql -u"$1" -p"$2" -e "status" > /dev/null 2>&1 17 | RET=$? 18 | done 19 | 20 | echo " Started with PID ${PID}" 21 | 22 | echo "=> Importing SQL file" 23 | mysql -u"$1" -p"$2" < "$3" 24 | 25 | echo "=> Stopping MySQL Server" 26 | mysqladmin -u"$1" -p"$2" shutdown 27 | 28 | echo "=> Done!" 29 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.6/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | bind-address=0.0.0.0 3 | # http://www.percona.com/blog/2008/05/31/dns-achilles-heel-mysql-installation/ 4 | skip_name_resolve 5 | #server-id 6 | #log-bin 7 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.6/mysqld_charset.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | character_set_server=utf8 3 | character_set_filesystem=utf8 4 | collation-server=utf8_general_ci 5 | init-connect='SET NAMES utf8' 6 | init_connect='SET collation_connection = utf8_general_ci' 7 | skip-character-set-client-handshake -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/5.6/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VOLUME_HOME="/var/lib/mysql" 4 | CONF_FILE="/etc/mysql/conf.d/my.cnf" 5 | LOG="/var/log/mysql/error.log" 6 | 7 | # Set permission of config file 8 | chmod 644 ${CONF_FILE} 9 | chmod 644 /etc/mysql/conf.d/mysqld_charset.cnf 10 | 11 | StartMySQL () 12 | { 13 | /usr/bin/mysqld_safe > /dev/null 2>&1 & 14 | 15 | # Time out in 1 minute 16 | LOOP_LIMIT=13 17 | for (( i=0 ; ; i++ )); do 18 | if [ ${i} -eq ${LOOP_LIMIT} ]; then 19 | echo "Time out. Error log is shown as below:" 20 | tail -n 100 ${LOG} 21 | exit 1 22 | fi 23 | echo "=> Waiting for confirmation of MySQL service startup, trying ${i}/${LOOP_LIMIT} ..." 24 | sleep 5 25 | mysql -uroot -e "status" > /dev/null 2>&1 && break 26 | done 27 | } 28 | 29 | CreateMySQLUser() 30 | { 31 | StartMySQL 32 | if [ "$MYSQL_PASS" = "**Random**" ]; then 33 | unset MYSQL_PASS 34 | fi 35 | 36 | PASS=${MYSQL_PASS:-$(pwgen -s 12 1)} 37 | _word=$( [ ${MYSQL_PASS} ] && echo "preset" || echo "random" ) 38 | echo "=> Creating MySQL user ${MYSQL_USER} with ${_word} password" 39 | 40 | mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '$PASS'" 41 | mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION" 42 | 43 | 44 | echo "=> Done!" 45 | 46 | echo "========================================================================" 47 | echo "You can now connect to this MySQL Server using:" 48 | echo "" 49 | echo " mysql -u$MYSQL_USER -p$PASS -h -P" 50 | echo "" 51 | echo "Please remember to change the above password as soon as possible!" 52 | echo "MySQL user 'root' has no password but only allows local connections" 53 | echo "========================================================================" 54 | 55 | mysqladmin -uroot shutdown 56 | } 57 | 58 | ImportSql() 59 | { 60 | StartMySQL 61 | 62 | for FILE in ${STARTUP_SQL}; do 63 | echo "=> Importing SQL file ${FILE}" 64 | mysql -uroot < "${FILE}" 65 | done 66 | 67 | mysqladmin -uroot shutdown 68 | } 69 | 70 | if [ ${REPLICATION_MASTER} == "**False**" ]; then 71 | unset REPLICATION_MASTER 72 | fi 73 | 74 | if [ ${REPLICATION_SLAVE} == "**False**" ]; then 75 | unset REPLICATION_SLAVE 76 | fi 77 | 78 | if [[ ! -d $VOLUME_HOME/mysql ]]; then 79 | echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME" 80 | echo "=> Installing MySQL ..." 81 | if [ ! -f /usr/share/mysql/my-default.cnf ] ; then 82 | cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf 83 | fi 84 | mysql_install_db > /dev/null 2>&1 85 | echo "=> Done!" 86 | echo "=> Creating admin user ..." 87 | CreateMySQLUser 88 | 89 | if [ -n "${STARTUP_SQL}" ]; then 90 | echo "=> Initializing DB with ${STARTUP_SQL}" 91 | ImportSql 92 | fi 93 | else 94 | echo "=> Using an existing volume of MySQL" 95 | fi 96 | 97 | # Set MySQL REPLICATION - MASTER 98 | if [ -n "${REPLICATION_MASTER}" ]; then 99 | echo "=> Configuring MySQL replication as master ..." 100 | if [ ! -f /replication_configured ]; then 101 | RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})" 102 | echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}" 103 | sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE} 104 | sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE} 105 | echo "=> Starting MySQL ..." 106 | StartMySQL 107 | echo "=> Creating a log user ${REPLICATION_USER}:${REPLICATION_PASS}" 108 | mysql -uroot -e "CREATE USER '${REPLICATION_USER}'@'%' IDENTIFIED BY '${REPLICATION_PASS}'" 109 | mysql -uroot -e "GRANT REPLICATION SLAVE ON *.* TO '${REPLICATION_USER}'@'%'" 110 | echo "=> Done!" 111 | mysqladmin -uroot shutdown 112 | touch /replication_configured 113 | else 114 | echo "=> MySQL replication master already configured, skip" 115 | fi 116 | fi 117 | 118 | # Set MySQL REPLICATION - SLAVE 119 | if [ -n "${REPLICATION_SLAVE}" ]; then 120 | echo "=> Configuring MySQL replication as slave ..." 121 | if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then 122 | if [ ! -f /replication_configured ]; then 123 | RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})" 124 | echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}" 125 | sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE} 126 | sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE} 127 | echo "=> Starting MySQL ..." 128 | StartMySQL 129 | echo "=> Setting master connection info on slave" 130 | mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT}, MASTER_CONNECT_RETRY=30" 131 | echo "=> Done!" 132 | mysqladmin -uroot shutdown 133 | touch /replication_configured 134 | else 135 | echo "=> MySQL replicaiton slave already configured, skip" 136 | fi 137 | else 138 | echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'" 139 | exit 1 140 | fi 141 | fi 142 | 143 | exec mysqld_safe 144 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/README.md: -------------------------------------------------------------------------------- 1 | tutum-docker-mysql 2 | ================== 3 | 4 | Base docker image to run a MySQL database server 5 | 6 | 7 | MySQL version 8 | ------------- 9 | 10 | Different versions are built from different folders. If you want to use MariaDB, please check our `tutum/mariadb` image: https://github.com/tutumcloud/tutum-docker-mariadb 11 | 12 | 13 | Usage 14 | ----- 15 | 16 | To create the image `tutum/mysql`, execute the following command on the tutum-mysql folder: 17 | 18 | docker build -t tutum/mysql 5.5/ 19 | 20 | To run the image and bind to port 3306: 21 | 22 | docker run -d -p 3306:3306 tutum/mysql 23 | 24 | The first time that you run your container, a new user `admin` with all privileges 25 | will be created in MySQL with a random password. To get the password, check the logs 26 | of the container by running: 27 | 28 | docker logs 29 | 30 | You will see an output like the following: 31 | 32 | ======================================================================== 33 | You can now connect to this MySQL Server using: 34 | 35 | mysql -uadmin -p47nnf4FweaKu -h -P 36 | 37 | Please remember to change the above password as soon as possible! 38 | MySQL user 'root' has no password but only allows local connections 39 | ======================================================================== 40 | 41 | In this case, `47nnf4FweaKu` is the password allocated to the `admin` user. 42 | 43 | Remember that the `root` user has no password but it's only accessible from within the container. 44 | 45 | You can now test your deployment: 46 | 47 | mysql -uadmin -p 48 | 49 | Done! 50 | 51 | 52 | Setting a specific password for the admin account 53 | ------------------------------------------------- 54 | 55 | If you want to use a preset password instead of a random generated one, you can 56 | set the environment variable `MYSQL_PASS` to your specific password when running the container: 57 | 58 | docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql 59 | 60 | You can now test your deployment: 61 | 62 | mysql -uadmin -p"mypass" 63 | 64 | The admin username can also be set via the `MYSQL_USER` environment variable. 65 | 66 | 67 | Mounting the database file volume 68 | --------------------------------- 69 | 70 | In order to persist the database data, you can mount a local folder from the host 71 | on the container to store the database files. To do so: 72 | 73 | docker run -d -v /path/in/host:/var/lib/mysql tutum/mysql /bin/bash -c "/usr/bin/mysql_install_db" 74 | 75 | This will mount the local folder `/path/in/host` inside the docker in `/var/lib/mysql` (where MySQL will store the database files by default). `mysql_install_db` creates the initial database structure. 76 | 77 | Remember that this will mean that your host must have `/path/in/host` available when you run your docker image! 78 | 79 | After this you can start your mysql image but this time using `/path/in/host` as the database folder: 80 | 81 | docker run -d -p 3306:3306 -v /path/in/host:/var/lib/mysql tutum/mysql 82 | 83 | 84 | Mounting the database file volume from other containers 85 | ------------------------------------------------------ 86 | 87 | Another way to persist the database data is to store database files in another container. 88 | To do so, first create a container that holds database files: 89 | 90 | docker run -d -v /var/lib/mysql --name db_vol -p 22:22 tutum/ubuntu-trusty 91 | 92 | This will create a new ssh-enabled container and use its folder `/var/lib/mysql` to store MySQL database files. 93 | You can specify any name of the container by using `--name` option, which will be used in next step. 94 | 95 | After this you can start your MySQL image using volumes in the container created above (put the name of container in `--volumes-from`) 96 | 97 | docker run -d --volumes-from db_vol -p 3306:3306 tutum/mysql 98 | 99 | 100 | Migrating an existing MySQL Server 101 | ---------------------------------- 102 | 103 | In order to migrate your current MySQL server, perform the following commands from your current server: 104 | 105 | To dump your databases structure: 106 | 107 | mysqldump -u -p --opt -d -B > /tmp/dbserver_schema.sql 108 | 109 | To dump your database data: 110 | 111 | mysqldump -u -p --quick --single-transaction -t -n -B > /tmp/dbserver_data.sql 112 | 113 | To import a SQL backup which is stored for example in the folder `/tmp` in the host, run the following: 114 | 115 | sudo docker run -d -v /tmp:/tmp tutum/mysql /bin/bash -c "/import_sql.sh /tmp/" 116 | 117 | Also you can start the new database initializing it with the SQL file: 118 | 119 | sudo docker run -d -v /path/in/host:/var/lib/mysql -e STARTUP_SQL="/tmp/" tutum/mysql 120 | 121 | Where `` and `` are the database username and password set earlier and `` is the name of the SQL file to be imported. 122 | 123 | 124 | Replication - Master/Slave 125 | ------------------------- 126 | To use MySQL replication, please set environment variable `REPLICATION_MASTER`/`REPLICATION_SLAVE` to `true`. Also, on master side, you may want to specify `REPLICATION_USER` and `REPLICATION_PASS` for the account to perform replication, the default value is `replica:replica` 127 | 128 | Examples: 129 | - Master MySQL 130 | - 131 | docker run -d -e REPLICATION_MASTER=true -e REPLICATION_PASS=mypass -p 3306:3306 --name mysql tutum/mysql 132 | 133 | - Example on Slave MySQL: 134 | - 135 | docker run -d -e REPLICATION_SLAVE=true -p 3307:3306 --link mysql:mysql tutum/mysql 136 | 137 | Now, you can access port `3306` and `3307` for the master/slave mysql 138 | Environment variables 139 | --------------------- 140 | 141 | `MYSQL_USER`: Set a specific username for the admin account (default 'admin') 142 | 143 | `MYSQL_PASS`: Set a specific password for the admin account. 144 | 145 | `STARTUP_SQL`: Defines one or more sql scripts separated by spaces to initialize the database. Note that the scripts must be inside the conainer so you may need to mount them 146 | 147 | Compatibility Issues 148 | -------------------- 149 | 150 | - Volume created by MySQL 5.6 cannot be used in MySQL 5.5 Images or MariaDB images 151 | -------------------------------------------------------------------------------- /db/tutum/tutum-docker-mysql/circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | services: 3 | - docker 4 | dependencies: 5 | override: 6 | - docker build -t mysql-5.5 5.5/ 7 | - docker build -t mysql-5.6 5.6/ 8 | test: 9 | override: 10 | # test mysql 5.5 11 | - docker run -d -p 13306:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.5; sleep 20 12 | - mysqladmin -uuser -ptest -h127.0.0.1 -P13306 ping | grep -c "mysqld is alive" 13 | # test mysql 5.6 14 | - docker run -d -p 13307:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.6; sleep 20 15 | - mysqladmin -uuser -ptest -h127.0.0.1 -P13307 ping | grep -c "mysqld is alive" 16 | # test replication 5.5 17 | - docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p 13308:3306 --name mysql55master mysql-5.5; sleep 20 18 | - docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true -p 13309:3306 --link mysql55master:mysql mysql-5.5; sleep 20 19 | - docker logs mysql55master | grep "repl:repl" 20 | - mysql -uuser -ptest -h127.0.0.1 -P13308 -e "show master status\G;" | grep "mysql-bin.*" 21 | - mysql -uuser -ptest -h127.0.0.1 -P13309 -e "show slave status\G;" | grep "Slave_IO_Running.*Yes" 22 | # test replication 5.6 23 | - docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p 13310:3306 --name mysql56master mysql-5.6; sleep 20 24 | - docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true -p 13311:3306 --link mysql56master:mysql mysql-5.6; sleep 20 25 | - docker logs mysql56master | grep "repl:repl" 26 | - mysql -uuser -ptest -h127.0.0.1 -P13310 -e "show master status\G;" | grep "mysql-bin.*" 27 | - mysql -uuser -ptest -h127.0.0.1 -P13311 -e "show slave status\G;" | grep "Slave_IO_Running.*Yes" 28 | -------------------------------------------------------------------------------- /figures/brc-u-logos/KHP_M_oneline_descriptor_strapline_hr_CMYK-e1409244956134.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KHP-Informatics/redcap-docker/d1c0f1d69718dedf6c0e4e07333000715abf8fb7/figures/brc-u-logos/KHP_M_oneline_descriptor_strapline_hr_CMYK-e1409244956134.jpg -------------------------------------------------------------------------------- /web-base/Dockerfile: -------------------------------------------------------------------------------- 1 | #FROM ubuntu:trusty 2 | 3 | # USE: docker build --tag="afolarin/cron-apache-php" . 4 | 5 | 6 | #need local cron for redcap so rebasing on phusions fat container image 7 | FROM phusion/baseimage:0.9.15 8 | MAINTAINER Amos Folarin 9 | 10 | # Set correct environment variables. 11 | ENV HOME /root 12 | 13 | # Regenerate SSH host keys. baseimage-docker does not contain any, so you 14 | # have to do that yourself. You may also comment out this instruction; the 15 | # init system will auto-generate one during boot. 16 | #??# RUN /etc/my_init.d/00_regen_ssh_host_keys.sh 17 | 18 | # Use baseimage-docker's init system. 19 | CMD ["/sbin/my_init"] 20 | 21 | 22 | ####------------- start tutum/apache-php and redcap layers -----------------------# 23 | 24 | # Install base packages 25 | ENV DEBIAN_FRONTEND noninteractive 26 | RUN apt-get update && \ 27 | apt-get -yq install \ 28 | apache2 \ 29 | curl \ 30 | libapache2-mod-php5 \ 31 | mysql-server-5.5 \ 32 | php5-mysql \ 33 | php5-gd \ 34 | php5-curl \ 35 | php-pear \ 36 | php-apc 37 | 38 | # PHP config 39 | RUN sed -i "s/variables_order.*/variables_order = \"EGPCS\"/g" /etc/php5/apache2/php.ini 40 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 41 | 42 | # Configure /app folder with sample tutum app 43 | RUN mkdir -p /app && rm -fr /var/www/html && ln -s /app /var/www/html 44 | #ADD sample/ /app 45 | 46 | 47 | # redcap web-application 48 | #COPY ./download/redcap /app/redcap 49 | 50 | 51 | ####------------- phusion startup and extra daemons -----------------------# 52 | # Startup scripts in /etc/my_init.d are run at container start 53 | #RUN mkdir -p /etc/my_init.d 54 | #ADD a_logfile.sh /etc/my_init.d/a_logfile.sh 55 | #ADD cron-conf.sh /etc/my_init.d/cron-conf.sh 56 | #ADD parse_redcap_config.sh /etc/my_init.d/parse_redcap_config.sh 57 | #RUN chmod +x /etc/my_init.d/*.sh 58 | ##RUN chmod 755 /etc/my_init.d/*.sh 59 | 60 | # Daemonised processes 61 | # Runtime sensitive information provided as [--env, --env-file] environment variables, 62 | # which are processed by parse_redcap_config.sh into the database.php file 63 | # control is then passed to the run.sh script 64 | COPY run /etc/service/apache/ 65 | #RUN chmod 755 /etc/service/apache/run 66 | 67 | 68 | EXPOSE 80 69 | WORKDIR /app 70 | 71 | 72 | # Clean up APT when done. 73 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 74 | 75 | 76 | -------------------------------------------------------------------------------- /web-base/a_logfile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### In a_logtime.sh (make sure this file is chmod +x): 4 | date > /tmp/boottime.txt 5 | 6 | -------------------------------------------------------------------------------- /web-base/cron-conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #run cron with the crontab that is bind-mounted cron-conf/crontab 4 | echo "Setting up crontab with /app/cron-conf/crontab" 5 | crontab /app/cron-conf/crontab 6 | -------------------------------------------------------------------------------- /web-base/parse_redcap_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #------------------------------------------------------------------------------ 4 | # DESC: 5 | # Setup config (mostly hooking up the database container and processing 6 | # some additional server reqirements of redcap) then execute the CMD transparently: 7 | 8 | # AUTHOR: Amos Folarin 9 | 10 | # USAGE: 11 | # Initialize and parameterize the 12 | # [ENTRYPOINT] = parse_redcap_config.sh [CMD = /run.sh] 13 | # parse_redcap_config.sh "/run.sh" 14 | # 15 | # This script is not required just to restart the container. 16 | # To restart the container, with default CMD and ENTRYPOINT if you need to 17 | # restart the apache webserver, using pre-existing params. 18 | #------------------------------------------------------------------------------ 19 | 20 | #ENTRYPOINT param parsing for RedCap Container 21 | 22 | #CMD to be run after config has been done 23 | CMD=${1} 24 | 25 | #RUNTIME ENV VARS 26 | REDCAP_DB_PORT_3306_TCP_ADDR_="" #The hostname of the linked database container 27 | REDCAP_DB_NAME_="redcap_mysql" #redcap database name created in mysql container 28 | REDCAP_DB_USER_="redcap_admin" #redcap database user, not the default mysql container "admin" user which is overprivileged for redcap 29 | REDCAP_DB_USER_PWD_="" #redcap database password 30 | REDCAP_DB_SALT_="" #the >12 digit salt for the database 31 | 32 | ## check if each env var exists or exit 33 | if [[ -n ${REDCAP_DB_PORT_3306_TCP_ADDR} ]] 34 | then 35 | REDCAP_DB_PORT_3306_TCP_ADDR_=${REDCAP_DB_PORT_3306_TCP_ADDR} 36 | else 37 | echo "error undefined REDCAP_DB_PORT_3306_TCP_ADDR\n" >&2 38 | exit 1 39 | fi 40 | 41 | if [[ -n ${REDCAP_DB_NAME} ]] 42 | then 43 | REDCAP_DB_NAME_=${REDCAP_DB_NAME} 44 | else 45 | echo "error undefined REDCAP_DB_NAME\n" >&2 46 | exit 1 47 | fi 48 | 49 | if [[ -n ${REDCAP_DB_USER} ]] 50 | then 51 | REDCAP_DB_USER_=${REDCAP_DB_USER} 52 | else 53 | echo "error undefined REDCAP_DB_USER\n" >&2 54 | exit 1 55 | fi 56 | 57 | if [[ -n ${REDCAP_DB_USER_PWD} ]] 58 | then 59 | REDCAP_DB_USER_PWD_=${REDCAP_DB_USER_PWD} 60 | else 61 | echo "error undefined REDCAP_DB_USER_PWD\n" >&2 62 | exit 1 63 | fi 64 | 65 | if [[ -n ${REDCAP_DB_SALT} ]] 66 | then 67 | REDCAP_DB_SALT_=${REDCAP_DB_SALT} 68 | else 69 | echo "error undefined REDCAP_DB_SALT\n" >&2 70 | exit 1 71 | fi 72 | 73 | ## CONNECT TO THE MYSQL SERVER CONTAINER as the default tutum MYSQL_USER "admin", which is used to 74 | ## create myql redcap database, user and password as provided at runtime 75 | #mysql -h${REDCAP_DB_PORT_3306_TCP_ADDR_} -u${MYSQL_USER} -p${MYSQL_PASS} << EOF 76 | #CREATE DATABASE ${REDCAP_DB_NAME_}; 77 | #CREATE USER "${REDCAP_DB_USER_}"@"${REDCAP_DB_PORT_3306_TCP_ADDR_}" IDENTIFIED BY "${REDCAP_DB_USER_PWD_}"; 78 | #GRANT DROP,DELETE,INSERT,SELECT,UPDATE ON ${REDCAP_DB_NAME_}.* TO "${REDCAP_DB_USER_}"@"${REDCAP_DB_PORT_3306_TCP_ADDR_}"; 79 | #EOF 80 | 81 | #User account for connecting from remote host, a root account exists for connecting from localhost 82 | ## CONNECT TO THE MYSQL SERVER CONTAINER as the default tutum MYSQL_USER "admin", which is used to 83 | ## create myql redcap database, user and password as provided at runtime 84 | mysql -h${REDCAP_DB_PORT_3306_TCP_ADDR_} -u${MYSQL_USER} -p${MYSQL_PASS} << EOF 85 | CREATE DATABASE ${REDCAP_DB_NAME_}; 86 | CREATE USER "${REDCAP_DB_USER_}"@"%" IDENTIFIED BY "${REDCAP_DB_USER_PWD_}"; 87 | GRANT DROP,DELETE,INSERT,SELECT,UPDATE ON ${REDCAP_DB_NAME_}.* TO "${REDCAP_DB_USER_}"@"%"; 88 | FLUSH PRIVILEGES; 89 | EOF 90 | 91 | ## Substitute env vars parsed at runtime into web-container:/app/redcap/database.php config file 92 | sed -in -e "s/your_mysql_host_name/${REDCAP_DB_PORT_3306_TCP_ADDR_}/" \ 93 | -e "s/your_mysql_db_name/${REDCAP_DB_NAME_}/" \ 94 | -e "s/your_mysql_db_username/${REDCAP_DB_USER_}/" \ 95 | -e "s/your_mysql_db_password/${REDCAP_DB_USER_PWD_}/" \ 96 | -e "s/\$salt = ''/\$salt = ${REDCAP_DB_SALT_}/" \ 97 | /app/redcap/database.php 98 | 99 | #Unset the password env var 100 | export REDCAP_DB_USER_PWD="" 101 | 102 | 103 | # OTHER REDCAP CONFIG REQUIREMENTS 104 | # postinstall checklist: http://localhost/redcap/redcap_v6.0.12/ControlCenter/check.php?upgradeinstall=1 105 | 106 | ## increase upload_max_filesize in php.ini 107 | sed -in -e "s/upload_max_filesize = 2M/upload_max_filesize = 32M/" /etc/php5/apache2/php.ini 108 | sed -in -e "s/post_max_size = 8M/post_max_size = 32M/" /etc/php5/apache2/php.ini 109 | 110 | ## uncomment max_input_vars in php.ini 111 | sed -in -e "s/\; max_input_vars = 1000/max_input_vars = 10000/" /etc/php5/apache2/php.ini 112 | 113 | ## ERROR: Cron job not running! May require supervisor, try cron in separate container first. 114 | 115 | ## setup cron, may require some supervisor? - CRITICAL 116 | 117 | ## setup SMTP server for emails - CRITICAL 118 | 119 | ## https + SSL certs strongly - CRITICAL 120 | 121 | ## Mcrypt extenstion not installed - RECOMMENDED 122 | 123 | ## Missing UTF-8 fonts for PDF export - RECOMMENDED 124 | 125 | ## Change default location for edocs folder - RECOMMENDED 126 | 127 | 128 | ## RESTART apache so uses new config 129 | #/etc/init.d/apache2 restart 130 | 131 | 132 | # NOTE! moving control of run.sh CMD to phusion/baseimage runit (/etc/services/apache/run) 133 | # and above parsed configuration to the phusion/baseimage startup scripts (/etc/my_init.d) 134 | #LASTLY: execute the docker run CMD now, standup apache. 135 | #$CMD 136 | 137 | 138 | 139 | #env 140 | #/bin/bash 141 | -------------------------------------------------------------------------------- /web-base/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown www-data:www-data /app -R 3 | source /etc/apache2/envvars 4 | exec apache2 -D FOREGROUND -D NO_DETACH 5 | -------------------------------------------------------------------------------- /web/Dockerfile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # Dockerized Redcap for deploying in a variety of environments 3 | # Based on the phusion + tutum-php container afolarin/cron-apache-php 4 | #------------------------------------------------------------------------------ 5 | 6 | #The Containers in the System: 7 | # 1) [afolarin/redcap:mysql] 8 | # 2) [afolarin/redcap:webapp] 9 | 10 | # BUILD: 11 | # $ cd web/ 12 | # $ docker build --tag="afolarin/redcap:webapp" . 13 | 14 | # USAGE: 15 | # docker run -d --name="redcap-web" -v $(pwd)/cron-conf/:/cron-conf/ --link="redcap-db:REDCAP_DB" --env-file="env.list" --publish="80:80" afolarin/redcap:webapp 16 | 17 | # Installation Checks: http:///redcap/redcap_v6.0.12/ControlCenter/check.php?upgradeinstall=1 18 | 19 | #------------------------------------------------------------------------------ 20 | # Redcap Container 21 | # build from inside the ./build dir see README.md 22 | #------------------------------------------------------------------------------ 23 | 24 | FROM afolarin/cron-apache-php 25 | 26 | MAINTAINER Amos Folarin 27 | 28 | # install mysql client 29 | RUN apt-get update && \ 30 | apt-get -yq install \ 31 | mysql-server-5.5 \ 32 | php5-mcrypt \ 33 | postfix 34 | # sendmail 35 | 36 | #setup mycrypt and restart apache 37 | RUN php5enmod mcrypt && \ 38 | service apache2 restart 39 | 40 | ### mail setup: postfix (SMTP) and when you use sendmail (non-SMTP). 41 | ### You may/should prefer to send your mail with a more appropriate mechanism.... 42 | 43 | #[optional] config sendmail (will req. user completion run sendmailconfig) 44 | # see: https://holarails.wordpress.com/2013/11/17/configure-sendmail-in-ubuntu-12-04-and-make-it-fast/ 45 | # setup to use TLS 46 | # RUN cat >> /etc/mail/sendmail.mc <<< "include(`/etc/mail/tls/starttls.m4')dnl" && \ 47 | # cat >> /etc/mail/submit.mc <<< "include(`/etc/mail/tls/starttls.m4')dnl" 48 | 49 | #[optional] config postfix 50 | # service postfix start #and select config. see http://www.slideshare.net/dotCloud/postfix-tuto4 51 | # I can seemingly only get postfix to work with ipv4 ... https://www.solver.io/wp/2012/10/15/postfix-gmail-network-is-unreachable/ 52 | RUN service postfix start && \ 53 | sed -i 's/inet_protocols = all/inet_protocols = ipv4/' /etc/postfix/main.cf && \ 54 | /etc/init.d/postfix reload 55 | 56 | 57 | 58 | 59 | # copy redcap application into the container /app which is linked as /var/www/html 60 | # and create default index.php at web root 61 | COPY ./download/redcap /app/redcap 62 | COPY ./index.php /app/index.php 63 | 64 | 65 | ############################################################################### 66 | # my_runit: Startup scripts in /etc/my_init.d are run at container start 67 | ############################################################################### 68 | RUN mkdir -p /etc/my_init.d 69 | ADD a_logfile.sh /etc/my_init.d/a_logfile.sh 70 | ADD cron-conf.sh /etc/my_init.d/cron-conf.sh 71 | ADD parse_redcap_config.sh /etc/my_init.d/parse_redcap_config.sh 72 | RUN chmod 755 /etc/my_init.d/*.sh 73 | 74 | 75 | ############################################################################### 76 | # my_runit: Daemonised processes /etc/service//run 77 | ############################################################################### 78 | # 79 | 80 | 81 | 82 | # Clean up APT when done. 83 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 84 | 85 | 86 | -------------------------------------------------------------------------------- /web/a_logfile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### In a_logtime.sh (make sure this file is chmod +x): 4 | date > /tmp/boottime.txt 5 | 6 | -------------------------------------------------------------------------------- /web/cron-conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #run cron with the crontab that is bind-mounted cron-conf/crontab 4 | echo "Setting up crontab with /app/cron-conf/crontab" 5 | crontab /cron-conf/crontab 6 | -------------------------------------------------------------------------------- /web/cron-conf/crontab: -------------------------------------------------------------------------------- 1 | # REDCap Cron Job (runs every minute) 2 | * * * * * /usr/bin/php /app/redcap/cron.php > /dev/null 3 | -------------------------------------------------------------------------------- /web/database.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | REDCAP on DOCKER 4 | 5 | 17 | 18 | 19 | 20 | 21 |

22 |

23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /web/parse_redcap_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #------------------------------------------------------------------------------ 4 | # DESC: 5 | # Setup config (mostly hooking up the database container and processing 6 | # some additional server reqirements of redcap) then execute the CMD transparently: 7 | 8 | # AUTHOR: Amos Folarin 9 | 10 | # USAGE: 11 | # Initialize and parameterize the 12 | # [ENTRYPOINT] = parse_redcap_config.sh [CMD = /run.sh] 13 | # parse_redcap_config.sh "/run.sh" 14 | # 15 | # This script is not required just to restart the container. 16 | # To restart the container, with default CMD and ENTRYPOINT if you need to 17 | # restart the apache webserver, using pre-existing params. 18 | #------------------------------------------------------------------------------ 19 | 20 | #ENTRYPOINT param parsing for RedCap Container 21 | 22 | #CMD to be run after config has been done 23 | CMD=${1} 24 | 25 | #RUNTIME ENV VARS 26 | REDCAP_DB_PORT_3306_TCP_ADDR_="" #The hostname of the linked database container 27 | REDCAP_DB_NAME_="redcap_mysql" #redcap database name created in mysql container 28 | REDCAP_DB_USER_="redcap_admin" #redcap database user, not the default mysql container "admin" user which is overprivileged for redcap 29 | REDCAP_DB_USER_PWD_="" #redcap database password 30 | REDCAP_DB_SALT_="" #the >12 digit salt for the database 31 | 32 | ## check if each env var exists or exit 33 | if [[ -n ${REDCAP_DB_PORT_3306_TCP_ADDR} ]] 34 | then 35 | REDCAP_DB_PORT_3306_TCP_ADDR_=${REDCAP_DB_PORT_3306_TCP_ADDR} 36 | else 37 | echo "error undefined REDCAP_DB_PORT_3306_TCP_ADDR\n" >&2 38 | exit 1 39 | fi 40 | 41 | if [[ -n ${REDCAP_DB_NAME} ]] 42 | then 43 | REDCAP_DB_NAME_=${REDCAP_DB_NAME} 44 | else 45 | echo "error undefined REDCAP_DB_NAME\n" >&2 46 | exit 1 47 | fi 48 | 49 | if [[ -n ${REDCAP_DB_USER} ]] 50 | then 51 | REDCAP_DB_USER_=${REDCAP_DB_USER} 52 | else 53 | echo "error undefined REDCAP_DB_USER\n" >&2 54 | exit 1 55 | fi 56 | 57 | if [[ -n ${REDCAP_DB_USER_PWD} ]] 58 | then 59 | REDCAP_DB_USER_PWD_=${REDCAP_DB_USER_PWD} 60 | else 61 | echo "error undefined REDCAP_DB_USER_PWD\n" >&2 62 | exit 1 63 | fi 64 | 65 | if [[ -n ${REDCAP_DB_SALT} ]] 66 | then 67 | REDCAP_DB_SALT_=${REDCAP_DB_SALT} 68 | else 69 | echo "error undefined REDCAP_DB_SALT\n" >&2 70 | exit 1 71 | fi 72 | 73 | ## CONNECT TO THE MYSQL SERVER CONTAINER as the default tutum MYSQL_USER "admin", which is used to 74 | ## create myql redcap database, user and password as provided at runtime 75 | #mysql -h${REDCAP_DB_PORT_3306_TCP_ADDR_} -u${MYSQL_USER} -p${MYSQL_PASS} << EOF 76 | #CREATE DATABASE ${REDCAP_DB_NAME_}; 77 | #CREATE USER "${REDCAP_DB_USER_}"@"${REDCAP_DB_PORT_3306_TCP_ADDR_}" IDENTIFIED BY "${REDCAP_DB_USER_PWD_}"; 78 | #GRANT DROP,DELETE,INSERT,SELECT,UPDATE ON ${REDCAP_DB_NAME_}.* TO "${REDCAP_DB_USER_}"@"${REDCAP_DB_PORT_3306_TCP_ADDR_}"; 79 | #EOF 80 | 81 | #User account for connecting from remote host, a root account exists for connecting from localhost 82 | ## CONNECT TO THE MYSQL SERVER CONTAINER as the default tutum MYSQL_USER "admin", which is used to 83 | ## create myql redcap database, user and password as provided at runtime 84 | mysql -h${REDCAP_DB_PORT_3306_TCP_ADDR_} -u${MYSQL_USER} -p${MYSQL_PASS} << EOF 85 | CREATE DATABASE ${REDCAP_DB_NAME_}; 86 | CREATE USER "${REDCAP_DB_USER_}"@"%" IDENTIFIED BY "${REDCAP_DB_USER_PWD_}"; 87 | GRANT DROP,DELETE,INSERT,SELECT,UPDATE ON ${REDCAP_DB_NAME_}.* TO "${REDCAP_DB_USER_}"@"%"; 88 | FLUSH PRIVILEGES; 89 | EOF 90 | 91 | ## Substitute env vars parsed at runtime into web-container:/app/redcap/database.php config file 92 | sed -in -e "s/your_mysql_host_name/${REDCAP_DB_PORT_3306_TCP_ADDR_}/" \ 93 | -e "s/your_mysql_db_name/${REDCAP_DB_NAME_}/" \ 94 | -e "s/your_mysql_db_username/${REDCAP_DB_USER_}/" \ 95 | -e "s/your_mysql_db_password/${REDCAP_DB_USER_PWD_}/" \ 96 | -e "s/\$salt = ''/\$salt = ${REDCAP_DB_SALT_}/" \ 97 | /app/redcap/database.php 98 | 99 | #Unset the password env var 100 | export REDCAP_DB_USER_PWD="" 101 | 102 | 103 | # OTHER REDCAP CONFIG REQUIREMENTS 104 | # postinstall checklist: http://localhost/redcap/redcap_v6.0.12/ControlCenter/check.php?upgradeinstall=1 105 | 106 | ## increase upload_max_filesize in php.ini 107 | sed -in -e "s/upload_max_filesize = 2M/upload_max_filesize = 32M/" /etc/php5/apache2/php.ini 108 | sed -in -e "s/post_max_size = 8M/post_max_size = 32M/" /etc/php5/apache2/php.ini 109 | 110 | ## uncomment max_input_vars in php.ini 111 | sed -in -e "s/\; max_input_vars = 1000/max_input_vars = 10000/" /etc/php5/apache2/php.ini 112 | 113 | 114 | ## setup cron, may require some supervisor? - CRITICAL 115 | ## --> could only setup *cron* as a multiprocess container, have based on phusion/baseimage 116 | 117 | ## setup SMTP server for emails - CRITICAL 118 | # NOTE DONE AS DEFAULT -- REQUIRE FOR PRODUCTION 119 | 120 | ## https + SSL certs strongly - CRITICAL 121 | # NOT DONE AS DEFAULT -- REQ FOR PRODUCTION 122 | 123 | ## Mcrypt extenstion not installed - RECOMMENDED 124 | # DONE -- installed php5-mycrypt 125 | 126 | ## Missing UTF-8 fonts for PDF export - RECOMMENDED 127 | # DONE -- add redcap/webtools2/pdf 128 | 129 | ## Change default location for edocs folder (i.e. not in /apt web accessible)- RECOMMENDED 130 | cp -r /app/redcap/edocs / 131 | chown www-data:www-data /edocs -R 132 | 133 | ## RESTART apache so uses new config 134 | #/etc/init.d/apache2 restart 135 | 136 | 137 | # NOTE! moving control of run.sh CMD to phusion/baseimage runit (/etc/services/apache/run) 138 | # and above parsed configuration to the phusion/baseimage startup scripts (/etc/my_init.d) 139 | # --- commenting out below as this script only handles initialization --- 140 | #LASTLY: execute the docker run CMD now, standup apache. 141 | #$CMD 142 | 143 | 144 | 145 | #env 146 | #/bin/bash 147 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/Dockerfile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # Dockerized "fat" machine container for deploying apache 3 | # This container image is based on the phusion/baseimage 4 | # (https://github.com/phusion/baseimage-docker) a multiprocess 5 | # container with various components such as cron, ssh, syslog, logrotate 6 | # more akin to a full machine. 7 | # Tutum apache-php (https://github.com/tutumcloud/tutum-docker-php) is rebuilt 8 | # ontop of phusion/baseimage:0.9.15 9 | #------------------------------------------------------------------------------ 10 | 11 | # BUILD: 12 | # $ cd web/tutum/tutum-docker-php 13 | # $ docker build --tag="afolarin/cron-apache-php" . 14 | 15 | # USAGE: 16 | # docker run -d --publish="80:80" afolarin/cron-apache-php 17 | 18 | 19 | 20 | #need local cron for redcap so rebasing on phusions fat container image 21 | FROM phusion/baseimage:0.9.15 22 | MAINTAINER Amos Folarin 23 | 24 | # Set correct environment variables. 25 | ENV HOME /root 26 | 27 | # Regenerate SSH host keys. baseimage-docker does not contain any, so you 28 | # have to do that yourself. You may also comment out this instruction; the 29 | # init system will auto-generate one during boot. 30 | #??# RUN /etc/my_init.d/00_regen_ssh_host_keys.sh 31 | 32 | # Use baseimage-docker's init system. 33 | CMD ["/sbin/my_init"] 34 | 35 | 36 | ############################################################################### 37 | #----------------------- start tutum/apache-php layers -----------------------# 38 | ############################################################################### 39 | # Install base packages 40 | ENV DEBIAN_FRONTEND noninteractive 41 | RUN apt-get update && \ 42 | apt-get -yq install \ 43 | curl \ 44 | apache2 \ 45 | libapache2-mod-php5 \ 46 | php5-mysql \ 47 | php5-gd \ 48 | php5-curl \ 49 | php-pear \ 50 | php-apc && \ 51 | rm -rf /var/lib/apt/lists/* 52 | 53 | RUN sed -i "s/variables_order.*/variables_order = \"EGPCS\"/g" /etc/php5/apache2/php.ini 54 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 55 | 56 | ############################################################################### 57 | # my_runit: Startup scripts in /etc/my_init.d are run at container start 58 | ############################################################################### 59 | # 60 | 61 | 62 | ############################################################################### 63 | # my_runit: Daemonised processes /etc/service//run 64 | ############################################################################### 65 | # Runtime sensitive information provided as [--env, --env-file] environment variables, 66 | # which are processed by parse_redcap_config.sh into the database.php file 67 | # control is then passed to the run.sh script 68 | COPY run /etc/service/apache/ 69 | RUN chmod 755 /etc/service/apache/run 70 | 71 | 72 | 73 | # Configure /app folder with sample app 74 | RUN mkdir -p /app && rm -fr /var/www/html && ln -s /app /var/www/html 75 | 76 | #Sample application (prints out linked containers info, so commenting out) 77 | # but if for any reason you require this, uncomment it and rebuild 78 | ADD sample/ /app 79 | 80 | EXPOSE 80 81 | WORKDIR /app 82 | 83 | 84 | # Clean up APT when done. 85 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 86 | 87 | 88 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/Dockerfile-tutum_ori: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | MAINTAINER Fernando Mayo 3 | 4 | # Install base packages 5 | ENV DEBIAN_FRONTEND noninteractive 6 | RUN apt-get update && \ 7 | apt-get -yq install \ 8 | curl \ 9 | apache2 \ 10 | libapache2-mod-php5 \ 11 | php5-mysql \ 12 | php5-gd \ 13 | php5-curl \ 14 | php-pear \ 15 | php-apc && \ 16 | rm -rf /var/lib/apt/lists/* 17 | RUN sed -i "s/variables_order.*/variables_order = \"EGPCS\"/g" /etc/php5/apache2/php.ini 18 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 19 | 20 | # Add image configuration and scripts 21 | ADD run.sh /run.sh 22 | RUN chmod 755 /*.sh 23 | 24 | # Configure /app folder with sample app 25 | RUN mkdir -p /app && rm -fr /var/www/html && ln -s /app /var/www/html 26 | ADD sample/ /app 27 | 28 | EXPOSE 80 29 | WORKDIR /app 30 | CMD ["/run.sh"] 31 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "[]" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright [yyyy] [name of copyright owner] 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/Makefile: -------------------------------------------------------------------------------- 1 | all: php 2 | 3 | php: 4 | docker build -t tutum/docker-php . 5 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/README-mods.md: -------------------------------------------------------------------------------- 1 | # afolarin/cron-apache-php 2 | ## is a REBUILD of webapp base to combine phusion/baseimage + tutum/apache-php 3 | 4 | ## Author: Amos Folarin 5 | 6 | 7 | apache now run by phusions init process using /etc/services/apache/run 8 | this is just the tutum/apache-php run.sh script renamed as phusion requires 9 | the script to be named "run". 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/README.md: -------------------------------------------------------------------------------- 1 | tutum-docker-php 2 | ================ 3 | 4 | Base docker image to run PHP applications on Apache 5 | 6 | 7 | Building the base image 8 | ----------------------- 9 | 10 | To create the base image `tutum/apache-php`, execute the following command on the tutum-docker-php folder: 11 | 12 | docker build -t tutum/apache-php . 13 | 14 | 15 | Running your Apache+PHP docker image 16 | ------------------------------------ 17 | 18 | Start your image binding the external ports 80 in all interfaces to your container: 19 | 20 | docker run -d -p 80:80 tutum/apache-php 21 | 22 | Test your deployment: 23 | 24 | curl http://localhost/ 25 | 26 | Hello world! 27 | 28 | 29 | Loading your custom PHP application 30 | ----------------------------------- 31 | 32 | This image can be used as a base image for your PHP application. Create a new `Dockerfile` in your 33 | PHP application folder with the following contents: 34 | 35 | FROM tutum/apache-php 36 | 37 | After that, build the new `Dockerfile`: 38 | 39 | docker build -t username/my-php-app . 40 | 41 | And test it: 42 | 43 | docker run -d -p 80:80 username/my-php-app 44 | 45 | Test your deployment: 46 | 47 | curl http://localhost/ 48 | 49 | That's it! 50 | 51 | 52 | Loading your custom PHP application with composer requirements 53 | -------------------------------------------------------------- 54 | 55 | Create a Dockerfile like the following: 56 | 57 | FROM tutum/apache-php 58 | RUN apt-get update && apt-get install -yq git && rm -rf /var/lib/apt/lists/* 59 | RUN rm -fr /app 60 | ADD . /app 61 | RUN composer install 62 | 63 | - Replacing `git` with any dependencies that your composer packages might need. 64 | - Add your php application to `/app` 65 | 66 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | services: 3 | - docker 4 | dependencies: 5 | override: 6 | - docker build -t sut . 7 | test: 8 | override: 9 | - docker run -d -p 80:80 sut; sleep 10 10 | - curl --retry 10 --retry-delay 5 -L -I http://localhost:80 -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown www-data:www-data /app -R 3 | source /etc/apache2/envvars 4 | exec apache2 -D FOREGROUND -D NO_DETACH 5 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/sample/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello world! 4 | 5 | 17 | 18 | 19 | 20 |

21 |

My hostname is

22 | $value) { 25 | if(preg_match("/^(.*)_PORT_([0-9]*)_(TCP|UDP)$/", $key, $matches)) { 26 | $links[] = [ 27 | "name" => $matches[1], 28 | "port" => $matches[2], 29 | "proto" => $matches[3], 30 | "value" => $value 31 | ]; 32 | } 33 | } 34 | if($links) { 35 | ?> 36 |

Links found

37 | 40 | listening in available at
41 | 44 | 49 |

I have Tutum API powers!

50 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /web/tutum/tutum-docker-php/sample/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KHP-Informatics/redcap-docker/d1c0f1d69718dedf6c0e4e07333000715abf8fb7/web/tutum/tutum-docker-php/sample/logo.png --------------------------------------------------------------------------------