added backup container, added version tagd via travis builds, fixed several bugs

This commit is contained in:
André Bauer 2017-07-22 15:14:20 +02:00
parent 1363772535
commit 98151eb8ac
19 changed files with 182 additions and 85 deletions

13
.travis.yml Normal file
View File

@ -0,0 +1,13 @@
dist: trusty
sudo: required
group: deprecated
services:
- docker
before_install:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -o Dpkg::Options::="--force-confnew" -y install docker-ce
- docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}"
install: true
script: hooks/build

View File

@ -14,3 +14,7 @@ This repo is meant to be the starting point for somebody who likes to use docker
## Getting started with zammad-docker-compose
https://docs.zammad.org/en/latest/install-docker-compose.html
## Build Status
[![Build Status](https://travis-ci.org/zammad/zammad-docker-compose.svg?branch=master)](https://travis-ci.org/zammad/zammad-docker-compose)

View File

@ -0,0 +1,30 @@
FROM zammad/zammad-docker-compose:zammad
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
ENV BACKUP_SLEEP 86400
ENV HOLD_DAYS 10
ENV BACKUP_DIR /var/tmp/zammad
LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.name="Zammad" \
org.label-schema.license="AGPL-3.0" \
org.label-schema.description="Docker container for Zammad - Backup container" \
org.label-schema.url="https://zammad.org" \
org.label-schema.vcs-url="https://github.com/zammad/zammad" \
org.label-schema.vcs-type="Git" \
org.label-schema.vendor="Zammad" \
org.label-schema.schema-version="1.2" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
RUN wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" >> /etc/apt/sources.list.d/postgres.list \
&& apt-get update;apt-get -y install postgresql-client
# create entrypoint
COPY containers/zammad-backup/docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
# docker init
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["zammad-backup"]

View File

@ -0,0 +1,32 @@
#!/bin/bash
if [ "$1" = 'zammad-backup' ]; then
# wait for zammad process coming up
until (echo > /dev/tcp/zammad-railsserver/3000) &> /dev/null; do
echo "backup waiting for zammads railsserver to be ready..."
sleep 2
done
while true; do
TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
echo "${TIMESTAMP} - backuping zammad..."
# create backup dis
test -d ${BACKUP_DIR} || mkdir -p ${BACKUP_DIR}
# delete old backups
test -d ${BACKUP_DIR} && find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm {} \;
# tar files
tar -czf ${ZAMMAD_DIR} ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz
#db backup
pg_dump --dbname=postgresql://postgres@zammad-postgresql:5432/zammad_production | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz
# wait until next backup
sleep ${BACKUP_SLEEP}
done
fi

View File

@ -1,4 +1,4 @@
FROM elasticsearch:alpine
FROM docker.elastic.co/elasticsearch/elasticsearch:5.5.0
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
@ -13,4 +13,5 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.schema-version="1.2" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
RUN yes | /usr/share/elasticsearch/bin/elasticsearch-plugin install mapper-attachments
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin remove x-pack --purge \
&& yes | /usr/share/elasticsearch/bin/elasticsearch-plugin install mapper-attachments

View File

@ -1,4 +1,4 @@
FROM postgres:alpine
FROM postgres:9.6-alpine
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
@ -12,4 +12,3 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.vendor="Zammad" \
org.label-schema.schema-version="1.2" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"

View File

@ -2,12 +2,6 @@ FROM zammad/zammad-docker-compose:zammad
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
ENV ZAMMAD_DIR /home/zammad
ENV RAILS_ENV production
ENV RAILS_SERVER puma
ENV GIT_URL https://github.com/zammad/zammad.git
ENV GIT_BRANCH develop
LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.name="Zammad" \
org.label-schema.license="AGPL-3.0" \
@ -23,9 +17,7 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
EXPOSE 3000
# docker init
USER root
COPY containers/zammad-railsserver/docker-entrypoint.sh /
RUN chown zammad:zammad /docker-entrypoint.sh;chmod +x /docker-entrypoint.sh
USER zammad
RUN chown ${ZAMMAD_USER}:${ZAMMAD_USER} /docker-entrypoint.sh;chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["zammad-railsserver"]

View File

@ -11,7 +11,13 @@ if [ "$1" = 'zammad-railsserver' ]; then
echo "railsserver can access postgresql server now..."
cd ${ZAMMAD_DIR}
bundle exec rails r "Setting.set('es_url', 'http://zammad-elasticsearch:9200')"
# update zammad
git pull
gem update bundler
bundle install
# db mirgrate
bundle exec rake db:migrate &> /dev/null
if [ $? != 0 ]; then
@ -19,9 +25,14 @@ if [ "$1" = 'zammad-railsserver' ]; then
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec rake searchindex:rebuild
fi
# es config
bundle exec rails r "Setting.set('es_url', 'http://zammad-elasticsearch:9200')"
bundle exec rake searchindex:rebuild
chown -R ${ZAMMAD_USER}:${ZAMMAD_USER} ${ZAMMAD_DIR}
# delete logs
find ${ZAMMAD_DIR}/log -iname *.log -exec rm {} \;
@ -30,9 +41,9 @@ if [ "$1" = 'zammad-railsserver' ]; then
echo "zammad will be accessable on http://localhost in some seconds"
if [ "${RAILS_SERVER}" == "puma" ]; then
bundle exec puma -b tcp://0.0.0.0:3000 -e ${RAILS_ENV}
exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec puma -b tcp://0.0.0.0:3000 -e ${RAILS_ENV}
elif [ "${RAILS_SERVER}" == "unicorn" ]; then
bundle exec unicorn -p 3000 -c config/unicorn.rb -E ${RAILS_ENV}
exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec unicorn -p 3000 -c config/unicorn.rb -E ${RAILS_ENV}
fi
fi

View File

@ -2,12 +2,6 @@ FROM zammad/zammad-docker-compose:zammad
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
ENV ZAMMAD_DIR /home/zammad
ENV RAILS_ENV production
ENV RAILS_SERVER puma
ENV GIT_URL https://github.com/zammad/zammad.git
ENV GIT_BRANCH develop
LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.name="Zammad" \
org.label-schema.license="AGPL-3.0" \
@ -20,9 +14,7 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
# docker init
USER root
COPY containers/zammad-scheduler/docker-entrypoint.sh /
RUN chown zammad:zammad /docker-entrypoint.sh;chmod +x /docker-entrypoint.sh
USER zammad
RUN chown ${ZAMMAD_USER}:${ZAMMAD_USER} /docker-entrypoint.sh;chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["zammad-scheduler"]

View File

@ -11,5 +11,5 @@ if [ "$1" = 'zammad-scheduler' ]; then
# start scheduler
cd ${ZAMMAD_DIR}
bundle exec script/scheduler.rb run
exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/scheduler.rb run
fi

View File

@ -2,16 +2,10 @@ FROM zammad/zammad-docker-compose:zammad
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
ENV ZAMMAD_DIR /home/zammad
ENV RAILS_ENV production
ENV RAILS_SERVER puma
ENV GIT_URL https://github.com/zammad/zammad.git
ENV GIT_BRANCH develop
LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.name="Zammad" \
org.label-schema.license="AGPL-3.0" \
org.label-schema.description="Docker container for Zammad - Wenbscocket server" \
org.label-schema.description="Docker container for Zammad - Websocket server" \
org.label-schema.url="https://zammad.org" \
org.label-schema.vcs-url="https://github.com/zammad/zammad" \
org.label-schema.vcs-type="Git" \
@ -23,9 +17,7 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
EXPOSE 6042
# docker init
USER root
COPY containers/zammad-websocket/docker-entrypoint.sh /
RUN chown zammad:zammad /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh
USER zammad
RUN chown ${ZAMMAD_USER}:${ZAMMAD_USER} /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["zammad-websocket"]

View File

@ -10,5 +10,5 @@ if [ "$1" = 'zammad-websocket' ]; then
echo "websocket server can access raillsserver now..."
cd ${ZAMMAD_DIR}
bundle exec script/websocket-server.rb -b 0.0.0.0 start
exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/websocket-server.rb -b 0.0.0.0 start
fi

View File

@ -3,10 +3,12 @@ MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
ENV ZAMMAD_DIR /home/zammad
ENV ZAMMAD_USER zammad
ENV RAILS_ENV production
ENV RAILS_SERVER puma
ENV GIT_URL https://github.com/zammad/zammad.git
ENV GIT_BRANCH stable
ENV GOSU_VERSION 1.10
LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.name="Zammad" \
@ -19,16 +21,32 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.schema-version="1.2" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
# install dependencies
RUN apt-get update && apt-get install -y build-essential git-core libpq5 libpq-dev
# install dependencies & GOSU
RUN BUILD_DEPENDENCIES="git build-essential libffi-dev libpq5 libpq-dev" \
GOSU_DEPENDENCIES="ca-certificates wget" \
set -ex \
&& apt-get update && apt-get install -y --force-yes --no-install-recommends $BUILD_DEPENDENCIES $GOSU_DEPENDENCIES && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true
# install zammad
COPY containers/zammad/install-zammad.sh /tmp
RUN chmod +x /tmp/install-zammad.sh;/bin/bash -l -c /tmp/install-zammad.sh
# cleanup
RUN apt-get remove --purge -y build-essential bzip2 git-core libffi-dev libgdbm3 libssl-dev procps zlib1g-dev && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
RUN set -ex \
&& useradd -M -d ${ZAMMAD_DIR} -s /bin/bash ${ZAMMAD_USER} \
&& cd $(dirname ${ZAMMAD_DIR}) \
&& git clone --depth 1 -b "${GIT_BRANCH}" "${GIT_URL}" \
&& cd ${ZAMMAD_DIR} \
&& bundle install --without test development mysql \
&& contrib/packager.io/fetch_locales.rb \
&& sed -e 's#.*adapter: postgresql# adapter: nulldb#g' -e 's#.*username:.*# username: postgres#g' -e 's#.*password:.*# password: \n host: zammad-postgresql\n#g' < config/database.yml.pkgr > config/database.yml \
&& bundle exec rake assets:precompile \
&& sed -e 's#.*adapter: postgresql# adapter: postgresql#g' -e 's#.*username:.*# username: postgres#g' -e 's#.*password:.*# password: \n host: zammad-postgresql\n#g' < config/database.yml.pkgr > config/database.yml \
&& rm -r tmp/cache \
&& chown -R ${ZAMMAD_USER}:${ZAMMAD_USER} ${ZAMMAD_DIR}
WORKDIR $ZAMMAD_DIR

View File

@ -1,32 +0,0 @@
#!/bin/bash
set -ex
# create zammad user
useradd -M -d "${ZAMMAD_DIR}" -s /bin/bash zammad
# git clone zammad
cd $(dirname "${ZAMMAD_DIR}")
git clone --depth 1 -b "${GIT_BRANCH}" "${GIT_URL}"
# install zammad
cd "${ZAMMAD_DIR}"
bundle install --without test development mysql
# fetch locales
contrib/packager.io/fetch_locales.rb
# set nulldb database adapter for assets precompile
sed -e 's#.*adapter: postgresql# adapter: nulldb#g' -e 's#.*username:.*# username: postgres#g' -e 's#.*password:.*# password: \n host: zammad-postgresql\n#g' < config/database.yml.pkgr > config/database.yml
# assets precompile
bundle exec rake assets:precompile
# set postgresql database adapter
sed -e 's#.*adapter: postgresql# adapter: postgresql#g' -e 's#.*username:.*# username: postgres#g' -e 's#.*password:.*# password: \n host: zammad-postgresql\n#g' < config/database.yml.pkgr > config/database.yml
# delete assets precompile cache
rm -r tmp/cache
# set user & group to zammad
chown -R zammad:zammad "${ZAMMAD_DIR}"

View File

@ -1,4 +1,4 @@
version: '3'
version: '3.3'
services:
@ -13,6 +13,19 @@ services:
volumes:
- data-zammad:/home/zammad
zammad-backup:
build:
context: .
dockerfile: containers/zammad-backup/Dockerfile
depends_on:
- zammad
links:
- zammad-postgresql
restart: always
volumes:
- data-zammad:/home/zammad
- backup-zammad:/var/tmp/zammad
zammad-elasticsearch:
build:
context: .
@ -80,5 +93,7 @@ services:
- data-zammad:/home/zammad
volumes:
backup-zammad:
driver: local
data-zammad:
driver: local

View File

@ -1,4 +1,4 @@
version: '3'
version: '3.3'
services:
@ -14,6 +14,19 @@ services:
volumes:
- data-zammad:/home/zammad
zammad-backup:
depends_on:
- zammad
image: zammad/zammad-docker-compose:zammad-backup
labels:
io.rancher.container.pull_image: always
links:
- zammad-postgresql
restart: always
volumes:
- data-zammad:/home/zammad
- backup-zammad:/var/tmp/zammad
zammad-elasticsearch:
image: zammad/zammad-docker-compose:zammad-elasticsearch
labels:
@ -83,5 +96,7 @@ services:
- data-zammad:/home/zammad
volumes:
backup-zammad:
driver: local
data-zammad:
driver: local

View File

@ -3,13 +3,24 @@
# build hook for dockerhubs autobuild feature
#
set -ex
. "hooks/config"
for DOCKER_IMAGE in ${DOCKER_IMAGES}; do
if [ ${TRAVIS} == 'true' ]; then
echo "Build Zammad Docker image ${DOCKER_IMAGE} with version ${TRAVIS_BUILD_NUMBER} for DockerHubs ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${DOCKER_REPOSITORY}:${DOCKER_IMAGE} repo"
docker build --pull --no-cache --build-arg BUILD_DATE=$(date -u +”%Y-%m-%dT%H:%M:%SZ”) -t ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${DOCKER_REPOSITORY}:${DOCKER_IMAGE} -t ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${DOCKER_REPOSITORY}:${DOCKER_IMAGE}-${TRAVIS_BUILD_NUMBER} -f containers/${DOCKER_IMAGE}/Dockerfile .
docker push ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${DOCKER_REPOSITORY}:${DOCKER_IMAGE}
docker push ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${DOCKER_REPOSITORY}:${DOCKER_IMAGE}-${TRAVIS_BUILD_NUMBER}
else
echo "Build Zammad Docker image ${DOCKER_IMAGE} for DockerHubs ${DOCKER_REPO}:${DOCKER_IMAGE} repo"
sleep 10
docker build --pull --no-cache --build-arg BUILD_DATE=$(date -u +”%Y-%m-%dT%H:%M:%SZ”) -t ${DOCKER_REPO}:${DOCKER_IMAGE} -f containers/${DOCKER_IMAGE}/Dockerfile .
docker push ${DOCKER_REPO}:${DOCKER_IMAGE}
docker build --pull --no-cache --build-arg BUILD_DATE=$(date -u +”%Y-%m-%dT%H:%M:%SZ”) -t ${DOCKER_REPO}:${DOCKER_IMAGE} -f containers/${DOCKER_IMAGE}/Dockerfile .
docker push ${DOCKER_REPO}:${DOCKER_IMAGE}
fi
done

View File

@ -3,4 +3,4 @@
# build hooks config
#
DOCKER_IMAGES="zammad zammad-elasticsearch zammad-nginx zammad-postgresql zammad-railsserver zammad-scheduler zammad-websocket"
DOCKER_IMAGES="zammad zammad-backup zammad-elasticsearch zammad-nginx zammad-postgresql zammad-railsserver zammad-scheduler zammad-websocket"

View File

@ -6,6 +6,10 @@ services:
scale: 1
start_on_create: true
zammad-backup:
scale: 1
start_on_create: true
zammad-elasticsearch:
scale: 1
start_on_create: true