From 5966dd78e67de613bea53a517712645c8449b358 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Thu, 10 Apr 2014 19:56:19 +0800 Subject: [PATCH 01/21] Add the scirpts for auto deploy. --- dockerfiles/build.sh | 28 ++++++++++++++++++++++++++++ dockerfiles/build.sh.bak | 27 +++++++++++++++++++++++++++ dockerfiles/images/gogits/Dockerfile | 8 ++++++-- dockerfiles/images/gogits/deploy.sh | 15 +++++++++++++++ dockerfiles/images/mysql/Dockerfile | 17 +++++++++++++---- dockerfiles/images/test/Dockerfile | 7 +++++++ dockerfiles/run.sh | 13 +++++++++++++ 7 files changed, 109 insertions(+), 6 deletions(-) create mode 100755 dockerfiles/build.sh create mode 100755 dockerfiles/build.sh.bak create mode 100644 dockerfiles/images/gogits/deploy.sh create mode 100644 dockerfiles/images/test/Dockerfile create mode 100755 dockerfiles/run.sh diff --git a/dockerfiles/build.sh b/dockerfiles/build.sh new file mode 100755 index 00000000..113f63db --- /dev/null +++ b/dockerfiles/build.sh @@ -0,0 +1,28 @@ +# Configs +MYSQL_PASSWORD="kuajie8402" +MYSQL_RUN_NAME="gogs_mysql" +typeset -u MYSQL_ALIAS +MYSQL_ALIAS="db" +HOST_PORT="3000" + +# 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 +sed -i "s/THE_MYSQL_ALIAS/$MYSQL_ALIAS/g" images/gogits/deploy.sh + + +# Build the MySQL image +cd images/mysql +docker build -t gogs/mysql . +# +## Build the gogits image +cd images/gogits +docker build -t 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 + diff --git a/dockerfiles/build.sh.bak b/dockerfiles/build.sh.bak new file mode 100755 index 00000000..545a13da --- /dev/null +++ b/dockerfiles/build.sh.bak @@ -0,0 +1,27 @@ +# Configs +MYSQL_PASSWORD="YOUR_MYSQL_PASSWORD" +MYSQL_RUN_NAME="YOUR_MYSQL_RUN_NAME" +typeset -u MYSQL_ALIAS +MYSQL_ALIAS="YOUR_MYSQL_ALIAS" +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 + + +# 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 + diff --git a/dockerfiles/images/gogits/Dockerfile b/dockerfiles/images/gogits/Dockerfile index 9c7d018b..265f86da 100644 --- a/dockerfiles/images/gogits/Dockerfile +++ b/dockerfiles/images/gogits/Dockerfile @@ -19,6 +19,10 @@ RUN cd $GOPATH/src/github.com/gogits/gogs && go build RUN apt-get autoremove -y RUN apt-get clean all -EXPOSE 3000 +# Add the deploy script to the docker image and assign execution permission to it. +ADD ./deploy.sh / +RUN chmod +x deploy.sh -CMD ["./$GOPATH/src/github.com/gogits/gogs/gogs"] +EXPOSE 3000 +CMD [/deploy.sh] +CMD ["$GOPATH/src/github.com/gogits/gogs/gogs web"] diff --git a/dockerfiles/images/gogits/deploy.sh b/dockerfiles/images/gogits/deploy.sh new file mode 100644 index 00000000..f9c2144e --- /dev/null +++ b/dockerfiles/images/gogits/deploy.sh @@ -0,0 +1,15 @@ +# deploy.sh in gogits image +# Script in the gogits image +## Replace the mysql password +MYSQL_PASSWORD=kuajie8402 +MYSQL_ALIAS=DB +MYSQL_PASSWORD_LINE=`awk '$0 ~ str{print NR+1}' str="USER = root" $GOPATH/src/github.com/gogits/gogs/conf/app.ini` + +sed -e "${MYSQL_PASSWORD_LINE}s/.*$/PASSWD = $MYSQL_PASSWORD/g" conf/app.ini + +## Replace the mysql address and port +# DB_PORT=tcp://172.17.0.2:3306 +# DB_PORT_3306_TCP_PORT=3306 +# DB_PORT_3306_TCP_PROTO=tcp +sed -e "/HOST = 127.0.0.1:3306/c\HOST = ${MYSQLALIAS}_PORT" app.ini + diff --git a/dockerfiles/images/mysql/Dockerfile b/dockerfiles/images/mysql/Dockerfile index ecf69a2c..7c032401 100644 --- a/dockerfiles/images/mysql/Dockerfile +++ b/dockerfiles/images/mysql/Dockerfile @@ -1,12 +1,21 @@ -FROM stackbrew/ubuntu:13.10 +#FROM stackbrew/ubuntu:13.10 +FROM stackbrew/ubuntu MAINTAINER Meaglith Ma (@genedna) +RUN apt-get install -y --force-yes software-properties-common + RUN echo "deb http://mirrors.aliyun.com/ubuntu/ saucy main restricted" > /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-backports main restricted universe multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security multiverse" >> /etc/apt/sources.list -#ENV MYSQL_PASSWORD docker +#RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" -#RUN echo "mysql-server mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections -#RUN echo "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections +RUN apt-get --yes --force-yes update +RUN apt-get --yes --force-yes upgrade + + +ENV MYSQL_PASSWORD kuajie8402 + +RUN echo "mysql-server mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections +RUN echo "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections RUN apt-get update && apt-get install -y --force-yes mysql-server RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf diff --git a/dockerfiles/images/test/Dockerfile b/dockerfiles/images/test/Dockerfile new file mode 100644 index 00000000..b8ed66d4 --- /dev/null +++ b/dockerfiles/images/test/Dockerfile @@ -0,0 +1,7 @@ +FROM stackbrew/ubuntu:saucy + +RUN apt-get install -y --force-yes software-properties-common +RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" +RUN apt-get --yes --force-yes update +RUN apt-get --yes --force-yes upgrade + diff --git a/dockerfiles/run.sh b/dockerfiles/run.sh new file mode 100755 index 00000000..7721ab41 --- /dev/null +++ b/dockerfiles/run.sh @@ -0,0 +1,13 @@ +# Configs +MYSQL_PASSWORD="kuajie8402" +MYSQL_RUN_NAME="gogs_mysql" +typeset -u MYSQL_ALIAS +MYSQL_ALIAS="db" +HOST_PORT="3000" + +## 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 + From 2315dc39b6c84bdb8fbbe778e56e4b27b8760ba9 Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Fri, 11 Apr 2014 14:55:43 +0800 Subject: [PATCH 02/21] Add the auto build scripts for deplying gogs with Docker. --- dockerfiles/build.sh | 15 ++++++--------- dockerfiles/images/gogits/Dockerfile | 11 ++++++++--- dockerfiles/images/gogits/deploy.sh | 15 ++++++++++----- dockerfiles/images/mysql/Dockerfile | 25 +++++++++++++++++-------- dockerfiles/images/test/Dockerfile | 7 ------- 5 files changed, 41 insertions(+), 32 deletions(-) delete mode 100644 dockerfiles/images/test/Dockerfile diff --git a/dockerfiles/build.sh b/dockerfiles/build.sh index 113f63db..57138577 100755 --- a/dockerfiles/build.sh +++ b/dockerfiles/build.sh @@ -1,16 +1,12 @@ -# Configs -MYSQL_PASSWORD="kuajie8402" -MYSQL_RUN_NAME="gogs_mysql" -typeset -u MYSQL_ALIAS -MYSQL_ALIAS="db" -HOST_PORT="3000" +# 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" +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 -sed -i "s/THE_MYSQL_ALIAS/$MYSQL_ALIAS/g" images/gogits/deploy.sh - # Build the MySQL image cd images/mysql @@ -24,5 +20,6 @@ docker build -t gogs/gogits . 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 +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" diff --git a/dockerfiles/images/gogits/Dockerfile b/dockerfiles/images/gogits/Dockerfile index 265f86da..410bb9cb 100644 --- a/dockerfiles/images/gogits/Dockerfile +++ b/dockerfiles/images/gogits/Dockerfile @@ -1,6 +1,8 @@ FROM stackbrew/ubuntu:13.10 MAINTAINER Meaglith Ma (@genedna) +ENV DEBIAN_FRONTEND noninteractive + RUN echo "deb http://mirrors.aliyun.com/ubuntu/ saucy main restricted" > /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-backports main restricted universe multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security multiverse" >> /etc/apt/sources.list RUN mkdir -p /go @@ -13,9 +15,12 @@ RUN apt-get update && apt-get install --yes --force-yes curl git mercurial zip w RUN curl -s http://docker.u.qiniudn.com/go1.2.1.src.tar.gz | tar -v -C /usr/local -xz RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1 -RUN http_proxy=106.187.38.45:3128 go get -u github.com/gogits/gogs +# You may need a proxy, if github is very slow. +#RUN http_proxy=106.187.38.45:3128 go get -u github.com/gogits/gogs +RUN go get -u github.com/gogits/gogs RUN cd $GOPATH/src/github.com/gogits/gogs && go build +# Clean all the unused packages RUN apt-get autoremove -y RUN apt-get clean all @@ -24,5 +29,5 @@ ADD ./deploy.sh / RUN chmod +x deploy.sh EXPOSE 3000 -CMD [/deploy.sh] -CMD ["$GOPATH/src/github.com/gogits/gogs/gogs web"] + +CMD /deploy.sh diff --git a/dockerfiles/images/gogits/deploy.sh b/dockerfiles/images/gogits/deploy.sh index f9c2144e..4612a63d 100644 --- a/dockerfiles/images/gogits/deploy.sh +++ b/dockerfiles/images/gogits/deploy.sh @@ -1,15 +1,20 @@ -# deploy.sh in gogits image -# Script in the gogits image +# deploy.sh in gogits image, replace the configs and run gogs + ## Replace the mysql password -MYSQL_PASSWORD=kuajie8402 +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` -sed -e "${MYSQL_PASSWORD_LINE}s/.*$/PASSWD = $MYSQL_PASSWORD/g" conf/app.ini +sed -i "${MYSQL_PASSWORD_LINE}s/.*$/PASSWD = $MYSQL_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: # DB_PORT=tcp://172.17.0.2:3306 # DB_PORT_3306_TCP_PORT=3306 # DB_PORT_3306_TCP_PROTO=tcp -sed -e "/HOST = 127.0.0.1:3306/c\HOST = ${MYSQLALIAS}_PORT" app.ini +# 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 +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") +sudo ./gogs web diff --git a/dockerfiles/images/mysql/Dockerfile b/dockerfiles/images/mysql/Dockerfile index 7c032401..9b163e32 100644 --- a/dockerfiles/images/mysql/Dockerfile +++ b/dockerfiles/images/mysql/Dockerfile @@ -1,18 +1,16 @@ #FROM stackbrew/ubuntu:13.10 -FROM stackbrew/ubuntu +#FROM stackbrew/ubuntu +FROM stackbrew/ubuntu:saucy MAINTAINER Meaglith Ma (@genedna) +ENV DEBIAN_FRONTEND noninteractive + RUN apt-get install -y --force-yes software-properties-common - -RUN echo "deb http://mirrors.aliyun.com/ubuntu/ saucy main restricted" > /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-backports main restricted universe multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security multiverse" >> /etc/apt/sources.list - -#RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" - +RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" RUN apt-get --yes --force-yes update RUN apt-get --yes --force-yes upgrade - -ENV MYSQL_PASSWORD kuajie8402 +ENV MYSQL_PASSWORD THE_MYSQL_PASSWORD RUN echo "mysql-server mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections RUN echo "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections @@ -20,9 +18,20 @@ RUN echo "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD RUN apt-get update && apt-get install -y --force-yes mysql-server RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf +RUN service mysql restart + +RUN echo "mysql -uroot -p$MYSQL_PASSWORD -e 'drop database if exists gogs;'" >> import.sh +RUN echo "mysql -uroot -p$MYSQL_PASSWORD -e 'create database gogs;'" >> import.sh +RUN chmod +x import.sh + RUN apt-get autoremove -y RUN apt-get clean all +RUN /usr/sbin/mysqld & \ + sleep 10s &&\ + echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql -p$MYSQL_PASSWORD &&\ + ./import.sh + EXPOSE 3306 CMD ["/usr/bin/mysqld_safe", "--skip-syslog", "--log-error=/dev/null"] diff --git a/dockerfiles/images/test/Dockerfile b/dockerfiles/images/test/Dockerfile deleted file mode 100644 index b8ed66d4..00000000 --- a/dockerfiles/images/test/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM stackbrew/ubuntu:saucy - -RUN apt-get install -y --force-yes software-properties-common -RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" -RUN apt-get --yes --force-yes update -RUN apt-get --yes --force-yes upgrade - From b1a3ba9932f2894a70d7f8e04ffc6ea8d71ce779 Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Fri, 11 Apr 2014 15:32:57 +0800 Subject: [PATCH 03/21] Fix the path problem, which will build the mysql image as the gogits image --- dockerfiles/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dockerfiles/build.sh b/dockerfiles/build.sh index 57138577..1e7cf0ad 100755 --- a/dockerfiles/build.sh +++ b/dockerfiles/build.sh @@ -13,13 +13,13 @@ cd images/mysql docker build -t gogs/mysql . # ## Build the gogits image -cd images/gogits +cd ../gogits docker build -t 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 -echo "Now we have the MySQL image(running) and gogs image, use the follow command to start gogs service:' +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" From a4f070b828638fe74946299618495af7efe028a7 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Fri, 11 Apr 2014 16:10:52 +0800 Subject: [PATCH 04/21] Update README.md Update the guide of how to deploy gogs in docker with the scripts. --- dockerfiles/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dockerfiles/README.md b/dockerfiles/README.md index 4268c7c2..97c5aa05 100644 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -1,5 +1,39 @@ ### Gogs Install With Docker +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: + +``` +MYSQL_PASSWORD="YOUR_MYSQL_PASSWORD" +MYSQL_RUN_NAME="YOUR_MYSQL_RUN_NAME" +HOST_PORT="YOUR_HOST_PORT" +``` + +And run: +``` +cd dockerfiles +./build.sh +``` + +The build might take some time, just be paient. After it finishes, you will receive the message: + +``` +Now we have the MySQL image(running) and gogs image, use the follow command to start gogs service( the content might be different, according to your own configs): + docker run -i -t --link gogs_mysql:db -p 3333:3000 gogs/gogits +``` + +Just follow the message, run: + +``` + docker run -i -t --link gogs_mysql:db -p 3333:3000 gogs/gogits +``` + +Now we have gogs running! Open the browser and navigate to: + +``` +http://YOUR_HOST_IP:YOUR_HOST_PORT +``` + +Let's 'gogs'! #### Gogs With MySQL From 6cc914b090acf81382c23a48fce882d908e02dce Mon Sep 17 00:00:00 2001 From: Lance Ju Date: Wed, 16 Apr 2014 00:14:17 +0800 Subject: [PATCH 05/21] 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 00000000..9f026600 --- /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 06/21] 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 545a13da..1617a1c5 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 07/21] 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 4612a63d..8c0e246b 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 08/21] 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 1e7cf0ad..272424c8 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 1617a1c5..272424c8 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 09/21] 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 8c0e246b..47e13260 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 213b366959ad404c13be23386248b7f05a951459 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 15 Apr 2014 23:34:58 -0400 Subject: [PATCH 10/21] Remove the installation of PostgreSQL, which not needed actually. --- dockerfiles/images/gogits/deploy.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/dockerfiles/images/gogits/deploy.sh b/dockerfiles/images/gogits/deploy.sh index 47e13260..34016de2 100644 --- a/dockerfiles/images/gogits/deploy.sh +++ b/dockerfiles/images/gogits/deploy.sh @@ -10,16 +10,6 @@ DB_PASSWORD_LINE=`awk '$0 ~ str{print NR+1}' str="USER = root" $GOPATH/src/githu 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 -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 From bb84bb8ac3003fdab62b397a21620ef272582a91 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 15 Apr 2014 23:41:46 -0400 Subject: [PATCH 11/21] Add two apt source:aliyun and nchc, make a '#sourcename#' before the RUN command to make the apt source configurable in build.sh --- dockerfiles/images/gogits/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dockerfiles/images/gogits/Dockerfile b/dockerfiles/images/gogits/Dockerfile index 410bb9cb..6a734c13 100644 --- a/dockerfiles/images/gogits/Dockerfile +++ b/dockerfiles/images/gogits/Dockerfile @@ -3,7 +3,9 @@ MAINTAINER Meaglith Ma (@genedna) ENV DEBIAN_FRONTEND noninteractive -RUN echo "deb http://mirrors.aliyun.com/ubuntu/ saucy main restricted" > /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-backports main restricted universe multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security multiverse" >> /etc/apt/sources.list +#aliyun#RUN echo "deb http://mirrors.aliyun.com/ubuntu/ saucy main restricted" > /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-updates multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-backports main restricted universe multiverse" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security main restricted" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security universe" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/ubuntu/ saucy-security multiverse" >> /etc/apt/sources.list + +#nchc#RUN echo "deb http://free.nchc.org.tw/ubuntu/ saucy main restricted" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy main restricted" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy-updates main restricted" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy-updates main restricted" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy universe" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy universe" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy-updates universe" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy-updates universe" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy multiverse" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy multiverse" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy-updates multiverse" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy-updates multiverse" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy-backports main restricted universe multiverse" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy-backports main restricted universe multiverse" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy-security main restricted" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy-security main restricted" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy-security universe" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy-security universe" >> /etc/apt/source.list && echo "deb http://free.nchc.org.tw/ubuntu/ saucy-security multiverse" >> /etc/apt/source.list && echo "deb-src http://free.nchc.org.tw/ubuntu/ saucy-security multiverse" >> /etc/apt/source.list && echo "deb http://extras.ubuntu.com/ubuntu saucy main" >> /etc/apt/source.list && echo "deb-src http://extras.ubuntu.com/ubuntu saucy main" >> /etc/apt/source.list RUN mkdir -p /go ENV PATH /usr/local/go/bin:/go/bin:$PATH From 066d91e1136249b2192ba6d9b8b14d106c1a1fe6 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 15 Apr 2014 23:48:33 -0400 Subject: [PATCH 12/21] Allow the user to config the apt source in build.sh --- dockerfiles/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dockerfiles/build.sh b/dockerfiles/build.sh index 272424c8..9b39afa5 100755 --- a/dockerfiles/build.sh +++ b/dockerfiles/build.sh @@ -1,6 +1,10 @@ # Configs of the docker images, you might have specify your own configs here. + # type of database, support 'mysql' and 'postgres' DB_TYPE="postgres" +# apt source, you can select 'nchc' or 'aliyun' according to your network. +APT_SOURCE="nchc" + DB_PASSWORD="YOUR_DB_PASSWORD" DB_RUN_NAME="YOUR_DB_RUN_NAME" HOST_PORT="YOUR_HOST_PORT" @@ -9,6 +13,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 apt source in gogits image Dockerfile. +sed -i "s/#$APT_SOURCE#//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 From 4b8d72dec253f1abbcbb3affe5380522a010bb07 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 22 Apr 2014 09:49:10 +0000 Subject: [PATCH 13/21] Change the MySQL password placeholder to THE_DB_PASSWORD. --- dockerfiles/images/mysql/Dockerfile | 2 +- dockerfiles/images/postgres/Dockerfile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dockerfiles/images/mysql/Dockerfile b/dockerfiles/images/mysql/Dockerfile index 9b163e32..8fff5a19 100644 --- a/dockerfiles/images/mysql/Dockerfile +++ b/dockerfiles/images/mysql/Dockerfile @@ -10,7 +10,7 @@ RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -s RUN apt-get --yes --force-yes update RUN apt-get --yes --force-yes upgrade -ENV MYSQL_PASSWORD THE_MYSQL_PASSWORD +ENV MYSQL_PASSWORD THE_DB_PASSWORD RUN echo "mysql-server mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections RUN echo "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections diff --git a/dockerfiles/images/postgres/Dockerfile b/dockerfiles/images/postgres/Dockerfile index 9f026600..44e82b7d 100644 --- a/dockerfiles/images/postgres/Dockerfile +++ b/dockerfiles/images/postgres/Dockerfile @@ -1,6 +1,8 @@ FROM ubuntu MAINTAINER SvenDowideit@docker.com +ENV DEBIAN_FRONTEND noninteractive + # 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 From 8a6119551b35031387e06d6aa0cb3e95d72a40a2 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 22 Apr 2014 10:14:10 +0000 Subject: [PATCH 14/21] Add the memcache(d) Dockerfile --- .../images/{memcached => memcache}/.gitkeep | 0 dockerfiles/images/memcache/Dockerfile | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+) rename dockerfiles/images/{memcached => memcache}/.gitkeep (100%) create mode 100644 dockerfiles/images/memcache/Dockerfile diff --git a/dockerfiles/images/memcached/.gitkeep b/dockerfiles/images/memcache/.gitkeep similarity index 100% rename from dockerfiles/images/memcached/.gitkeep rename to dockerfiles/images/memcache/.gitkeep diff --git a/dockerfiles/images/memcache/Dockerfile b/dockerfiles/images/memcache/Dockerfile new file mode 100644 index 00000000..2466c1f5 --- /dev/null +++ b/dockerfiles/images/memcache/Dockerfile @@ -0,0 +1,26 @@ +FROM ubuntu + +# Set the file maintainer (your name - the file's author) +MAINTAINER Borja Burgos + +ENV DEBIAN_FRONTEND noninteractive + +# Update the default application repository sources list +RUN apt-get update + +# Install Memcached +RUN apt-get install -y memcached + +# Port to expose (default: 11211) +EXPOSE 11211 + +# Default Memcached run command arguments +# Change to limit memory when creating container in Tutum +CMD ["-m", "64"] + +# Set the user to run Memcached daemon +USER daemon + +# Set the entrypoint to memcached binary +ENTRYPOINT memcached + From b60d5ecc3e09d242c6c5d48e9a7714563282c6d9 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 22 Apr 2014 10:15:12 +0000 Subject: [PATCH 15/21] Add the redis Dockerfile --- dockerfiles/images/redis/Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dockerfiles/images/redis/Dockerfile diff --git a/dockerfiles/images/redis/Dockerfile b/dockerfiles/images/redis/Dockerfile new file mode 100644 index 00000000..d8b24d5a --- /dev/null +++ b/dockerfiles/images/redis/Dockerfile @@ -0,0 +1,14 @@ +FROM stackbrew/ubuntu:saucy +MAINTAINER Meaglith Ma (@genedna), Lance Ju (@crystaldust) + +ENV DEBIAN_FRONTEND noninteractive + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get install -y redis-server +# Usually redis doesn't need a password +#RUN sed -i "s/# requirepass foobared/requirepass THE_REDIS_PASSWORD/g" /etc/redis/redis.conf +EXPOSE 6379 +ENTRYPOINT ["/usr/bin/redis-server"] +CMD ["--bind", "0.0.0.0"] + From 65ad26feba64ce88cee71af7ec0cc2bea17084bc Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 22 Apr 2014 10:19:23 +0000 Subject: [PATCH 16/21] Checkout to the latest dev branch when building the gogs docker image. --- dockerfiles/images/gogits/Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dockerfiles/images/gogits/Dockerfile b/dockerfiles/images/gogits/Dockerfile index 6a734c13..25d1dd5e 100644 --- a/dockerfiles/images/gogits/Dockerfile +++ b/dockerfiles/images/gogits/Dockerfile @@ -13,14 +13,13 @@ ENV GOROOT /usr/local/go ENV GOPATH /go RUN apt-get update && apt-get install --yes --force-yes curl git mercurial zip wget ca-certificates build-essential +RUN apt-get install -yq vim RUN curl -s http://docker.u.qiniudn.com/go1.2.1.src.tar.gz | tar -v -C /usr/local -xz RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1 -# You may need a proxy, if github is very slow. -#RUN http_proxy=106.187.38.45:3128 go get -u github.com/gogits/gogs -RUN go get -u github.com/gogits/gogs -RUN cd $GOPATH/src/github.com/gogits/gogs && go build +RUN go get -u -d github.com/gogits/gogs +RUN cd $GOPATH/src/github.com/gogits/gogs && git checkout dev && git pull origin dev && go install && go build -tags redis # Clean all the unused packages RUN apt-get autoremove -y From 1560abe55302c8d55ab7c027f2bcf5de5242850a Mon Sep 17 00:00:00 2001 From: crystaldust Date: Tue, 22 Apr 2014 10:20:27 +0000 Subject: [PATCH 17/21] Add the MEM db config replacement script in the deploy.sh. --- dockerfiles/images/gogits/deploy.sh | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/dockerfiles/images/gogits/deploy.sh b/dockerfiles/images/gogits/deploy.sh index 34016de2..94085248 100644 --- a/dockerfiles/images/gogits/deploy.sh +++ b/dockerfiles/images/gogits/deploy.sh @@ -4,12 +4,47 @@ DB_TYPE=THE_DB_TYPE DB_PASSWORD=THE_DB_PASSWORD DB_ALIAS=DB +MEM_TYPE=THE_MEM_TYPE + 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 "${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 + + +if [ $MEM_TYPE != "" ] + then + MEM_HOST_LINE=`awk '$0 ~ str{print NR+6}' str="ADAPTER = memory" $GOPATH/src/github.com/gogits/gogs/conf/app.ini` + + _MEM_ADDR=`echo $MEM_PORT | cut -d '/' -f 3 | cut -d ':' -f 1` + _MEM_PORT=`echo $MEM_PORT | cut -d '/' -f 3 | cut -d ':' -f 2` + + # take advantage of memory db for adapter and provider + sed -i "s/ADAPTER = memory/ADAPTER = $MEM_TYPE/g" $GOPATH/src/github.com/gogits/gogs/conf/app.ini + # Comment the memory interval since we don't use 'memory' as adapter + sed -i "s/INTERVAL = 60/;INTERVAL = 60/g" $GOPATH/src/github.com/gogits/gogs/conf/app.ini + + + case $MEM_TYPE in + "redis") + # Modify the adapter host + sed -i "${MEM_HOST_LINE}s/.*/HOST = $_MEM_ADDR:$_MEM_PORT/" $GOPATH/src/github.com/gogits/gogs/conf/app.ini + sed -i "s/PROVIDER = file/PROVIDER = $MEM_TYPE/g" $GOPATH/src/github.com/gogits/gogs/conf/app.ini + # Modify the provider config + sed -i "s#PROVIDER_CONFIG = data/sessions#PROVIDER_CONFIG = $_MEM_ADDR:$_MEM_PORT#g" $GOPATH/src/github.com/gogits/gogs/conf/app.ini + ;; + + "memcache") + # Modify the adapter host + sed -i "${MEM_HOST_LINE}s/.*/HOST = $_MEM_ADDR:$_MEM_PORT/" $GOPATH/src/github.com/gogits/gogs/conf/app.ini + ;; + esac + +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 From a90a01403303ddfea2c8bf9d903c02de2d0d7106 Mon Sep 17 00:00:00 2001 From: crystaldust Date: Wed, 23 Apr 2014 00:05:14 +0000 Subject: [PATCH 18/21] Change the image naming, start with "gogits/" --- dockerfiles/build.sh | 51 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/dockerfiles/build.sh b/dockerfiles/build.sh index 9b39afa5..d6fb8f5f 100755 --- a/dockerfiles/build.sh +++ b/dockerfiles/build.sh @@ -1,12 +1,15 @@ # Configs of the docker images, you might have specify your own configs here. # type of database, support 'mysql' and 'postgres' -DB_TYPE="postgres" -# apt source, you can select 'nchc' or 'aliyun' according to your network. -APT_SOURCE="nchc" +DB_TYPE="YOUR_DB_TYPE" +# type of memory database, support 'redis' and 'memcache' +MEM_TYPE="YOUR_MEM_TYPE" +# apt source, you can select 'nchc'(mirror in Taiwan) or 'aliyun'(best for mainlance China users) according to your network, if you could connect to the official unbunt mirror in a fast speed, just leave it to "". +APT_SOURCE="" DB_PASSWORD="YOUR_DB_PASSWORD" DB_RUN_NAME="YOUR_DB_RUN_NAME" +MEM_RUN_NAME="YOUR_MEM_RUN_NAME" HOST_PORT="YOUR_HOST_PORT" # Replace the database root password in database image Dockerfile. @@ -14,22 +17,54 @@ 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 apt source in gogits image Dockerfile. -sed -i "s/#$APT_SOURCE#//g" images/gogits/Dockerfile +sed -i "s/#$APT_SOURCE#//" images/gogits/Dockerfile +# Uncomment the installation of database lib in gogs Dockerfile +sed -i "s/#$DB_TYPE#//" 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 +if [ $MEM_TYPE != "" ] + then + # Replace the mem configs in deploy.sh + sed -i "s/THE_MEM_TYPE/$MEM_TYPE/g" images/gogits/deploy.sh + # Uncomment the installation of go mem lib + sed -i "s/#$MEM_TYPE#//" images/gogits/Dockerfile + + # Add the tags when get gogs + sed -i "s#RUN go get -u -d github.com/gogits/gogs#RUN go get -u -d -tags $MEM_TYPE github.com/gogits/gogs#g" images/gogits/Dockerfile + # Append the tag in gogs build + GOGS_BUILD_LINE=`awk '$0 ~ str{print NR}' str="go build" images/gogits/Dockerfile` + # Append the build tags + sed -i "${GOGS_BUILD_LINE}s/$/ -tags $MEM_TYPE/" images/gogits/Dockerfile + + cd images/$MEM_TYPE + docker build -t gogits/$MEM_TYPE . + docker run -d --name $MEM_RUN_NAME gogits/$MEM_TYPE + MEM_LINK=" --link $MEM_RUN_NAME:mem " + cd ../../ +fi + # Build the database image cd images/$DB_TYPE -docker build -t gogs/$DB_TYPE . +docker build -t gogits/$DB_TYPE . # + + ## Build the gogits image cd ../gogits -docker build -t gogs/gogits . + +docker build -t gogits/gogs . + +#sed -i "s#RUN go get -u -tags $MEM_TYPE github.com/gogits/gogs#RUN go get -u github.com/gogits/gogs#g" Dockerfile + +# Remove the appended tags in go build line(if there is any) +sed -i "s/ -tags $MEM_TYPE//" Dockerfile + # ## Run MySQL image with name -docker run -d --name $DB_RUN_NAME gogs/$DB_TYPE +docker run -d --name $DB_RUN_NAME gogits/$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" +echo -e "\033[33m docker run -i -t --link $DB_RUN_NAME:db $MEM_LINK -p $HOST_PORT:3000 gogits/gogs \033[0m" From e5aaf23bb21a7a7ead371a30d1e5c26c114b346e Mon Sep 17 00:00:00 2001 From: crystaldust Date: Wed, 23 Apr 2014 02:26:56 +0000 Subject: [PATCH 19/21] Update the githu.com/Unknwon/com module before getting gogs. --- dockerfiles/images/gogits/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/dockerfiles/images/gogits/Dockerfile b/dockerfiles/images/gogits/Dockerfile index 25d1dd5e..1b85f3bd 100644 --- a/dockerfiles/images/gogits/Dockerfile +++ b/dockerfiles/images/gogits/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get install -yq vim RUN curl -s http://docker.u.qiniudn.com/go1.2.1.src.tar.gz | tar -v -C /usr/local -xz RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1 +RUN go get -u github.com/Unknwon/com RUN go get -u -d github.com/gogits/gogs RUN cd $GOPATH/src/github.com/gogits/gogs && git checkout dev && git pull origin dev && go install && go build -tags redis From baacba96ca760608036fd770afac48adaaa36d1c Mon Sep 17 00:00:00 2001 From: crystaldust Date: Wed, 23 Apr 2014 03:16:09 +0000 Subject: [PATCH 20/21] Remove the dependency of Unkwon/com, since gogs has already integrate the lateset version of Unkwon/com. --- dockerfiles/images/gogits/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/dockerfiles/images/gogits/Dockerfile b/dockerfiles/images/gogits/Dockerfile index 1b85f3bd..25d1dd5e 100644 --- a/dockerfiles/images/gogits/Dockerfile +++ b/dockerfiles/images/gogits/Dockerfile @@ -18,7 +18,6 @@ RUN apt-get install -yq vim RUN curl -s http://docker.u.qiniudn.com/go1.2.1.src.tar.gz | tar -v -C /usr/local -xz RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1 -RUN go get -u github.com/Unknwon/com RUN go get -u -d github.com/gogits/gogs RUN cd $GOPATH/src/github.com/gogits/gogs && git checkout dev && git pull origin dev && go install && go build -tags redis From b01e967a9f2526365c71c49cdebf16bda43cd7fd Mon Sep 17 00:00:00 2001 From: crystaldust Date: Wed, 23 Apr 2014 03:29:17 +0000 Subject: [PATCH 21/21] Add the configs comments, and update the README.md file --- dockerfiles/README.md | 39 +++++++++++---------------------------- dockerfiles/build.sh | 16 +++++++--------- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/dockerfiles/README.md b/dockerfiles/README.md index 97c5aa05..2989bd36 100644 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -1,11 +1,14 @@ -### Gogs Install With Docker +### Install Gogs With Docker -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: +Deplying 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: ``` -MYSQL_PASSWORD="YOUR_MYSQL_PASSWORD" -MYSQL_RUN_NAME="YOUR_MYSQL_RUN_NAME" -HOST_PORT="YOUR_HOST_PORT" +DB_TYPE="YOUR_DB_TYPE" # type of database, support 'mysql' and 'postgres' +MEM_TYPE="YOUR_MEM_TYPE" # type of memory database, support 'redis' and 'memcache' +DB_PASSWORD="YOUR_DB_PASSWORD" # The database password. +DB_RUN_NAME="YOUR_DB_RUN_NAME" # The --name option value when run the database image. +MEM_RUN_NAME="YOUR_MEM_RUN_NAME" # The --name option value when run the mem database image. +HOST_PORT="YOUR_HOST_PORT" # The port on host, which will be redirected to the port 3000 inside gogs container. ``` And run: @@ -18,13 +21,13 @@ The build might take some time, just be paient. After it finishes, you will rece ``` Now we have the MySQL image(running) and gogs image, use the follow command to start gogs service( the content might be different, according to your own configs): - docker run -i -t --link gogs_mysql:db -p 3333:3000 gogs/gogits + docker run -i -t --link YOUR_DB_RUN_NAME:db --link YOUR_MEM_RUN_NAME:mem -p YOUR_HOST_PORT:3000 gogits/gogs ``` Just follow the message, run: ``` - docker run -i -t --link gogs_mysql:db -p 3333:3000 gogs/gogits + docker run -i -t --link YOUR_DB_RUN_NAME:db --link YOUR_MEM_RUN_NAME:mem -p YOUR_HOST_PORT:3000 gogits/gogs ``` Now we have gogs running! Open the browser and navigate to: @@ -34,24 +37,4 @@ http://YOUR_HOST_IP:YOUR_HOST_PORT ``` Let's 'gogs'! - -#### Gogs With MySQL - - -#### Gogs With PostgreSQL - - -#### Gogs, MySQL With Redis - - -#### Gogs, MySQL With Memcached - - -#### Gogs, PostgreSQL With Redis - - -#### Gogs, PostgreSQL With Memcached - - - - +Ouya~ diff --git a/dockerfiles/build.sh b/dockerfiles/build.sh index d6fb8f5f..83f7e9a5 100755 --- a/dockerfiles/build.sh +++ b/dockerfiles/build.sh @@ -1,17 +1,15 @@ # Configs of the docker images, you might have specify your own configs here. -# type of database, support 'mysql' and 'postgres' -DB_TYPE="YOUR_DB_TYPE" -# type of memory database, support 'redis' and 'memcache' -MEM_TYPE="YOUR_MEM_TYPE" +DB_TYPE="YOUR_DB_TYPE" # type of database, support 'mysql' and 'postgres' +MEM_TYPE="YOUR_MEM_TYPE" # type of memory database, support 'redis' and 'memcache' +DB_PASSWORD="YOUR_DB_PASSWORD" # The database password. +DB_RUN_NAME="YOUR_DB_RUN_NAME" # The --name option value when run the database image. +MEM_RUN_NAME="YOUR_MEM_RUN_NAME" # The --name option value when run the mem database image. +HOST_PORT="YOUR_HOST_PORT" # The port on host, which will be redirected to the port 3000 inside gogs container. + # apt source, you can select 'nchc'(mirror in Taiwan) or 'aliyun'(best for mainlance China users) according to your network, if you could connect to the official unbunt mirror in a fast speed, just leave it to "". APT_SOURCE="" -DB_PASSWORD="YOUR_DB_PASSWORD" -DB_RUN_NAME="YOUR_DB_RUN_NAME" -MEM_RUN_NAME="YOUR_MEM_RUN_NAME" -HOST_PORT="YOUR_HOST_PORT" - # 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.