FROM ruby:2.6.8-alpine3.13 AS base

# Author's information
LABEL maintainer="supports.maintenances@ngser.com"

# Install dependances
ENV BUNDLER_VERSION=2.0.2

RUN apk add --update --no-cache \
  binutils-gold \
  build-base \
  curl \
  file \
  g++ \
  gcc \
  git \
  less \
  libstdc++ \
  libffi-dev \
  libc-dev \
  linux-headers \
  libxml2-dev \
  libxslt-dev \
  libgcrypt-dev \
  make \
  netcat-openbsd \
  openssl \
  pkgconfig \
  postgresql-dev \
  python3 \
  openssh \
  nodejs \
  yarn \
  tzdata \
  ssh

# Download application source code into git
RUN mkdir /root/.ssh
ADD ./ssh-key /root/.ssh
RUN chmod 600 -R /root/.ssh/
ADD ./ssh-key /root/.ssh

# Set the working directory of everything to the directory we just made.
WORKDIR /app

# Download app
RUN ssh -V
RUN git clone -b Develop git@gitlab.com:mmgg-guinee/payments.git .
RUN cp entrypoint.sh /usr/bin/entrypoint.sh && chmod +x /usr/bin/entrypoint.sh

# Install and run bundle to get the app ready
RUN gem install bundler
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle config set without 'test' && \ 
    bundle check || bundle install --jobs=3 --retry=3

# Add a script to be executed every time the container starts.
ENTRYPOINT ["sh", "entrypoint.sh"]

# Expose port 3000 on the container
EXPOSE 3000

# Clear cache (optional)
# RUN bundle exec rake tmp:clear

# Run the application on port 3000
CMD ["bundle", "exec", "rails", "s"]
#CMD ["bundle", "exec", "puma"]
