LayerCI Ruby on Rails Example

#This is an example LayerCI configuration!
FROM vm/ubuntu:18.04

# To note: Layerfiles create entire VMs, *not* containers!

# Install postgresql and run it in the background
RUN apt-get update && \
    apt-get install postgresql postgresql-contrib libpq-dev

# install rails dependencies
RUN curl -fSsL https://deb.nodesource.com/setup_12.x | bash && \
    curl -fSsL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
    echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list && \
    apt-get update && \
    apt-get install git-core zlib1g-dev build-essential libssl-dev \
    libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \
    libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv
ENV PATH=$HOME/.rbenv/bin:$PATH
RUN echo 'eval "$(rbenv init -)"' >> ~/.bashrc

RUN git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
RUN echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc

RUN rbenv install 2.7.1
ENV PATH=$HOME/.rbenv/versions/2.7.1/bin:$PATH


RUN gem install pg rails

# Create a rails template project
RUN rails new myapp --database=postgresql
WORKDIR myapp
ENV RAILS_ENV=development

RUN sudo -u postgres createuser -s -i -d -r -l -w root
RUN sudo -u postgres -H -- psql -t -c "CREATE DATABASE mydb;"
RUN sudo -u postgres -H -- psql -c "ALTER ROLE root WITH PASSWORD 'password';"

# set up database
RUN echo -e 'development:\n\
  adapter: postgresql\n\
  encoder: unicode\n\
  database: mydb\n\
  username: root\n\
  password: password\n' > config/database.yml

# run migrations
RUN rake db:migrate
RUN rake db:setup

# Start the server
RUN BACKGROUND rails server --binding 0.0.0.0
EXPOSE WEBSITE localhost:3000
Try this example live