From 6cc914b090acf81382c23a48fce882d908e02dce Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Wed, 16 Apr 2014 00:14:17 +0800 Subject: [PATCH 1/6] Rename the posgresql to postgres, add the Dockerfile for postgres image. --- .../images/{posgresql => postgres}/.gitkeep | 0 dockerfiles/images/postgres/Dockerfile | 49 +++++++++++++++++++ 2 files changed, 49 insertions(+) rename dockerfiles/images/{posgresql => postgres}/.gitkeep (100%) create mode 100644 dockerfiles/images/postgres/Dockerfile diff --git a/dockerfiles/images/posgresql/.gitkeep b/dockerfiles/images/postgres/.gitkeep similarity index 100% rename from dockerfiles/images/posgresql/.gitkeep rename to dockerfiles/images/postgres/.gitkeep diff --git a/dockerfiles/images/postgres/Dockerfile b/dockerfiles/images/postgres/Dockerfile new file mode 100644 index 000000000..9f026600c --- /dev/null +++ b/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"] From 1d3c7693b762108c5d3fd6f2637482e169073855 Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Wed, 16 Apr 2014 00:16:32 +0800 Subject: [PATCH 2/6] Build the database image by the variable DB_TYPE, but not mysql. --- dockerfiles/build.sh.bak | 48 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/dockerfiles/build.sh.bak b/dockerfiles/build.sh.bak index 545a13dae..1617a1c52 100755 --- a/dockerfiles/build.sh.bak +++ b/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="mysql" +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 Dockerfile. +sed -i "s/THE_DB_TYPE/$DB_TYPE/g" images/gogits/Dockerfile - -# 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" From 8080beea858f42c5bbd116008ef7a9b01fb942a2 Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Wed, 16 Apr 2014 00:17:52 +0800 Subject: [PATCH 3/6] Add the line to replace the database type. Replace the 'mysql' options with 'db' options, makeing the config according to the database type. --- dockerfiles/images/gogits/deploy.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/dockerfiles/images/gogits/deploy.sh b/dockerfiles/images/gogits/deploy.sh index 4612a63da..8c0e246b1 100644 --- a/dockerfiles/images/gogits/deploy.sh +++ b/dockerfiles/images/gogits/deploy.sh @@ -1,14 +1,25 @@ # 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 + 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 From 1f989d0b9881c8c0c3d0d1926fa9882dc880a141 Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Wed, 16 Apr 2014 00:54:02 +0800 Subject: [PATCH 4/6] Replace the 'mysql' options with 'db' options in build.sh --- dockerfiles/build.sh | 30 +++++++++++++++++------------- dockerfiles/build.sh.bak | 6 +++--- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/dockerfiles/build.sh b/dockerfiles/build.sh index 1e7cf0ad0..272424c87 100755 --- a/dockerfiles/build.sh +++ b/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" diff --git a/dockerfiles/build.sh.bak b/dockerfiles/build.sh.bak index 1617a1c52..272424c87 100755 --- a/dockerfiles/build.sh.bak +++ b/dockerfiles/build.sh.bak @@ -1,6 +1,6 @@ # Configs of the docker images, you might have specify your own configs here. # type of database, support 'mysql' and 'postgres' -DB_TYPE="mysql" +DB_TYPE="postgres" DB_PASSWORD="YOUR_DB_PASSWORD" DB_RUN_NAME="YOUR_DB_RUN_NAME" HOST_PORT="YOUR_HOST_PORT" @@ -9,8 +9,8 @@ HOST_PORT="YOUR_HOST_PORT" 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 Dockerfile. -sed -i "s/THE_DB_TYPE/$DB_TYPE/g" images/gogits/Dockerfile +# 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 cd images/$DB_TYPE From f456f964ecdd5e01b3a54df09493a2e6adc35c09 Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Wed, 16 Apr 2014 00:55:39 +0800 Subject: [PATCH 5/6] Add the apt source when installing potgres. Replace the host with $DB_PORT, which is dependent to the database imagae's exposed port. --- dockerfiles/images/gogits/deploy.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dockerfiles/images/gogits/deploy.sh b/dockerfiles/images/gogits/deploy.sh index 8c0e246b1..47e13260c 100644 --- a/dockerfiles/images/gogits/deploy.sh +++ b/dockerfiles/images/gogits/deploy.sh @@ -14,6 +14,8 @@ 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 @@ -24,7 +26,9 @@ fi # 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") From dfba49b06289147ae1cefdbac4a31903215311c0 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Wed, 16 Apr 2014 07:50:58 +0800 Subject: [PATCH 6/6] Update README.md Add the instruction of installing gogs with PostgreSQL --- dockerfiles/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dockerfiles/README.md b/dockerfiles/README.md index 97c5aa053..cb9221d9c 100644 --- a/dockerfiles/README.md +++ b/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