
FROM alpine:3.16

WORKDIR /app

RUN apk add --no-cache --update \
    bash \
    git \
    wget \
    curl \
    vim \
    perl-dev \
    build-base \
    readline-dev \
    openssl-dev \
    zlib-dev \
    openssh-client \
&& rm -rf /var/cache/apk/*

# rbenv
ENV PATH /usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH
ENV RBENV_ROOT /usr/local/rbenv
ENV RUBY_VERSION 2.6.10
ENV CONFIGURE_OPTS --disable-install-doc

RUN apk add --no-cache --update \
    linux-headers \
    imagemagick-dev \    
    libffi-dev \
    && rm -rf /var/cache/apk/*

RUN git clone --depth 1 https://github.com/rbenv/rbenv.git ${RBENV_ROOT}
RUN git clone --depth 1 https://github.com/rbenv/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build
RUN git clone --depth 1 https://github.com/jf/rbenv-gemset.git ${RBENV_ROOT}/plugins/rbenv-gemset
RUN ${RBENV_ROOT}/plugins/ruby-build/install.sh

RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh 

RUN rbenv install $RUBY_VERSION \
    &&  rbenv global $RUBY_VERSION

# # Add files
COPY Gemfile .
COPY Gemfile.lock .
COPY docker-entrypoint.sh .

# Update gem and install bundler
RUN gem update --system 2.5.2 \
    && gem install bundler:2.2.16

# Install and update dependencies
RUN bundle install \
    && bundle update capistrano \
    && bundle update --bundler

RUN mkdir -p ~/.ssh

# CMD
CMD ["/bin/bash", "/app/docker-entrypoint.sh", "&"]