Skip to content

Instantly share code, notes, and snippets.

@webchi
Created October 3, 2019 13:41
Show Gist options
  • Save webchi/206dfc0a9d6e30430befc4789134d528 to your computer and use it in GitHub Desktop.
Save webchi/206dfc0a9d6e30430befc4789134d528 to your computer and use it in GitHub Desktop.
Rails MariaDB Docker MultiStage
FROM ruby:2.5.5-alpine3.9 as builder
WORKDIR /app
ENV BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_IGNORE_MESSAGES=1 \
BUNDLE_GITHUB_HTTPS=1 \
BUNDLE_FROZEN=1 \
BUNDLE_WITHOUT=development:test
RUN apk update && apk add --no-cache \
build-base mariadb-dev nodejs tzdata
COPY Gemfile* ./
RUN gem install bundler && bundle install -j4 --retry 3
# Add the Rails app
COPY . /app
RUN bundle exec rake assets:precompile RAILS_ENV=production && \
mv ./config/database_docker.yml ./config/database.yml && \
mv ./config/secrets_sample.yml ./config/secrets.yml
FROM ruby:2.5.5-alpine3.9
ENV RAILS_ENV=production
WORKDIR /app
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY --from=builder /app ./
RUN apk update && apk add --no-cache \
mariadb-connector-c tzdata nodejs && \
addgroup -g 1000 -S appuser && \
adduser -u 1000 -S appuser -G appuser && \
chown appuser:appuser /app -R
EXPOSE 3000
USER appuser
CMD ["ruby", "init.rb"]
#!/usr/bin/env ruby
# frozen_string_literal: true
environment = ENV['RAILS_ENV']
exec "bundle exec rails db:migrate && bundle exec puma -e #{environment}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment