diff --git a/.github/docker-image-build.sh b/.github/docker-image-build.sh new file mode 100755 index 0000000..9e8cdad --- /dev/null +++ b/.github/docker-image-build.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# build zammads docker & docker-compose images + +set -o errexit +set -o pipefail + +DOCKER_IMAGES="zammad zammad-elasticsearch zammad-postgresql" +DOCKER_IMAGE_TAG="ci-snapshot" +DOCKER_REGISTRY="index.docker.io" +DOCKER_REPOSITORY="zammad-docker-compose" + +# dockerhub auth +echo "${DOCKER_PASSWORD}" | docker login --username="${DOCKER_USERNAME}" --password-stdin + +# shellcheck disable=SC2153 +for DOCKER_IMAGE in ${DOCKER_IMAGES}; do + echo "Build Zammad Docker image ${DOCKER_IMAGE} with version ${DOCKER_IMAGE_TAG} for DockerHubs ${DOCKER_REGISTRY}/${REPO_USER}/${DOCKER_REPOSITORY} repo" + + docker build --pull --no-cache --build-arg BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" -t "${DOCKER_REGISTRY}/${REPO_USER}/${DOCKER_REPOSITORY}:${DOCKER_IMAGE}-${DOCKER_IMAGE_TAG}" -f "containers/${DOCKER_IMAGE}/Dockerfile" . + docker push "${DOCKER_REGISTRY}/${REPO_USER}/${DOCKER_REPOSITORY}:${DOCKER_IMAGE}-${DOCKER_IMAGE_TAG}" +done diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d6a28eb..6f681f6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,12 +32,30 @@ jobs: with: dockerfile: containers/zammad-postgresql/Dockerfile + build-containers: + needs: + - lint-bash-scripts + - lint-docker-files + runs-on: ubuntu-latest + env: + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + REPO_USER: ${{ secrets.REPO_USER }} + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: build docker containers + run: .github/docker-image-build.sh + test-docker-compose: + needs: build-containers timeout-minutes: 10 runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v1 + - name: use images build by ci + run: sed -i -e 's#VERSION=.*#VERSION=-ci-snapshot#g' < .env - name: pull container images run: docker-compose pull - name: run docker-compose up diff --git a/containers/zammad/docker-entrypoint.sh b/containers/zammad/docker-entrypoint.sh index f133f40..9b9b42f 100755 --- a/containers/zammad/docker-entrypoint.sh +++ b/containers/zammad/docker-entrypoint.sh @@ -49,36 +49,23 @@ if [ "$1" = 'zammad-init' ]; then # configure memcache sed -i -e "s/.*config.cache_store.*file_store.*cache_file_store.*/ config.cache_store = :dalli_store, '${MEMCACHED_HOST}:${MEMCACHED_PORT}'\\n config.session_store = :dalli_store, '${MEMCACHED_HOST}:${MEMCACHED_PORT}'/" config/application.rb - echo "initialising / updating database..." - # check if database exists / update to new version - set +e - bundle exec rake db:migrate &> /dev/null - DB_MIGRATE="$?" + echo "initialising / updating database..." + if ! (bundle exec rails r 'puts User.any?' 2> /dev/null | grep -q true); then + if [ "${POSTGRESQL_DB_CREATE}" == "true" ]; then + bundle exec rake db:create + fi + bundle exec rake db:migrate + bundle exec rake db:seed - # check if database is populated - if [ "${DB_MIGRATE}" == "0" ]; then - bundle exec rails r "Setting.set('es_url', '${ELASTICSEARCH_SCHEMA}://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}')" &> /dev/null - DB_SETTINGS="$?" + # create autowizard.json on first install + if [ -n "${AUTOWIZARD_JSON}" ]; then + echo "${AUTOWIZARD_JSON}" | base64 -d > auto_wizard.json + fi + else + bundle exec rake db:migrate fi - set -e - - # create database if not exists - if [ "${DB_MIGRATE}" != "0" ] && [ "${POSTGRESQL_DB_CREATE}" == "true" ]; then - echo "creating database..." - bundle exec rake db:create - fi - - # populate database and create autowizard.json on first install - if [ "${DB_SETTINGS}" != "0" ]; then - echo "seeding database..." - bundle exec rake db:seed - - if [ -n "${AUTOWIZARD_JSON}" ]; then - echo "${AUTOWIZARD_JSON}" | base64 -d > auto_wizard.json - fi - fi - + # es config echo "changing settings..." bundle exec rails r "Setting.set('es_url', '${ELASTICSEARCH_SCHEMA}://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}')" @@ -116,11 +103,6 @@ fi if [ "$1" = 'zammad-nginx' ]; then check_zammad_ready - # configure nginx - if ! env | grep -q KUBERNETES; then - sed -e "s#server .*:3000#server ${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT}#g" -e "s#server .*:6042#server ${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT}#g" -e "s#server_name .*#server_name ${NGINX_SERVER_NAME};#g" -e 's#/var/log/nginx/zammad.\(access\|error\).log#/dev/stdout#g' < contrib/nginx/zammad.conf > /etc/nginx/sites-enabled/default - fi - echo "starting nginx..." exec /usr/sbin/nginx -g 'daemon off;' diff --git a/docker-compose.yml b/docker-compose.yml index 2cd6f09..0f1183e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: - BACKUP_SLEEP=86400 - HOLD_DAYS=10 - POSTGRESQL_USER=${POSTGRES_USER} - - POSTGRESQL_PASSWORD=${POSTGRES_PASS} + - POSTGRESQL_PASSWORD=${POSTGRES_PASS} image: ${IMAGE_REPO}:zammad-postgresql${VERSION} links: - zammad-postgresql