Skip to content

Commit

Permalink
Docker for peach
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Mar 26, 2016
1 parent d9d54ab commit e101891
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git
.git/**
custom*
LICENSE
Makefile
.dockerignore
*.yml
*.md
.bra.toml
.gitignore
Dockerfile*
peach.sublime*
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine:3.3
MAINTAINER [email protected]

# Install system utils & runtime dependencies
ADD https://github.com/tianon/gosu/releases/download/1.7/gosu-amd64 /usr/sbin/gosu
RUN chmod +x /usr/sbin/gosu \
&& apk --no-cache --no-progress add ca-certificates bash git s6 curl socat

COPY . /app/peach/
WORKDIR /app/peach/
RUN ./docker/build.sh

# Configure LibC Name Service
COPY docker/nsswitch.conf /etc/nsswitch.conf

# Configure Docker Container
VOLUME ["/data/peach"]
EXPOSE 5555
ENTRYPOINT ["docker/start.sh"]
CMD ["/bin/s6-svscan", "/app/peach/docker/s6/"]
72 changes: 72 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Docker for Peach

Visit [Docker Hub](https://hub.docker.com/r/peachdocs/peach/) see all available tags.

## Usage

To keep your data out of Docker container, we do a volume (`/var/peach` -> `/data/peach`) here, and you can change it based on your situation.

```
# Pull image from Docker Hub.
$ docker pull peachdocs/peach
# Create local directory for volume.
$ mkdir -p /var/peach
# Use `docker run` for the first time.
# Peach will complain about missing custom app.ini, leave it there and see Settings section below.
$ docker run --name=peach -p 5555:5555 -v /var/peach:/data/peach peachdocs/peach
# Use `docker start` if you have stopped it.
$ docker start peach
```

Files will be store in local path `/var/peach` in my case.

Directory `/var/peach` keeps Git repositories and Gogs data:

/var/peach
|-- custom
|-- data
|-- log

### Volume with data container

If you're more comfortable with mounting data to a data container, the commands you execute at the first time will look like as follows:

```
# Create data container
docker run --name=peach-data --entrypoint /bin/true peachdocs/peach
# Use `docker run` for the first time.
docker run --name=peach --volumes-from peach-data -p 5555:5555 peachdocs/peach
```

#### Using Docker 1.9 Volume command

```
# Create docker volume.
$ docker volume create --name peach-data
# Use `docker run` for the first time.
$ docker run --name=peach -p 5555:5555 -v peach-data:/data/peach peachdocs/peach
```

## Settings



## Upgrade

:exclamation::exclamation::exclamation:<span style="color: red">**Make sure you have volumed data to somewhere outside Docker container**</span>:exclamation::exclamation::exclamation:

Steps to upgrade Peach with Docker:

- `docker pull peachdocs/peach`
- `docker stop peach`
- `docker rm peach`
- Finally, create container as the first time and don't forget to do same volume and port mapping.

## Known Issues

- The docker container can not currently be build on Raspberry 1 (armv6l) as our base image `alpine` does not have a `go` package available for this platform.
26 changes: 26 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
set -x
set -e

# Set temp environment vars
export GOPATH=/tmp/go
export PATH=${PATH}:${GOPATH}/bin

# Install build deps
apk --no-cache --no-progress add --virtual build-deps go gcc musl-dev

# Init go environment to build
mkdir -p ${GOPATH}/src/github.com/peachdocs/
ln -s /app/peach/ ${GOPATH}/src/github.com/peachdocs/peach
cd ${GOPATH}/src/github.com/peachdocs/peach
go get -v
mv ${GOPATH}/bin/peach .

# Cleanup GOPATH
rm -r $GOPATH

# Remove build deps
apk --no-progress del build-deps

# Create user
adduser -H -D -g 'Peach Docs' peach -h /data/peach -s /bin/bash && passwd -u peach
15 changes: 15 additions & 0 deletions docker/nsswitch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# /etc/nsswitch.conf

passwd: compat
group: compat
shadow: compat

hosts: files dns
networks: files

protocols: db files
services: db files
ethers: db files
rpc: db files

netgroup: nis
5 changes: 5 additions & 0 deletions docker/s6/.s6-svscan/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

# Cleanup SOCAT services and s6 event folder
rm -rf $(find /app/peach/docker/s6/ -name 'event')
rm -rf /app/peach/docker/s6/SOCAT_*
7 changes: 7 additions & 0 deletions docker/s6/syslogd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if test -f ./setup; then
source ./setup
fi

exec gosu root /sbin/syslogd -nS -O-
56 changes: 56 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

create_socat_links() {
# Bind linked docker container to localhost socket using socat
USED_PORT="5555"
while read NAME ADDR PORT; do
if test -z "$NAME$ADDR$PORT"; then
continue
elif echo $USED_PORT | grep -E "(^|:)$PORT($|:)" > /dev/null; then
echo "init:socat | Can't bind linked container ${NAME} to localhost, port ${PORT} already in use" 1>&2
else
SERV_FOLDER=/app/gogs/docker/s6/SOCAT_${NAME}_${PORT}
mkdir -p ${SERV_FOLDER}
CMD="socat -ls TCP4-LISTEN:${PORT},fork,reuseaddr TCP4:${ADDR}:${PORT}"
echo -e "#!/bin/sh\nexec $CMD" > ${SERV_FOLDER}/run
chmod +x ${SERV_FOLDER}/run
USED_PORT="${USED_PORT}:${PORT}"
echo "init:socat | Linked container ${NAME} will be binded to localhost on port ${PORT}" 1>&2
fi
done << EOT
$(env | sed -En 's|(.*)_PORT_([0-9]+)_TCP=tcp://(.*):([0-9]+)|\1 \3 \4|p')
EOT
}

cleanup() {
# Cleanup SOCAT services and s6 event folder
# On start and on shutdown in case container has been killed
rm -rf $(find /app/peach/docker/s6/ -name 'event')
rm -rf /app/peach/docker/s6/SOCAT_*
}

create_volume_subfolder() {
# Create VOLUME subfolder
for f in /data/peach/data /data/peach/custom /data/peach/log; do
if ! test -d $f; then
mkdir -p $f
fi
done
}

cleanup
create_volume_subfolder

LINK=$(echo "$SOCAT_LINK" | tr '[:upper:]' '[:lower:]')
if [ "$LINK" = "false" -o "$LINK" = "0" ]; then
echo "init:socat | Will not try to create socat links as requested" 1>&2
else
create_socat_links
fi

# Exec CMD or S6 by default if nothing present
if [ $# -gt 0 ];then
exec "$@"
else
exec /bin/s6-svscan /app/peach/docker/s6/
fi
2 changes: 1 addition & 1 deletion public/config.codekit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"CodeKitInfo": "This is a CodeKit 2.x project configuration file. It is designed to sync project settings across multiple machines. MODIFYING THE CONTENTS OF THIS FILE IS A POOR LIFE DECISION. If you do so, you will likely cause CodeKit to crash. This file is not useful unless accompanied by the project that created it in CodeKit 2. This file is not backwards-compatible with CodeKit 1.x. For more information, see: http:\/\/incident57.com\/codekit",
"creatorBuild": "19102",
"creatorBuild": "19115",
"files": {
"\/css\/highlight-8.7\/default.css": {
"fileType": 16,
Expand Down

0 comments on commit e101891

Please sign in to comment.