diff --git a/.ruby-version b/.ruby-version index 8e8299dc..73462a5a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4.2 +2.5.1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7f25d3db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM ruby:2.5.1 +MAINTAINER siong1987@gmail.com + +# Install apt based dependencies required to run Rails as +# well as RubyGems. As the Ruby image itself is based on a +# Debian image, we use apt-get to install those. +RUN apt-get update && apt-get install -y \ + postgresql-client \ + build-essential \ + locales \ + nodejs + +# Use en_US.UTF-8 as our locale +RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment +RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen +RUN echo "LANG=en_US.UTF-8" > /etc/locale.conf +RUN locale-gen en_US.UTF-8 +RUN dpkg-reconfigure --frontend=noninteractive locales + +# Make /app our working directory. +RUN mkdir -p /app +WORKDIR /app + +# Install bundler and make sure that the gems are cached +# at /cache/bundle. +ENV BUNDLE_PATH /cache/bundle +RUN gem install bundler + +# Copy the main application. +COPY . ./ + +# Expose port 3000 to the Docker host, so we can access it +# from the outside. +EXPOSE 3000 + +# Configure an entry point, so we don't need to specify +# "bundle exec" for each of our commands. +ENTRYPOINT ["./bin/docker/run"] diff --git a/bin/docker/run b/bin/docker/run new file mode 100755 index 00000000..2f1c03e9 --- /dev/null +++ b/bin/docker/run @@ -0,0 +1,7 @@ +#!/bin/bash + +if bundle check &> /dev/null; then + bundle exec "$@" +else + exec "$@" +fi diff --git a/bin/docker/start b/bin/docker/start new file mode 100755 index 00000000..801246b3 --- /dev/null +++ b/bin/docker/start @@ -0,0 +1,7 @@ +#!/bin/bash + +bundle check || bundle install --jobs 5 + +yarn check || yarn install + +bundle exec rails server -b 0.0.0.0 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..930fd261 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: "2" +services: + postgres: + image: postgres:10-alpine + volumes: + - .:/app + ports: + - "5432:5432" + app: + build: . + command: ./bin/docker/start + volumes: + - .:/app + volumes_from: + - cache + environment: + - WITHIN_DOCKER=1 + - PGHOST=postgres + - PGUSER=postgres + ports: + - "3000:3000" + depends_on: + - postgres + cache: + image: busybox + volumes: + - /cache