Created
October 3, 2019 13:41
-
-
Save webchi/206dfc0a9d6e30430befc4789134d528 to your computer and use it in GitHub Desktop.
Rails MariaDB Docker MultiStage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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