FROM openbuildservice/base

# FIXME: https://bugzilla.opensuse.org/show_bug.cgi?id=957818
RUN rm -rf /var/cache/zypp/*

RUN /root/bin/docker-bootstrap.sh frontend

# Install other requirements
RUN npm install -g jshint

ADD src/api/Gemfile /obs/src/api/Gemfile
ADD src/api/Gemfile.lock /obs/src/api/Gemfile.lock
RUN chown -R frontend /obs/src/api

# Now do the rest as the user with the same ID as the user who
# builds this container
USER frontend
WORKDIR /obs/src/api

# Ensure there are ruby, gem and irb commands without ruby suffix
RUN for i in ruby gem irb; do ln -s /usr/bin/$i.ruby2.5 ~/bin/$i; done

# Install our bundle
# FIXME: Retrying bundler if it fails is a workaround for https://github.com/moby/moby/issues/783
#        which seems to happen on openSUSE (< Tumbleweed 20171001)...
RUN export NOKOGIRI_USE_SYSTEM_LIBRARIES=1; bundle install --jobs=3 --retry=3 || bundle install --jobs=3 --retry=3

# Switch to root again so we don't block changing our frontend user id...
USER root

# Run our command
CMD ["/bin/bash", "-l"]
