Merge pull request #410 from tstorch/docker_mix_match

Docker mix and match setup
This commit is contained in:
无闻 2014-09-01 10:53:51 +08:00
Родитель bc67c34bea d1a2228f1c
Коммит d55c5b9e28
25 изменённых файлов: 373 добавлений и 40 удалений

89
docker/README.md Normal file
Просмотреть файл

@ -0,0 +1,89 @@
Docker
======
TOOLS ARE WRITTEN FOR TESTING AND TO SEE WHAT IT IS!
For this to work you will need the nifty docker tool [fig].
The most simple setup will look like this:
```sh
./assemble_blocks.sh docker_gogs w_db option_db_mysql
fig up
```
That's it. You have GoGS running in docker linked to a MySQL docker container.
Now visit http://localhost:3000/ and give details for the admin account an you're up and running.
How does it work
----------------
`./assemble_blocks.sh` will look in `blocks` for subdirectories.
In the subdirectories there are three relevant files: `Dockerfile`, `config` and `fig`.
`Dockerfile` will be copied to `docker/` (also means last `Dockerfile` wins).
The `config` file contains lines which will in the gogs docker container end up in `$GOGS_PATH/custom/config/app.ini` and by this gogs will be configured.
Here you can define things like the MySQL server for your database block.
The `fig` file will just be added to `fig.yml`, which is used by fig to manage your containers.
This inculdes container linking!
Just have a look at them and it will be clear how to write your own blocks.
Just some things
- all files (`Dockerfile`, `fig` and `config`) are optional
- the gogs block should always be the first block
Currently the blocks are designed that, the blocks that start with `docker` pull in the base docker image.
Then one block starting with `w` defines, what containers should be linked to the gogs container.
For every option in the `w` block you need to add an `option` container.
Example:
```sh
./assemble_blocks.sh docker_gogs w_db_cache option_db_mysql option_cache_redis
```
More sophisticated Example
--------------------------
Her is a more elaborated example
```sh
./assemble_blocks.sh docker_gogs w_db_cache_session option_db_postgresql option_cache_redis option_session_mysql
fig up
```
This will set up four containters and link them proberly. One for each of
- gogs
- database (postgresql)
- cache (redis)
- session (mysql)
WARNING: This will not work at the Moment! MySQL session is broken!
Remark
------
After you execute `assemble_blocks.sh` you should always trigger `fig build` to inculde the the new init script `init_gogs.sh` in the docker image.
If you want to use another GoGS docker file, but keep everything else the same, you can create a block, e.g. `docker_gogs_custom`, with only a `Dockerfile` and call
```sh
./assemble_blocks.sh docker_gogs_custom w_db option_database_mysql
```
This will pull in the `Dockerfile` from `docker_gogs` instead of the one from `docker_gogs`.
`Dockerfile`s for the `master` and `dev` branch are provided as `docker_gogs` and `docker_gogs_dev`
[fig]:http://www.fig.sh/

72
docker/assemble_blocks.sh Executable file
Просмотреть файл

@ -0,0 +1,72 @@
#!/bin/bash
blocks_dir=blocks
docker_dir=docker
template_dir=templates
docker_file=Dockerfile
gogs_config_file=conf.tmp
gogs_config=config
gogs_init_file=$docker_dir/init_gogs.sh
fig_file=fig.yml
fig_config=fig
gogs_init_template=$template_dir/init_gogs.sh.tpl
if [ "$#" == 0 ]; then
blocks=`ls $blocks_dir`
if [ -z "$blocks" ]; then
echo "No Blocks available in $blocks_dir"
else
echo "Available Blocks:"
for block in $blocks; do
echo " $block"
done
fi
exit 0
fi
for file in $gogs_config_file $fig_file; do
if [ -e $file ]; then
echo "Deleting $file"
rm $file
fi
done
for dir in $@; do
current_dir=$blocks_dir/$dir
if [ ! -d "$current_dir" ]; then
echo "$current_dir is not a directory"
exit 1
fi
if [ -e $current_dir/$docker_file ]; then
echo "Copying $current_dir/$docker_file to $docker_dir/$docker_file"
cp $current_dir/$docker_file $docker_dir/$docker_file
fi
if [ -e $current_dir/$gogs_config ]; then
echo "Adding $current_dir/$gogs_config to $gogs_config_file"
cat $current_dir/$gogs_config >> $gogs_config_file
echo "" >> $gogs_config_file
fi
if [ -e $current_dir/$fig_config ]; then
echo "Adding $current_dir/$fig_config to $fig_file"
cat $current_dir/fig >> $fig_file
echo "" >> $fig_file
fi
done
echo "Creating $gogs_init_file"
sed "/{{ CONFIG }}/{
r $gogs_config_file
d
}" $gogs_init_template > $gogs_init_file
if [ -e $gogs_config_file ]; then
echo "Removing temporary GoGS config"
rm $gogs_config_file
fi

Просмотреть файл

@ -0,0 +1,52 @@
FROM ubuntu:14.04
# This part is taken from the official docker image --------------------
RUN apt-get update && apt-get install -y \
build-essential ca-certificates curl \
bzr git mercurial \
--no-install-recommends
ENV GOLANG_VERSION 1.3
RUN curl -sSL http://golang.org/dl/go$GOLANG_VERSION.src.tar.gz \
| tar -v -C /usr/src -xz
WORKDIR /usr/src/go
RUN cd src && ./make.bash --no-clean 2>&1
ENV PATH /usr/src/go/bin:$PATH
RUN mkdir -p /go/src
ENV GOPATH /go
ENV PATH /go/bin:$PATH
WORKDIR /go
# ----------------------------------------------------------------------
RUN useradd -m git
ENV GOGS_PATH $GOPATH/src/github.com/gogits/gogs
ENV GOGS_CUSTOM_CONF_PATH $GOGS_PATH/custom/conf
ENV GOGS_CUSTOM_CONF $GOGS_CUSTOM_CONF_PATH/app.ini
RUN go get -u -d github.com/gogits/gogs
# WORKDIR $GOGS_PATH
WORKDIR /go/src/github.com/gogits/gogs
RUN go build github.com/gogits/gogs
RUN chown -R git $GOGS_PATH
ADD init_gogs.sh /tmp/
RUN chown git /tmp/init_gogs.sh
RUN chmod +x /tmp/init_gogs.sh
USER git
ENV HOME /home/git
ENV USER git
ENV PATH $GOGS_PATH:$PATH
RUN git config --global user.name "GoGS"
ENTRYPOINT ["/tmp/init_gogs.sh"]
CMD ["gogs", "web"]

Просмотреть файл

@ -0,0 +1,52 @@
FROM ubuntu:14.04
# This part is taken from the official docker image --------------------
RUN apt-get update && apt-get install -y \
build-essential ca-certificates curl \
bzr git mercurial \
--no-install-recommends
ENV GOLANG_VERSION 1.3
RUN curl -sSL http://golang.org/dl/go$GOLANG_VERSION.src.tar.gz \
| tar -v -C /usr/src -xz
WORKDIR /usr/src/go
RUN cd src && ./make.bash --no-clean 2>&1
ENV PATH /usr/src/go/bin:$PATH
RUN mkdir -p /go/src
ENV GOPATH /go
ENV PATH /go/bin:$PATH
WORKDIR /go
# ----------------------------------------------------------------------
RUN useradd -m git
ENV GOGS_PATH $GOPATH/src/github.com/gogits/gogs
ENV GOGS_CUSTOM_CONF_PATH $GOGS_PATH/custom/conf
ENV GOGS_CUSTOM_CONF $GOGS_CUSTOM_CONF_PATH/app.ini
RUN go get -u -d github.com/gogits/gogs
# WORKDIR $GOGS_PATH
WORKDIR /go/src/github.com/gogits/gogs
RUN git checkout dev; go get -u; git checkout dev; go build
RUN chown -R git $GOGS_PATH
ADD init_gogs.sh /tmp/
RUN chown git /tmp/init_gogs.sh
RUN chmod +x /tmp/init_gogs.sh
USER git
ENV HOME /home/git
ENV USER git
ENV PATH $GOGS_PATH:$PATH
RUN git config --global user.name "GoGS"
ENTRYPOINT ["/tmp/init_gogs.sh"]
CMD ["gogs", "web"]

Просмотреть файл

@ -0,0 +1,3 @@
[cache]
DB_TYPE = memcache
HOST = HOST = ${CACHE_1_PORT_11211_TCP_ADDR}:${CACHE_1_PORT_11211_TCP_PORT}

Просмотреть файл

@ -0,0 +1,2 @@
cache:
image: sylvainlasnier/memcached:latest

Просмотреть файл

@ -0,0 +1,3 @@
[cache]
DB_TYPE = redis
HOST = ${CACHE_1_PORT_6379_TCP_ADDR}:${CACHE_1_PORT_6379_TCP_PORT}

Просмотреть файл

@ -0,0 +1,2 @@
cache:
image: redis:latest

Просмотреть файл

@ -0,0 +1,6 @@
[database]
DB_TYPE = mysql
HOST = ${DB_1_PORT_3306_TCP_ADDR}:${DB_1_PORT_3306_TCP_PORT}
NAME = ${DB_1_ENV_MYSQL_DATABASE}
USER = ${DB_1_ENV_MYSQL_USER}
PASSWD = ${DB_1_ENV_MYSQL_PASSWORD}

Просмотреть файл

@ -0,0 +1,7 @@
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: gogs
MYSQL_USER: gogs
MYSQL_PASSWORD: password

Просмотреть файл

@ -0,0 +1,6 @@
[database]
DB_TYPE = postgres
HOST = ${DB_1_PORT_5432_TCP_ADDR}:${DB_1_PORT_5432_TCP_PORT}
NAME = ${DB_1_ENV_POSTGRESQL_DB}
USER = ${DB_1_ENV_POSTGRESQL_USER}
PASSWD = ${DB_1_ENV_POSTGRESQL_PASS}

Просмотреть файл

@ -0,0 +1,6 @@
db:
image: wyaeld/postgres:9.3
environment:
POSTGRESQL_DB: gogs
POSTGRESQL_USER: gogs
POSTGRESQL_PASS: password

Просмотреть файл

@ -0,0 +1,3 @@
[session]
PROVIDER = mysql
PROVIDER_CONFIG = ${SESSION_1_ENV_MYSQL_USER}:${SESSION_1_ENV_MYSQL_PASSWORD}@SESSION_1_PORT_3306_TCP_PROTO(${SESSION_1_PORT_3306_TCP_ADDR}:${SESSION_1_PORT_3306_TCP_PORT})/${SESSION_1_ENV_MYSQL_DATABASE}

Просмотреть файл

@ -0,0 +1,7 @@
session:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: gogs_session
MYSQL_USER: gogs
MYSQL_PASSWORD: password

Просмотреть файл

@ -0,0 +1,6 @@
gogs:
build: docker
links:
- cache
ports:
- "3000:3000"

Просмотреть файл

@ -0,0 +1,7 @@
gogs:
build: docker
links:
- cache
- session
ports:
- "3000:3000"

6
docker/blocks/w_db/fig Normal file
Просмотреть файл

@ -0,0 +1,6 @@
gogs:
build: docker
links:
- db
ports:
- "3000:3000"

Просмотреть файл

@ -0,0 +1,7 @@
gogs:
build: docker
links:
- db
- cache
ports:
- "3000:3000"

Просмотреть файл

@ -0,0 +1,8 @@
gogs:
build: docker
links:
- db
- cache
- session
ports:
- "3000:3000"

Просмотреть файл

@ -0,0 +1,7 @@
gogs:
build: docker
links:
- db
- session
ports:
- "3000:3000"

4
docker/blocks/w_none/fig Normal file
Просмотреть файл

@ -0,0 +1,4 @@
gogs:
build: docker
ports:
- "3000:3000"

Просмотреть файл

@ -0,0 +1,6 @@
gogs:
build: docker
links:
- session
ports:
- "3000:3000"

0
docker/docker/.gitkeep Normal file
Просмотреть файл

Просмотреть файл

@ -0,0 +1,12 @@
#!/bin/sh
if [ ! -d "$DIRECTORY" ]; then
mkdir -p $GOGS_CUSTOM_CONF_PATH
echo "
{{ CONFIG }}
" >> $GOGS_CUSTOM_CONF
fi
exec "$@"

Просмотреть файл

@ -1,40 +0,0 @@
### Install Gogs With Docker
Deploying 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 configs:
```
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:
```
cd dockerfiles
./build.sh
```
The build might take some time, just be patient. 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 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 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:
```
http://YOUR_HOST_IP:YOUR_HOST_PORT
```
Let's 'gogs'!
Ouya~