diff --git a/.gitignore b/.gitignore index 902de7a..d075455 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,6 @@ yarn-debug.log* # Ignore uploaded files in development /storage/* !/storage/.keep + +# Ignore IJ IDE directory +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6cf98a2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM ruby:2.5 +RUN apt-get update -qq && apt-get install -y nodejs postgresql-client +RUN mkdir /myapp +WORKDIR /myapp +COPY Gemfile /myapp/Gemfile +COPY Gemfile.lock /myapp/Gemfile.lock +RUN bundle install +COPY . /myapp + +# Add a script to be executed every time the container starts. +COPY entrypoint.sh /usr/bin/ + RUN chmod +x /usr/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] +EXPOSE 3000 + +# Start the main process. +CMD ["rails", "server", "-b", "0.0.0.0"] \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..be8f5a7 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'rails', '~>6' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..5a8fcd9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,10 @@ +GEM + specs: + +PLATFORMS + x64-mingw32 + +DEPENDENCIES + +BUNDLED WITH + 1.17.2 diff --git a/README.md b/README.md index 5bf61e3..247fe68 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # docker-compose-rails-skel -Skeleton for the Docker ["Compose and Rails"](https://docs.docker.com/compose/rails/) tutorial +This project is a skeleton for a rails app following ["Quickstart: Compose and Rails"](https://docs.docker.com/compose/rails/) + +From this sketch you can run the following commands to jump-start your app: +``` +docker-compose run web rails new . --force --no-deps --database=postgresql +sudo chown -R $USER:$USER . # Linux only +docker-compose build +``` +Now you should continue from ["Connect the database"](https://docs.docker.com/compose/rails/#connect-the-database) section of the tutorial diff --git a/docker-compose-rails-skel.iml b/docker-compose-rails-skel.iml new file mode 100644 index 0000000..af03825 --- /dev/null +++ b/docker-compose-rails-skel.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b31969c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3' +services: + db: + image: postgres + volumes: + - ./tmp/db:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: password + web: + build: . + command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" + volumes: + - .:/myapp + ports: + - "3000:3000" + depends_on: + - db \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..0721cd7 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Remove a potentially pre-existing server.pid for Rails. +rm -f /myapp/tmp/pids/server.pid + +# Then exec the container's main process (what's set as CMD in the Dockerfile). +exec "$@" \ No newline at end of file