mirror of
1
Fork 0

Merge pull request #83 from dockboard/master

Add postgresql support in docker deployed.
This commit is contained in:
无闻 2014-04-16 14:04:07 -04:00
commit e44655f722
6 changed files with 119 additions and 47 deletions

View File

@ -1,5 +1,9 @@
### Gogs Install With Docker ### Gogs Install With Docker
#### Gogs With MySQL
Deply gogs in [Docker](http://www.docker.io/) is just as easy as eating a pie, what you do is just open the `dockerfiles/build.sh` file, replace the confis: Deply gogs in [Docker](http://www.docker.io/) is just as easy as eating a pie, what you do is just open the `dockerfiles/build.sh` file, replace the confis:
``` ```
@ -35,11 +39,9 @@ http://YOUR_HOST_IP:YOUR_HOST_PORT
Let's 'gogs'! Let's 'gogs'!
#### Gogs With MySQL
#### Gogs With PostgreSQL #### Gogs With PostgreSQL
Installing Gogs with PostgreSQL is nearly the same with installing it with MySQL. What you do is just change the DB_TYPE in build.sh to 'postgres'.
#### Gogs, MySQL With Redis #### Gogs, MySQL With Redis

View File

@ -1,25 +1,29 @@
# Configs of the docker images, you might have specify your own configs here. # Configs of the docker images, you might have specify your own configs here.
MYSQL_PASSWORD="YOUR_MYSQL_PASSWORD" # type of database, support 'mysql' and 'postgres'
MYSQL_RUN_NAME="YOUR_MYSQL_RUN_NAME" DB_TYPE="postgres"
DB_PASSWORD="YOUR_DB_PASSWORD"
DB_RUN_NAME="YOUR_DB_RUN_NAME"
HOST_PORT="YOUR_HOST_PORT" HOST_PORT="YOUR_HOST_PORT"
# Replace the mysql root password in MySQL image Dockerfile. # Replace the database root password in database image Dockerfile.
sed -i "s/THE_MYSQL_PASSWORD/$MYSQL_PASSWORD/g" images/mysql/Dockerfile sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/$DB_TYPE/Dockerfile
# Replace the mysql root password in gogits image Dockerfile. # Replace the database root password in gogits image deploy.sh file.
sed -i "s/THE_MYSQL_PASSWORD/$MYSQL_PASSWORD/g" images/gogits/deploy.sh sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/gogits/deploy.sh
# Replace the database type in gogits image deploy.sh file.
sed -i "s/THE_DB_TYPE/$DB_TYPE/g" images/gogits/deploy.sh
# Build the MySQL image # Build the database image
cd images/mysql cd images/$DB_TYPE
docker build -t gogs/mysql . docker build -t gogs/$DB_TYPE .
# #
## Build the gogits image ## Build the gogits image
cd ../gogits cd ../gogits
docker build -t gogs/gogits . docker build -t gogs/gogits .
# #
## Run MySQL image with name ## Run MySQL image with name
docker run -d --name $MYSQL_RUN_NAME gogs/mysql docker run -d --name $DB_RUN_NAME gogs/$DB_TYPE
# #
## Run gogits image and link it to the MySQL image ## Run gogits image and link it to the database image
echo "Now we have the MySQL image(running) and gogs image, use the follow command to start gogs service:" echo "Now we have the $DB_TYPE image(running) and gogs image, use the follow command to start gogs service:"
echo -e "\033[33m docker run -i -t --link $MYSQL_RUN_NAME:db -p $HOST_PORT:3000 gogs/gogits \033[0m" echo -e "\033[33m docker run -i -t --link $DB_RUN_NAME:db -p $HOST_PORT:3000 gogs/gogits \033[0m"

View File

@ -1,27 +1,29 @@
# Configs # Configs of the docker images, you might have specify your own configs here.
MYSQL_PASSWORD="YOUR_MYSQL_PASSWORD" # type of database, support 'mysql' and 'postgres'
MYSQL_RUN_NAME="YOUR_MYSQL_RUN_NAME" DB_TYPE="postgres"
typeset -u MYSQL_ALIAS DB_PASSWORD="YOUR_DB_PASSWORD"
MYSQL_ALIAS="YOUR_MYSQL_ALIAS" DB_RUN_NAME="YOUR_DB_RUN_NAME"
HOST_PORT="YOUR_HOST_PORT" HOST_PORT="YOUR_HOST_PORT"
# Replace the mysql root password in MySQL image Dockerfile. # Replace the database root password in database image Dockerfile.
sed -i "s/THE_MYSQL_PASSWORD/$MYSQL_PASSWORD/g" images/mysql/Dockerfile sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/$DB_TYPE/Dockerfile
# Replace the mysql root password in gogits image Dockerfile. # Replace the database root password in gogits image deploy.sh file.
sed -i "s/THE_MYSQL_PASSWORD/$MYSQL_PASSWORD/g" images/gogits/Dockerfile sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/gogits/deploy.sh
# Replace the database type in gogits image deploy.sh file.
sed -i "s/THE_DB_TYPE/$DB_TYPE/g" images/gogits/deploy.sh
# Build the database image
# Build the MySQL image cd images/$DB_TYPE
cd images/mysql docker build -t gogs/$DB_TYPE .
docker build -i gogs/mysql . #
## Build the gogits image
# Build the gogits image cd ../gogits
cd images/gogits docker build -t gogs/gogits .
docker build -i gogs/gogits . #
## Run MySQL image with name
# Run MySQL image with name docker run -d --name $DB_RUN_NAME gogs/$DB_TYPE
docker run -d --name $MYSQL_RUN_NAME gogs/mysql #
## Run gogits image and link it to the database image
# Run gogits image and link it to the MySQL image echo "Now we have the $DB_TYPE image(running) and gogs image, use the follow command to start gogs service:"
docker run --link $MYSQL_RUN_NAME:$MYSQL_ALIAS -p $HOST_PORT:3000 gogs/gogits echo -e "\033[33m docker run -i -t --link $DB_RUN_NAME:db -p $HOST_PORT:3000 gogs/gogits \033[0m"

View File

@ -1,19 +1,34 @@
# deploy.sh in gogits image, replace the configs and run gogs # deploy.sh in gogits image, replace the configs and run gogs
## Replace the mysql password ## Replace the database password
MYSQL_PASSWORD=THE_MYSQL_PASSWORD DB_TYPE=THE_DB_TYPE
MYSQL_ALIAS=DB DB_PASSWORD=THE_DB_PASSWORD
MYSQL_PASSWORD_LINE=`awk '$0 ~ str{print NR+1}' str="USER = root" $GOPATH/src/github.com/gogits/gogs/conf/app.ini` DB_ALIAS=DB
DB_TYPE_LINE=`awk '$0 ~ str{print NR}' str="DB_TYPE = mysql" $GOPATH/src/github.com/gogits/gogs/conf/app.ini`
DB_PASSWORD_LINE=`awk '$0 ~ str{print NR+1}' str="USER = root" $GOPATH/src/github.com/gogits/gogs/conf/app.ini`
sed -i "${MYSQL_PASSWORD_LINE}s/.*$/PASSWD = $MYSQL_PASSWORD/g" $GOPATH/src/github.com/gogits/gogs/conf/app.ini sed -i "${DB_TYPE_LINE}s/.*$/DB_TYPE = $DB_TYPE/g" $GOPATH/src/github.com/gogits/gogs/conf/app.ini
sed -i "${DB_PASSWORD_LINE}s/.*$/PASSWD = $DB_PASSWORD/g" $GOPATH/src/github.com/gogits/gogs/conf/app.ini
## Replace the mysql address and port if [ $DB_TYPE = "postgres" ]
# When using --link in docker run, the mysql image's info looks like this: then
# Add the postgres in gogs image.
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
apt-get update
apt-get -y -q install python-software-properties software-properties-common
apt-get -y -q install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
fi
## Replace the database address and port
# When using --link in docker run, the database image's info looks like this:
# DB_PORT=tcp://172.17.0.2:3306 # DB_PORT=tcp://172.17.0.2:3306
# DB_PORT_3306_TCP_PORT=3306 # DB_PORT_3306_TCP_PORT=3306
# DB_PORT_3306_TCP_PROTO=tcp # DB_PORT_3306_TCP_PROTO=tcp
# DB_PORT_3306_TCP_ADDR=172.17.0.2 # DB_PORT_3306_TCP_ADDR=172.17.0.2
sed -i "/HOST = 127.0.0.1:3306/c\HOST = $DB_PORT_3306_TCP_ADDR:$DB_PORT_3306_TCP_PORT" $GOPATH/src/github.com/gogits/gogs/conf/app.ini #sed -i "/HOST = 127.0.0.1:3306/c\HOST = $DB_PORT_3306_TCP_ADDR:$DB_PORT_3306_TCP_PORT" $GOPATH/src/github.com/gogits/gogs/conf/app.ini
sed -i "/HOST = 127.0.0.1:3306/c\HOST = `echo $DB_PORT | cut -d '/' -f 3`" $GOPATH/src/github.com/gogits/gogs/conf/app.ini
cd $GOPATH/src/github.com/gogits/gogs/ cd $GOPATH/src/github.com/gogits/gogs/
# The sudo is a must here, or the go within docker container won't get the current user by os.Getenv("USERNAME") # The sudo is a must here, or the go within docker container won't get the current user by os.Getenv("USERNAME")

View File

@ -0,0 +1,49 @@
FROM ubuntu
MAINTAINER SvenDowideit@docker.com
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
# of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Update the Ubuntu and PostgreSQL repository indexes
RUN apt-get update
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
# There are some warnings (in red) that show up during the build. You can hide
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get -y -q install python-software-properties software-properties-common
RUN apt-get -y -q install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
# Note: The official Debian and Ubuntu images automatically ``apt-get clean``
# after each ``apt-get``
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&\`` to run commands one after the other - the ``\``
# allows the RUN command to span multiple lines.
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER root WITH SUPERUSER PASSWORD 'THE_DB_PASSWORD';" &&\
createdb -O root gogs
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE 5432
# Add VOLUMEs to allow backup of config, logs and databases
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]