Skip to content

Commit

Permalink
Initial import of eramba
Browse files Browse the repository at this point in the history
x
  • Loading branch information
kost committed Aug 24, 2015
1 parent 466ec03 commit da8aaea
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 0 deletions.
16 changes: 16 additions & 0 deletions alpine-eramba/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM k0st/alpine-apache-php
MAINTAINER kost - https://github.com/kost

ENV VERSION_ERAMBA 204015

RUN apk --update add php-mysql php-pdo_mysql mysql-client && rm -f /var/cache/apk/* && \
curl https://s3.eu-central-1.amazonaws.com/dlh/eramba/eramba_$VERSION_ERAMBA.tgz -o /tmp/eramba_$VERSION_ERAMBA.tgz && \
tar -xvz -C /app -f /tmp/eramba_$VERSION_ERAMBA.tgz && \
rm -f /tmp/eramba_$VERSION_ERAMBA.tgz && \
mv /app/eramba_v2/* /app/ && \
mv /app/eramba_v2/.htaccess /app/ && \
rm -rf /app/eramba_v2/ && \
echo "Success"

ADD scripts/eramba-initdb.sh /scripts/pre-exec.d/eramba-initdb.sh

26 changes: 26 additions & 0 deletions alpine-eramba/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# k0st/alpine-eramba

Dockerized eramba

Image is based on the [gliderlabs/alpine](https://registry.hub.docker.com/u/gliderlabs/alpine/) base image

## Docker image size

[![Latest](https://badge.imagelayers.io/k0st/alpine-eramba.svg)](https://imagelayers.io/?images=k0st/alpine-eramba:latest 'latest')

## Docker image usage

```
docker run -it k0st/alpine-eramba
```

## Examples

Use docker compose to setup everything needed (database and web server with eramba):
```
docker-compose up
```

### Todo
- [ ] Check volume and data

15 changes: 15 additions & 0 deletions alpine-eramba/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
db:
image: k0st/alpine-mariadb
volumes:
- /data/work/erambadb:/var/lib/mysql
environment:
- MYSQL_DATABASE=erambadb
- MYSQL_USER=erambadb
- MYSQL_PASSWORD=erambapass

web:
image: k0st/alpine-eramba
ports:
- "80:10080"
links:
- db
133 changes: 133 additions & 0 deletions alpine-eramba/scripts/eramba-initdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/sh

# set -x

ERAMBADBCONF=/app/app/Config/database.php
MAXTRIES=20

if [ "$DB_ENV_MYSQL_PASSWORD" = "" ]; then
DBPWOPT=
else
DBPWOPT="-p$DB_ENV_MYSQL_PASSWORD"
fi

wait4mysql () {
echo "[i] Waiting for database to setup..."

for i in $(seq 1 1 $MAXTRIES)
do
echo "[i] Trying to connect to database: try $i..."
mysql -B --connect-timeout=1 -h db -u $DB_ENV_MYSQL_USER $DBPWOPT -e "SELECT VERSION();" $DB_ENV_MYSQL_DATABASE

if [ "$?" = "0" ]; then
echo "[i] Successfully connected to database!"
break
else
if [ "$i" = "$MAXTRIES" ]; then
echo "[!] You need to have container for database. Take a look at docker-compose.yml file!"
exit 0
else
sleep 5
fi
fi
done
}

check4mysql () {
echo "[i] Checking if database is empty..."
LISTTABLES=`(mysql -B -h db -u $DB_ENV_MYSQL_USER $DBPWOPT -e "SHOW TABLES;" $DB_ENV_MYSQL_DATABASE )`
if [ "$?" = "0" ]; then
NUMTABLES=`( echo "$LISTTABLES" | wc -l )`
echo "Tables: $NUMTABLES"
if [ "$NUMTABLES" = "1" ]; then
echo "[i] Looks like database is empty!"
return 1
fi
else
echo "[i] Error connecting to database. Exiting"
exit 1
fi
return 0
}

wait4mysql
DBEMPTY=$( check4mysql )

if [ -f "$ERAMBADBCONF" ]; then
echo "[i] Found database configuration. Not touching it!"
else
echo "[i] Database configuration missing. Creating..."

cat << EOF > $ERAMBADBCONF
<?php
class DATABASE_CONFIG {
public \$default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'db',
'login' => '$DB_ENV_MYSQL_USER',
'password' => '$DB_ENV_MYSQL_PASSWORD',
'database' => '$DB_ENV_MYSQL_DATABASE',
'prefix' => '',
'encoding' => 'utf8',
);
}
EOF

if [ "$DBEMPTY" = "1" ]; then
echo "[i] Creating initial schema..."
cat /app/app/Config/db_schema/latest.sql | mysql -h db -u $DB_ENV_MYSQL_USER $DBPWOPT $DB_ENV_MYSQL_DATABASE
else
echo "[i] Database not empty. Not touching it!"
fi
fi


if [ "$SUBURI" == "" ]; then
echo "[i] Using root (/) URI"
else
echo "[i] Using suburi: $SUBURI"
cat << EOF > /etc/apache2/conf.d/eramba.conf
Alias $SUBURI "/app/"
<Directory "/app">
Options FollowSymLinks
AllowOverride All
# Require all granted
Order allow,deny
Allow from all
</Directory>
EOF
grep ^DocumentRoot /etc/apache2/httpd.conf | grep -i /var/www/localhost/htdocs
if [ "$?" != "0" ]; then
sed -i 's#^DocumentRoot ".*#DocumentRoot "/var/www/localhost/htdocs"#g' /etc/apache2/httpd.conf
fi

grep RewriteBase /app/.htaccess
if [ "$?" != "0" ]; then
sed -i "s#RewriteEngine on#RewriteEngine on\n\tRewriteBase ${SUBURI}#gi" /app/.htaccess
else
sed -i "s#RewriteBase.*#RewriteBase ${SUBURI}#gi" /app/.htaccess
fi
grep RewriteBase /app/app/.htaccess
if [ "$?" != "0" ]; then
sed -i "s#RewriteEngine on#RewriteEngine on\n\tRewriteBase ${SUBURI}#gi" /app/app/.htaccess
else
sed -i "s#RewriteBase.*#RewriteBase ${SUBURI}#gi" /app/app/.htaccess
fi
grep RewriteBase /app/app/webroot/.htaccess
if [ "$?" != "0" ]; then
sed -i "s#RewriteEngine on#RewriteEngine on\n\tRewriteBase ${SUBURI}#gi" /app/app/webroot/.htaccess
else
sed -i "s#RewriteBase.*#RewriteBase ${SUBURI}#gi" /app/app/webroot/.htaccess
fi
fi

if [ "$DEBUG" = "" ]; then
sed -i "s#Configure::write('debug',.*)#Configure::write('debug',0)#g" /app/app/Config/core.php
fi

0 comments on commit da8aaea

Please sign in to comment.