use multistage docker image

This commit is contained in:
André Bauer 2019-02-15 16:11:49 +01:00
parent 151371c39a
commit 5aa5151c88
8 changed files with 88 additions and 40 deletions

2
.env
View File

@ -1,5 +1,5 @@
# don't forget to add the minus before the version
# example: VERSION=-2.1.0-13
# example: VERSION=-2.9.0-1
IMAGE_REPO=zammad/zammad-docker-compose
VERSION=
RESTART=always

View File

@ -9,5 +9,5 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
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.schema-version="2.9.0" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"

View File

@ -10,7 +10,7 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
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.schema-version="2.9.0" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin remove x-pack --purge && \

View File

@ -11,7 +11,7 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
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.schema-version="2.9.0" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
# docker init

View File

@ -15,7 +15,7 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
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.schema-version="2.9.0" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
# copy backup script

View File

@ -1,18 +1,33 @@
FROM ruby:2.4.4-slim
FROM ruby:2.4.4-slim AS builder
# note: zammad is currently incompatible to alpine because of:
# https://github.com/docker-library/ruby/issues/113
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
ARG DEBIAN_FRONTEND=noninteractive
ENV ZAMMAD_DIR /opt/zammad
ENV ZAMMAD_USER zammad
ENV RAILS_ENV production
ENV RAILS_SERVER puma
ENV PROJECT_URL https://github.com/zammad/zammad
ENV GIT_URL ${PROJECT_URL}.git
ENV GIT_BRANCH stable
ENV ZAMMAD_TMP_DIR /tmp/zammad-${GIT_BRANCH}
ENV TAR_GZ_URL ${PROJECT_URL}/archive/${GIT_BRANCH}.tar.gz
ENV GIT_URL ${PROJECT_URL}.git
ENV GOSU_VERSION 1.11
ENV PROJECT_URL https://github.com/zammad/zammad
ENV RAILS_ENV production
ENV TAR_GZ_URL ${PROJECT_URL}/archive/${GIT_BRANCH}.tar.gz
ENV ZAMMAD_DIR /opt/zammad
ENV ZAMMAD_READY_FILE ${ZAMMAD_DIR}/tmp/zammad.ready
ENV ZAMMAD_TMP_DIR /tmp/zammad-${GIT_BRANCH}
ENV ZAMMAD_USER zammad
# install zammad
COPY containers/zammad/setup.sh /tmp
RUN chmod +x /tmp/setup.sh; \
/tmp/setup.sh install
FROM ruby:2.4.4-slim
MAINTAINER Zammad <info@zammad.org>
ARG BUILD_DATE
ARG DEBIAN_FRONTEND=noninteractive
LABEL org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.name="Zammad" \
@ -22,33 +37,23 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \
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.schema-version="2.9.0" \
org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up"
# install dependencies & gosu
RUN BUILD_DEPENDENCIES="build-essential ca-certificates curl dirmngr git gnupg2 libffi-dev libpq5 libpq-dev nginx rsync" && \
set -ex && \
apt-get update && apt-get install -y --no-install-recommends ${BUILD_DEPENDENCIES} && rm -rf /var/lib/apt/lists/* && \
curl -s -J -L -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-$(dpkg --print-architecture)" && \
chmod +x /usr/local/bin/gosu && \
gosu nobody true
ENV GIT_BRANCH stable
ENV RAILS_ENV production
ENV ZAMMAD_DIR /opt/zammad
ENV ZAMMAD_READY_FILE ${ZAMMAD_DIR}/tmp/zammad.ready
ENV ZAMMAD_TMP_DIR /tmp/zammad-${GIT_BRANCH}
ENV ZAMMAD_USER zammad
# install zammad
RUN groupadd -g 1000 ${ZAMMAD_USER} && \
useradd -M -d ${ZAMMAD_DIR} -s /bin/bash -u 1000 -g 1000 ${ZAMMAD_USER} && \
cd $(dirname ${ZAMMAD_TMP_DIR}) && \
curl -s -J -L -O "${TAR_GZ_URL}" && \
tar -xzf zammad-${GIT_BRANCH}.tar.gz && \
rm zammad-${GIT_BRANCH}.tar.gz && \
cd ${ZAMMAD_TMP_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' < contrib/packager.io/database.yml.pkgr > config/database.yml && \
sed -i '/# Use a different logger for distributed setups./a \ \ config.logger = Logger.new(STDOUT)' config/environments/production.rb && \
sed -i 's/.*scheduler_\(err\|out\).log.*//g' script/scheduler.rb && \
bundle exec rake assets:precompile && \
rm -r tmp/cache && \
chown -R ${ZAMMAD_USER}:${ZAMMAD_USER} ${ZAMMAD_TMP_DIR}
COPY containers/zammad/setup.sh /tmp
RUN chmod +x /tmp/setup.sh; \
/tmp/setup.sh run
COPY --from=builder ${ZAMMAD_TMP_DIR} ${ZAMMAD_TMP_DIR}
COPY --from=builder /usr/local/bin/gosu /usr/local/bin/gosu
COPY --from=builder /usr/local/bundle /usr/local/bundle
# docker init
COPY containers/zammad/docker-entrypoint.sh /

4
containers/zammad/docker-entrypoint.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
@ -129,10 +129,12 @@ if [ "$1" = 'zammad-railsserver' ]; then
echo "starting railsserver..."
#shellcheck disable=SC2101
exec gosu "${ZAMMAD_USER}":"${ZAMMAD_USER}" bundle exec rails server puma -b [::] -p "${ZAMMAD_RAILSSERVER_PORT}" -e "${RAILS_ENV}"
fi
# zammad-scheduler
if [ "$1" = 'zammad-scheduler' ]; then
check_zammad_ready

View File

@ -0,0 +1,41 @@
#!/usr/bin/env sh
set -e
# install dependencies
if [ "$1" = 'install' ]; then
PACKAGES="build-essential curl git libimlib2-dev libpq-dev"
elif [ "$1" = 'run' ]; then
PACKAGES="curl libimlib2 libimlib2-dev libpq5 nginx rsync"
fi
apt-get update
apt-get upgrade -y
apt-get install -y --no-install-recommends ${PACKAGES}
rm -rf /var/lib/apt/lists/*
# install gosu
if [ "$1" = 'install' ]; then
curl -s -J -L -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-$(dpkg --print-architecture)"
chmod +x /usr/local/bin/gosu
gosu nobody true
fi
# install zammad
groupadd -g 1000 "${ZAMMAD_USER}"
useradd -M -d "${ZAMMAD_DIR}" -s /bin/bash -u 1000 -g 1000 "${ZAMMAD_USER}"
if [ "$1" = 'install' ]; then
cd "$(dirname "${ZAMMAD_TMP_DIR}")"
curl -s -J -L -O "${TAR_GZ_URL}"
tar -xzf zammad-"${GIT_BRANCH}".tar.gz
rm zammad-"${GIT_BRANCH}".tar.gz
cd "${ZAMMAD_TMP_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' < contrib/packager.io/database.yml.pkgr > config/database.yml
sed -i '/# Use a different logger for distributed setups./a \ \ config.logger = Logger.new(STDOUT)' config/environments/production.rb
sed -i 's/.*scheduler_\(err\|out\).log.*//g' script/scheduler.rb
bundle exec rake assets:precompile
rm -r tmp/cache
chown -R "${ZAMMAD_USER}":"${ZAMMAD_USER}" "${ZAMMAD_TMP_DIR}"
fi