setup.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. set -e
  3. apt-get update
  4. apt-get upgrade -y
  5. if [ "$1" = 'builder' ]; then
  6. if [ -z "${COMMIT_SHA}" ]
  7. then
  8. echo "Error: the required build argument \$COMMIT_SHA is missing."
  9. exit 1
  10. fi
  11. # Append build information to the Zammad VERSION.
  12. echo "$(tr -d '\n' < VERSION)-${COMMIT_SHA:0:8}.docker" > VERSION
  13. echo 'Updated build information in VERSION:'
  14. cat VERSION
  15. PACKAGES="build-essential curl git libimlib2-dev libpq-dev libyaml-dev"
  16. elif [ "$1" = 'runner' ]; then
  17. # Add official PostgreSQL apt repository to not depend on Debian's version.
  18. # https://www.postgresql.org/download/linux/debian/
  19. apt-get install -y postgresql-common
  20. /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
  21. PACKAGES="curl libimlib2 libpq5 nginx gnupg postgresql-client-17"
  22. fi
  23. # shellcheck disable=SC2086
  24. apt-get install -y --no-install-recommends ${PACKAGES}
  25. rm -rf /var/lib/apt/lists/*
  26. if [ "$1" = 'builder' ]; then
  27. cd "${ZAMMAD_DIR}"
  28. bundle config set --local without 'test development mysql'
  29. # Don't use the 'deployment' switch here as it would require always using 'bundle exec'
  30. # to invoke commands like rails.
  31. bundle config set --local frozen 'true'
  32. bundle install
  33. touch db/schema.rb
  34. ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile # Don't require Redis or Postgres.
  35. script/build/cleanup.sh
  36. fi
  37. if [ "$1" = 'runner' ]; then
  38. groupadd -g 1000 "${ZAMMAD_USER}"
  39. useradd -M -d "${ZAMMAD_DIR}" -s /bin/bash -u 1000 -g 1000 "${ZAMMAD_USER}"
  40. sed -i -e "s#user www-data;##g" -e 's#/var/log/nginx/\(access\|error\).log#/dev/stdout#g' -e 's#pid /run/nginx.pid;#pid /tmp/nginx.pid;#g' /etc/nginx/nginx.conf
  41. mkdir -p "${ZAMMAD_DIR}" /var/log/nginx
  42. # Pre-create the storage/ and tmp/ folders to avoid mount permission issues (see https://github.com/zammad/zammad/issues/5412).
  43. mkdir -p "${ZAMMAD_DIR}/storage" "${ZAMMAD_DIR}/tmp"
  44. chown -R "${ZAMMAD_USER}":"${ZAMMAD_USER}" /etc/nginx /var/lib/nginx /var/log/nginx "${ZAMMAD_DIR}"
  45. fi