Browse Source

Merge pull request #83 from dockboard/master

Add postgresql support in docker deployed.
pull/85/head
无闻 11 years ago
parent
commit
e44655f722
  1. 8
      dockerfiles/README.md
  2. 30
      dockerfiles/build.sh
  3. 48
      dockerfiles/build.sh.bak
  4. 31
      dockerfiles/images/gogits/deploy.sh
  5. 0
      dockerfiles/images/postgres/.gitkeep
  6. 49
      dockerfiles/images/postgres/Dockerfile

8
dockerfiles/README.md

@ -1,5 +1,9 @@
### 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:
```
@ -35,11 +39,9 @@ http://YOUR_HOST_IP:YOUR_HOST_PORT
Let's 'gogs'!
#### Gogs With MySQL
#### 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

30
dockerfiles/build.sh

@ -1,25 +1,29 @@
# Configs of the docker images, you might have specify your own configs here.
MYSQL_PASSWORD="YOUR_MYSQL_PASSWORD"
MYSQL_RUN_NAME="YOUR_MYSQL_RUN_NAME"
# type of database, support 'mysql' and 'postgres'
DB_TYPE="postgres"
DB_PASSWORD="YOUR_DB_PASSWORD"
DB_RUN_NAME="YOUR_DB_RUN_NAME"
HOST_PORT="YOUR_HOST_PORT"
# Replace the mysql root password in MySQL image Dockerfile.
sed -i "s/THE_MYSQL_PASSWORD/$MYSQL_PASSWORD/g" images/mysql/Dockerfile
# Replace the mysql root password in gogits image Dockerfile.
sed -i "s/THE_MYSQL_PASSWORD/$MYSQL_PASSWORD/g" images/gogits/deploy.sh
# Replace the database root password in database image Dockerfile.
sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/$DB_TYPE/Dockerfile
# Replace the database root password in gogits image deploy.sh file.
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
cd images/mysql
docker build -t gogs/mysql .
# Build the database image
cd images/$DB_TYPE
docker build -t gogs/$DB_TYPE .
#
## Build the gogits image
cd ../gogits
docker build -t gogs/gogits .
#
## 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
echo "Now we have the MySQL 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"
## Run gogits image and link it to the database image
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 $DB_RUN_NAME:db -p $HOST_PORT:3000 gogs/gogits \033[0m"

48
dockerfiles/build.sh.bak

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

31
dockerfiles/images/gogits/deploy.sh

@ -1,19 +1,34 @@
# deploy.sh in gogits image, replace the configs and run gogs
## Replace the mysql password
MYSQL_PASSWORD=THE_MYSQL_PASSWORD
MYSQL_ALIAS=DB
MYSQL_PASSWORD_LINE=`awk '$0 ~ str{print NR+1}' str="USER = root" $GOPATH/src/github.com/gogits/gogs/conf/app.ini`
## Replace the database password
DB_TYPE=THE_DB_TYPE
DB_PASSWORD=THE_DB_PASSWORD
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
# When using --link in docker run, the mysql image's info looks like this:
if [ $DB_TYPE = "postgres" ]
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_3306_TCP_PORT=3306
# DB_PORT_3306_TCP_PROTO=tcp
# 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/
# The sudo is a must here, or the go within docker container won't get the current user by os.Getenv("USERNAME")

0
dockerfiles/images/posgresql/.gitkeep → dockerfiles/images/postgres/.gitkeep

49
dockerfiles/images/postgres/Dockerfile

@ -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"]
Loading…
Cancel
Save