Skip to content

Instantly share code, notes, and snippets.

@leeuwd
Created September 12, 2017 09:46
Show Gist options
  • Save leeuwd/7cd862d8a2b5d370a662b115e06f03b6 to your computer and use it in GitHub Desktop.
Save leeuwd/7cd862d8a2b5d370a662b115e06f03b6 to your computer and use it in GitHub Desktop.
Travelteq Rails MySQL Docker template
generate(:scaffold, "post", "title:string", "body:text")
route "root to: 'posts#index'"
file 'config/database.yml', <<-CODE
default: &default
adapter: mysql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: db
username: <%= ENV.fetch('MYSQL_USER') %>
password: <%= ENV.fetch('MYSQL_PASSWORD') %>
development:
<<: *default
database: travelteq_development
test:
<<: *default
database: travelteq_test
production:
<<: *default
database: travelteq_production
CODE
file 'Dockerfile', <<-CODE
FROM ruby:2.4.1-stretch
# Set local timezone
RUN apk add --update tzdata && \
cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime && \
echo "Europe/Amsterdam" > /etc/timezone
# Install your app's runtime dependencies in the container
RUN apk add --update --virtual runtime-deps mysql-10.1.26-r0 nodejs libffi-dev readline sqlite
# Bundle into the temp directory
WORKDIR /tmp
ADD Gemfile* ./
RUN apk add --virtual build-deps build-base openssl-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 \
RACK_ENV=production
# 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