helpyio / helpy

Helpy is a modern, open source helpdesk customer support application. Features include knowledgebase, community discussions and support tickets integrated with email.
http://helpy.io/?source=ghh
MIT License
2.37k stars 499 forks source link

Serving from subdirectory with Passenger - example.com/support #1045

Open jaredvacanti opened 5 years ago

jaredvacanti commented 5 years ago

I have found both of these issues (https://github.com/helpyio/helpy/pull/565 and https://github.com/helpyio/helpy/issues/563) that appear to have resolved how to serve helpy from a subdirectory.

However, when deploying to production and access at example.com/support I am redirected to example.com/en and receive a 404 error. If I manually navigate to example.com/support/en I render the page but get 404s on all-<id>.css, all-<id>.js, application-<id>.js, and logo-<id>.png, so it's not respecting the RAILS_RELATIVE_URL when I precompile the assets. Is there another necessary step to properly serve helpy from a subdirectory?

I have included my Dockerfile (using official passenger+nginx image):

Dockerfile

FROM phusion/passenger-ruby24

RUN apt-get update \
    && apt-get upgrade -y \
    && apt-get install -y tzdata nodejs postgresql-client imagemagick git wget --no-install-recommends \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# how to add environment variables using phusion/baseimage-docker
# otherwise rake tasks will fail (non-absolute HOME)
RUN echo /root > /etc/container_environment/HOME

ENV RUBY_VERSION=2.4.5
ENV HOME /root
ENV DEBIAN_FRONTEND=noninteractive

RUN rm -f /etc/service/nginx/down
RUN bash -lc 'rvm --default use ruby-${RUBY_VERSION}'

ENV HELPY_VERSION=2.2.0
ENV ARCHIVE_URL=https://github.com/helpyio/helpy/archive/${HELPY_VERSION}.tar.gz

RUN mkdir /home/app/webapp
WORKDIR /home/app/webapp

RUN git clone --branch $HELPY_VERSION --depth=1 https://github.com/helpyio/helpy.git . \
  && chown -R app:app ./

# adjust ruby interpreter version
RUN sed -i -e "/ruby '>= 2.2', '< 3.0'/ s/.*/ruby '${RUBY_VERSION}'/" Gemfile

RUN /usr/bin/bundle install

COPY database.yml config/database.yml
RUN /usr/bin/rake secret

RUN mkdir -p /helpy/log/ \
  && touch /helpy/log/production.log \
  && chmod 0664 /helpy/log/production.log \
  && mkdir -p /home/app/webapp/log/ \
  && touch /home/app/webapp/log/production.log \
  && chmod 0664 /home/app/webapp/log/production.log

# configure nginx & init scripts
ADD env.conf /etc/nginx/main.d/env.conf

RUN rm /etc/nginx/sites-enabled/default
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf

RUN mkdir -p /etc/my_init.d
ADD init.sh /etc/my_init.d/init.sh
RUN chmod +x /etc/my_init.d/init.sh

RUN rvm-exec ${RUBY_VERSION} rvm rvmrc warning ignore /home/app/webapp/Gemfile

CMD ["/sbin/my_init"]

init.sh

#!/bin/sh

HOME=/home/app
SECRET_KEY_BASE=$(/usr/bin/rake secret)
sed -i -e "/secret_key_base/ s/.*/  secret_key_base: $SECRET_KEY_BASE/" config/secrets.yml

RAILS_RELATIVE_URL_ROOT=/support/ RAILS_ENV=production rake assets:precompile
chown -R app:app tmp

RAILS_RELATIVE_URL_ROOT=/support/ RAILS_ENV=production rake db:setup

webapp.conf

passenger_log_file /dev/stdout;

server {

    listen 80;
    server_name ptbnl.io;
    root /home/app/webapp/public;

    access_log /dev/stdout;
    error_log /dev/stdout;

    passenger_enabled on;
    passenger_user app;
    # passenger_app_env development;

    # If this is a Ruby app, specify a Ruby version:
    passenger_ruby /usr/bin/ruby2.4;

    # This block has been added.
    location ~ ^/support(/.*|$) {
        alias /home/app/webapp/public$1;  # <-- be sure to point to 'public'!
        passenger_base_uri /support/;
        passenger_app_root /home/app/webapp;
        passenger_document_root /home/app/webapp/public;
        passenger_enabled on;
    }

}

env.conf (necessary to keep environment variables in child processes)

env POSTGRES_DB;
env POSTGRES_USER;
env POSTGRES_PASSWORD;
env POSTGRES_HOST;
env POSTGRES_PORT;
env PGPASSWORD;
env SECRET_KEY_BASE;
env RAILS_RELATIVE_URL_ROOT;
env RAILS_LOG_TO_STDOUT;

I did not include my database.yml, otherwise the example is complete. The application serves but assets aren't served correctly and redirects are relative to the root directory not the subdirectory.

Is there another step to serve from a subdirectory that we can get into the documentation? Thanks for any help.

scott commented 5 years ago

@jaredvacanti were you ever able to get this working?

jaredvacanti commented 5 years ago

I didn't have a chance to come back to this, lthough I recall the issue was with how Rails bundles an application to serve from a subdirectory. This requires configuration in and of itself, and having Helpy respect that configuration.