Skip to content

Instantly share code, notes, and snippets.

@chrism
Last active July 26, 2021 13:19
Show Gist options
  • Save chrism/98e87c8018b3391dfdf73d05813c4b76 to your computer and use it in GitHub Desktop.
Save chrism/98e87c8018b3391dfdf73d05813c4b76 to your computer and use it in GitHub Desktop.
Docker Setup for Rails – 26 July 2021
POSTGRES_USER=postgres
POSTGRES_PASSWORD=ThereNeedsToBeOne
POSTGRES_DB=my_project_development
DATABASE_HOST=database
# Environment variables
/.env/*
/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity
default: &default
adapter: postgresql
encoding: unicode
host: <%= ENV.fetch('DATABASE_HOST') %>
username: <%= ENV.fetch('POSTGRES_USER') %>
password: <%= ENV.fetch('POSTGRES_PASSWORD') %>
database: <%= ENV.fetch('POSTGRES_DB') %>
pool: 5
variables:
statement_timeout: 5000
development:
<<: *default
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: my_project_test
production:
<<: *default
version: '3'
services:
app: &app
build: .
tmpfs:
- /tmp
backend: &backend
<<: *app
stdin_open: true
tty: true
volumes:
- .:/usr/src/app:cached
- rails_cache:/usr/src/app/tmp/cache
- bundle:/usr/local/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=webpack-dev-server
web:
<<: *backend
entrypoint: ./bin/docker-entrypoint.sh
command: bundle exec rails server -b 0.0.0.0
ports:
- "3000:3000"
- "4000:4000"
webpack-dev-server:
<<: *app
command: ./bin/webpack-dev-server
volumes:
- .:/usr/src/app:cached
- bundle:/usr/local/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
ports:
- "3035:3035"
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db_data:/var/lib/postgresql/data
selenium_chrome:
image: selenium/standalone-chrome-debug:3.141.59
ports:
- "5900:5900"
volumes:
db_data:
rails_cache:
bundle:
node_modules:
packs:
#!/bin/sh
set -e
if [ -f tmp/pids/server.pid ]; then
rm tmp/pids/server.pid
fi
exec bundle exec "$@"
FROM ruby:2.7.4
LABEL maintainer="name@email.com"
# Allow use of https
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
apt-transport-https
# Get recent Node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
# Get latest yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | \
tee /etc/apt/sources.list.d/yarn.list
# Install packages
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
nodejs \
yarn
WORKDIR /usr/src/app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment