link-stack/docker/zammad/Dockerfile
2026-02-12 12:01:56 +01:00

103 lines
4.1 KiB
Docker

ARG ZAMMAD_VERSION=6.5.2
FROM node:22-slim AS node
FROM zammad/zammad-docker-compose:${ZAMMAD_VERSION} AS builder
USER root
# Copy Node.js from node image
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
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
WORKDIR ${ZAMMAD_DIR}
# Copy addons and installation scripts
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
# Rebuild Vite frontend to include addon Vue components
# The base image has pre-built Vite assets, but addon Vue files need to be compiled
RUN RAILS_ENV=production bundle exec vite build --clobber
# 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
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 && \
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
# 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
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