link-stack/docker/zammad/Dockerfile

100 lines
3.9 KiB
Text
Raw Normal View History

ARG ZAMMAD_VERSION=6.5.2
2024-05-09 07:42:44 +02:00
FROM node:22-slim AS node
2023-09-27 11:13:19 +02:00
FROM zammad/zammad-docker-compose:${ZAMMAD_VERSION} AS builder
USER root
# Copy Node.js from node image
2023-09-27 11:13:19 +02:00
COPY --from=node /opt /opt
COPY --from=node /usr/local/bin /usr/local/bin
COPY --from=node /usr/local/lib /usr/local/lib
COPY --from=node /usr/lib /usr/lib
2024-06-26 10:58:17 +02:00
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
# Install pnpm for package management
RUN npm install -g pnpm
RUN pnpm --version
ENV ZAMMAD_DIR=/opt/zammad
2024-06-26 10:58:17 +02:00
WORKDIR ${ZAMMAD_DIR}
# Copy addons and installation scripts
2024-06-28 15:37:22 +02:00
RUN mkdir -p /opt/zammad/contrib/link/addons
COPY addons contrib/link/addons
COPY setup.rb contrib/link/setup.rb
COPY install.rb contrib/link/install.rb
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*
# Install Ruby gems (they should already be installed in the base image)
RUN bundle check || bundle install --jobs 8
# Install Node packages
RUN pnpm install --frozen-lockfile
# CRITICAL: Install addons
# This extracts addon files including CoffeeScript, Vue components, TypeScript, and CSS
RUN ruby contrib/link/install.rb
# Fix OpenSearch compatibility: Replace 'flattened' with 'flat_object'
# Elasticsearch uses 'flattened' but OpenSearch uses 'flat_object'
# Without this fix, search index creation fails with:
# [o.o.c.m.MetadataCreateIndexService] failed on parsing mappings on index creation
# org.opensearch.index.mapper.MapperParsingException: Failed to parse mapping [_doc]:
# No handler for type [flattened] declared on field [preferences]
# See: https://github.com/zammad/zammad/blob/bfd2f5befc3aec3fe607a5b6146788ec9af461e4/lib/search_index_backend.rb#L896
RUN sed -i "s/'flattened'/'flat_object'/g" /opt/zammad/lib/search_index_backend.rb
# Precompile assets with addon CoffeeScript files included
# Use ZAMMAD_SAFE_MODE=1 and dummy DATABASE_URL to avoid needing real database
RUN touch db/schema.rb && \
ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile
# Clean up build artifacts
RUN rm -rf tmp/cache node_modules/.cache
2023-09-27 14:34:34 +02:00
ARG EMBEDDED=false
ARG LINK_HOST=http://link:3000
# Add nginx proxy configuration for embedded mode
# Insert location block before the final closing brace
RUN if [ "$EMBEDDED" = "true" ] ; then \
sed -i '$ d' /opt/zammad/contrib/nginx/zammad.conf && \
echo "" >> /opt/zammad/contrib/nginx/zammad.conf && \
echo " location /link {" >> /opt/zammad/contrib/nginx/zammad.conf && \
2025-12-19 15:27:27 +01:00
echo " set \$link_url ${LINK_HOST}; proxy_pass \$link_url;" >> /opt/zammad/contrib/nginx/zammad.conf && \
echo " proxy_set_header Host \$host;" >> /opt/zammad/contrib/nginx/zammad.conf && \
echo " proxy_set_header X-Real-IP \$remote_addr;" >> /opt/zammad/contrib/nginx/zammad.conf && \
echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;" >> /opt/zammad/contrib/nginx/zammad.conf && \
echo " proxy_set_header X-Forwarded-Proto https;" >> /opt/zammad/contrib/nginx/zammad.conf && \
echo " }" >> /opt/zammad/contrib/nginx/zammad.conf && \
echo "}" >> /opt/zammad/contrib/nginx/zammad.conf; \
fi
2025-11-22 10:56:13 +01:00
# Modify entrypoint to install packages and run migrations at runtime
RUN sed -i '/^[[:space:]]*# es config/a\
echo "Installing addon packages..."\n\
bundle exec rails runner /opt/zammad/contrib/link/setup.rb\n\
bundle exec rake zammad:package:migrate\n\
' /docker-entrypoint.sh
FROM zammad/zammad-docker-compose:${ZAMMAD_VERSION} AS runner
USER root
# Install Node.js and npm in runner for asset compilation at runtime
# Using Node from Debian repository for simplicity
RUN apt-get update && \
apt-get install -y --no-install-recommends nodejs npm && \
rm -rf /var/lib/apt/lists/* && \
npm install -g pnpm
USER zammad
2025-11-22 10:56:13 +01:00
COPY --from=builder --chown=zammad:zammad ${ZAMMAD_DIR} ${ZAMMAD_DIR}
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY --from=builder /docker-entrypoint.sh /docker-entrypoint.sh