Added support for external Postgres servers

This commit is contained in:
Ulrich Petri 2014-01-06 11:20:58 +01:00 committed by Sameer Naik
parent d9e166a156
commit def992d883
4 changed files with 61 additions and 10 deletions

View File

@ -10,7 +10,8 @@ RUN apt-get install -y wget curl unzip build-essential checkinstall zlib1g-dev l
RUN apt-get install -y python-software-properties && \
add-apt-repository -y ppa:git-core/ppa && \
apt-get update && apt-get install -y libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev libmysqlclient-dev \
apt-get update && \
apt-get install -y libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev libmysqlclient-dev libpq-dev \
sudo nginx git-core mysql-server openssh-server redis-server python2.7 python-docutils postfix logrotate supervisor vim && \
apt-get clean

View File

@ -140,6 +140,36 @@ docker run -d \
sameersbn/gitlab
```
#### Using an external PostgreSQL server
The image also supports using an external PostgreSQL Server. This is also controlled via environment variables.
```bash
createuser gitlab
createdb -O gitlab gitlabhq_production
```
To make sure the database is initialized start the container with **app:db:initialize** option.
**NOTE: This should be done only for the first run**.
*Assuming that the PostgreSQL server host is 192.168.1.100*
```bash
docker run -d \
-e "DB_TYPE=postgres" -e "DB_HOST=192.168.1.100" -e "DB_NAME=gitlabhq_production" -e "DB_USER=gitlab" -e "DB_PASS=password" \
-v /opt/gitlab/data:/home/git/data \
sameersbn/gitlab app:db:initialize
```
This will initialize the gitlab database. Now that the database is initialized, start the container without the initialize command.
```bash
docker run -d \
-e "DB_TYPE=postgres" -e "DB_HOST=192.168.1.100" -e "DB_NAME=gitlabhq_production" -e "DB_USER=gitlab" -e "DB_PASS=password" \
-v /opt/gitlab/data:/home/git/data \
sameersbn/gitlab
```
### Configuring Mail
The mail configuration should be specified using environment variables while starting the GitLab image. The configuration defaults to using gmail to send emails and requires the specification of a valid username and password to login to the gmail servers.
@ -294,25 +324,29 @@ Below is the complete list of parameters that can be set using environment varia
The number of concurrent sidekiq jobs to run. Defaults to 5
* DB_TYPE
The database type. Possible values: mysql, postgres. Defaults to mysql.
* DB_HOST
The mysql server hostname. Defaults to localhost.
The database server hostname. Defaults to localhost.
* DB_NAME
The mysql database name. Defaults to gitlabhq_production
The database database name. Defaults to gitlabhq_production
* DB_USER
The mysql database user. Defaults to root
The database database user. Defaults to root
* DB_PASS
The mysql database password. Defaults to no password
The database database password. Defaults to no password
* DB_POOL
The mysql database connection pool count. Defaults to 5.
The database database connection pool count. Defaults to 5.
* SMTP_HOST

View File

@ -12,6 +12,7 @@ UNICORN_WORKERS=${UNICORN_WORKERS:-2}
UNICORN_TIMEOUT=${UNICORN_TIMEOUT:-60}
SIDEKIQ_CONCURRENCY=${SIDEKIQ_CONCURRENCY:-5}
DB_TYPE=${DB_TYPE:-mysql}
DB_HOST=${DB_HOST:-localhost}
DB_NAME=${DB_NAME:-gitlabhq_production}
DB_USER=${DB_USER:-root}
@ -29,6 +30,10 @@ SMTP_PASS=${SMTP_PASS:-}
# start mysql server if ${DB_HOST} is localhost
if [ "${DB_HOST}" == "localhost" ]; then
if [ "${DB_TYPE}" == "postgres" ]; then
echo "DB_TYPE 'postgres' is not supported internally. Please provide DB_HOST."
exit 1
fi
cat > /etc/supervisor/conf.d/mysqld.conf <<EOF
[program:mysqld]
priority=20
@ -127,6 +132,17 @@ sudo -u git -H sed 's/support_email: support@localhost/support_email: '${GITLAB_
sudo -u git -H sed 's/# signup_enabled: true/signup_enabled: '${GITLAB_SIGNUP}'/' -i /home/git/gitlab/config/gitlab.yml
# configure database
if [ "${DB_TYPE}" == "postgres" ]; then
sudo -u git -H sed 's/{{DB_ADAPTER}}/postgresql/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_ENCODING}}/unicode/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/reconnect: false/#reconnect: false/' -i /home/git/gitlab/config/database.yml
elif [ "${DB_TYPE}" == "mysql" ]; then
sudo -u git -H sed 's/{{DB_ADAPTER}}/mysql2/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_ENCODING}}/utf8/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/#reconnect: false/reconnect: false/' -i /home/git/gitlab/config/database.yml
else
echo "Invalid database type: '$DB_TYPE'. Supported choices: [mysql, postgres]."
fi
sudo -u git -H sed 's/{{DB_HOST}}/'${DB_HOST}'/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_NAME}}/'${DB_NAME}'/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_USER}}/'${DB_USER}'/' -i /home/git/gitlab/config/database.yml

View File

@ -57,17 +57,17 @@ if [ -d "/gitlab/setup/cache" ]; then
# offline gem installation
mv /gitlab/setup/cache vendor/
chown -R git:git vendor/cache
sudo -u git -H bundle install --local --deployment --without development test postgres aws
sudo -u git -H bundle install --local --deployment --without development test aws
else
# online gem installation
sudo -u git -H bundle install --deployment --without development test postgres aws
sudo -u git -H bundle install --deployment --without development test aws
fi
# add database.yml template
sudo -u git -H cat > config/database.yml <<EOF
production:
adapter: mysql2
encoding: utf8
adapter: {{DB_ADAPTER}}
encoding: {{DB_ENCODING}}
reconnect: false
database: {{DB_NAME}}
host: {{DB_HOST}}