FROM phusion/passenger-ruby26:1.0.9
LABEL Richard Piacentini <richard.piacentini@nuxos.asia>
ENV REFRESHED_AT 2019-12-03
ENV DEBIAN_FRONTEND=noninteractive

# Avoid Tzdata problem: https://github.com/phusion/passenger-docker/issues/195
RUN apt-get update && apt-get install -y --fix-missing --no-install-recommends tzdata

# Set correct environment variables.
ENV HOME /root
ENV APP_HOME /home/app/rails_app
ENV RVM_GEMSET_PATH=/usr/local/rvm/gems/ruby-2.6.5@pixtech

# Workdir for bundle and bower
WORKDIR ${APP_HOME}

# MySQL Client
#RUN apt-get update && apt-get install -y --fix-missing --no-install-recommends mysql-client

# Change /home/app/webapp owner to user app
RUN chown -R app:app ${APP_HOME}

# Enable ssh and insecure key permanently (development)
#RUN rm -f /etc/service/sshd/down
#RUN /usr/sbin/enable_insecure_key

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Add init scripts
COPY docker/my_init.d/*.sh /etc/my_init.d/
# Ensure premissions to execute and Unix newlines
RUN chmod +x /etc/my_init.d/*.sh && sed -i 's/\r$//' /etc/my_init.d/*.sh

# !! Not work We need to use Bundler 2, add it in RVM global.gems
#COPY docker/rvm/global.gems /usr/local/rvm/gemsets/global.gems
#RUN gem install bundler --default -v 2.0.2

# COPY Gemfile ${APP_HOME}
# COPY Gemfile.lock ${APP_HOME}
# RUN bundle install
# !!** my_init requires root privileges

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]