mirror of https://github.com/go-gitea/gitea
Merge pull request #83 from dockboard/master
Add postgresql support in docker deployed.pull/197/head
commit
e44655f722
@ -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" |
||||
|
||||
|
@ -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" |
||||
|
||||
|
@ -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…
Reference in new issue