Skip to content

Instantly share code, notes, and snippets.

@zealot128
Last active January 18, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/dd24aee7b23f39f567b8dac5e51339b0 to your computer and use it in GitHub Desktop.
Save zealot128/dd24aee7b23f39f567b8dac5e51339b0 to your computer and use it in GitHub Desktop.
Basis Docker setup for Rails app (Postgres)
version: '3.4'
services:
app:
restart: always
build:
context: .
dockerfile: ./Dockerfile
args:
- SECRET_KEY_BASE
- DATABASE_URL
depends_on:
- postgres
volumes:
- attachments:/app/app/uploads:delegated
- ./seed:/app/seed
environment:
RAILS_ENV: production
DATABASE_URL: "postgres://postgres:postgres@postgres:5432/app"
SECRET_KEY_BASE: xxxxxxxxxxxx
RAILS_LOG_TO_STDOUT: 1
RAILS_SERVE_STATIC_FILES: 1
command: /bin/sh -c "rm -f ./tmp/pids/server.pid && rails server -b 0.0.0.0"
logging:
driver: "json-file"
options:
max-size: "100k"
max-file: "20"
postgres:
image: postgres:12.1
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- db_data:/var/lib/postgresql/data
restart: on-failure
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
logging:
driver: none
volumes:
db_data:
attachments:
FROM ruby:2.7.1-alpine
ENV BUNDLER_VERSION=2.0.2
RUN apk add --update --no-cache \
binutils-gold \
build-base \
curl \
file \
g++ \
gcc \
git \
less \
libstdc++ \
libffi-dev \
libc-dev \
linux-headers \
postgresql-client \
libxml2-dev \
libxml2-dev \
imagemagick \
libxslt-dev \
libgcrypt-dev \
make \
netcat-openbsd \
nodejs \
openssl \
pkgconfig \
postgresql-dev \
tzdata \
yarn
RUN gem install -N bundler -v 2.1.2
WORKDIR /app
COPY entrypoint.sh /app/entrypoint.sh
WORKDIR /app/app
COPY app/Gemfile app/Gemfile.lock ./
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
COPY app/package.json app/yarn.lock ./
RUN yarn install --check-files
COPY app/. ./
RUN bundle add activerecord-nulldb-adapter && rm config/credentials.yml.enc
# copy database.yml with credentials OR config via DB_URL
RUN cp config/database.yml.example config/database.yml
RUN DB_ADAPTER=nulldb bundle exec rake assets:precompile RAILS_ENV=production SECRET_KEY_BASE=foobar
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment