Skip to content

Instantly share code, notes, and snippets.

@cblunt
Last active April 1, 2020 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save cblunt/1d3b0c1829875e3889d50c27eb233ebe to your computer and use it in GitHub Desktop.
Save cblunt/1d3b0c1829875e3889d50c27eb233ebe to your computer and use it in GitHub Desktop.
A simple Rails application configured for PostgreSQL and Docker
route "root to: 'posts#index'"
generate :scaffold, 'post', 'title:string', 'body:text'
file 'config/database.yml', <<-CODE
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: db
username: <%= ENV.fetch('POSTGRES_USER') { 'postgres' } %>
password: <%= ENV.fetch('POSTGRES_PASSWORD') { 'secret123' } %>
development:
<<: *default
database: my-app_development
test:
<<: *default
database: my-app_test
production:
<<: *default
database: my-app_production
CODE
file 'Dockerfile', <<-CODE
FROM ruby:2.6-alpine
# Set local timezone
RUN apk add --update tzdata && cp /usr/share/zoneinfo/Europe/London /etc/localtime && echo "Europe/London" > /etc/timezone
# Install your app's runtime dependencies in the container
RUN apk add --update --virtual runtime-deps postgresql-client nodejs libffi-dev readline sqlite xz-libs
# Install Yarn
ENV PATH=/root/.yarn/bin:$PATH
RUN apk add --virtual build-yarn curl && \
touch ~/.bashrc && \
curl -o- -L https://yarnpkg.com/install.sh | sh && \
apk del build-yarn
# Bundle into the temp directory
WORKDIR /tmp
ADD Gemfile* ./
RUN apk add --virtual build-deps build-base postgresql-dev libc-dev linux-headers libxml2-dev libxslt-dev readline-dev && bundle install --jobs=2 && apk del build-deps
# Copy the app's code into the container
ENV APP_HOME /app
COPY . $APP_HOME
WORKDIR $APP_HOME
# Configure production environment variables
ENV RAILS_ENV=production
ENV RACK_ENV=production
# Precompile assets into the container
RUN bin/rails webpacker:install
RUN bin/rails assets:precompile
# Expose port 3000 from the container
EXPOSE 3000
# Run puma server by default
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment