Guest User

Untitled

a guest
Jun 20th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. ARG RUBY_VER=2.5.1
  2. ARG APP_PATH=/usr/src/app
  3. ARG ENVIRONMENT=production
  4.  
  5. ##################
  6. # Stage: Builder
  7. ##################
  8. FROM ruby:${RUBY_VER}-alpine as builder
  9.  
  10. # Set working dir
  11. ARG APP_PATH
  12. RUN mkdir $APP_PATH
  13. WORKDIR $APP_PATH
  14.  
  15. # Set environment
  16. ARG ENVIRONMENT
  17. ENV RAILS_ENV $ENVIRONMENT
  18. ENV NODE_ENV $ENVIRONMENT
  19.  
  20. # Install build dependencies
  21. RUN apk --update add --no-cache \
  22. build-base \
  23. # For nokogiri
  24. libxml2-dev libxslt-dev \
  25. # For uglifier & webpacker
  26. nodejs \
  27. # For postgresql
  28. postgresql-dev \
  29. # For tzinfo-data
  30. tzdata \
  31. # For webpacker
  32. yarn
  33.  
  34. # Bundle gems
  35. COPY Gemfile Gemfile.lock $APP_PATH/
  36. RUN if [[ "$RAILS_ENV" == "production" ]]; \
  37. then bundle install --jobs "$(getconf _NPROCESSORS_ONLN)" --retry 5 --without development test; \
  38. else bundle install --jobs "$(getconf _NPROCESSORS_ONLN)" --retry 5; \
  39. fi
  40.  
  41. # Install Javascript packages
  42. COPY package.json yarn.lock $APP_PATH/
  43. RUN if [[ "$NODE_ENV" == "production" ]]; \
  44. then yarn install --frozen-lockfile --production; \
  45. else yarn install --frozen-lockfile; \
  46. fi \
  47. && yarn cache clean
  48.  
  49. COPY . $APP_PATH/
  50.  
  51. # Precompile assets
  52. RUN if [[ "$RAILS_ENV" == "production" ]]; \
  53. then bundle exec rails assets:precompile; \
  54. fi
  55.  
  56. # Cleanup
  57. RUN rm -rf node_modules tmp/* log/* /usr/local/bundle/cache/*.gem \
  58. && find /usr/local/bundle/gems/ -name "*.c" -delete \
  59. && find /usr/local/bundle/gems/ -name "*.o" -delete
  60.  
  61. ##################
  62. # Stage: Final app
  63. ##################
  64. FROM ruby:${RUBY_VER}-alpine
  65.  
  66. ARG APP_PATH
  67. ENV PATH $APP_PATH/bin:$PATH
  68. ENV RAILS_LOG_TO_STDOUT true
  69.  
  70. # Set working dir
  71. RUN mkdir $APP_PATH
  72. WORKDIR $APP_PATH
  73.  
  74. # Install runtime dependencies
  75. RUN apk --update add --no-cache \
  76. # For Active Storage
  77. imagemagick \
  78. # For uglifier & webpacker
  79. nodejs \
  80. # For postgresql
  81. postgresql-dev \
  82. # For tzinfo-data
  83. tzdata
  84.  
  85. # Set environment
  86. ARG ENVIRONMENT
  87. ENV RAILS_ENV $ENVIRONMENT
  88. ENV NODE_ENV $ENVIRONMENT
  89.  
  90. COPY --from=builder $APP_PATH $APP_PATH
  91. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  92.  
  93. # Tighten security
  94. RUN chown -R nobody:nogroup $APP_PATH
  95. USER nobody
  96.  
  97. CMD ["bundle", "exec", "rails", "s", "-p", "3000", "-b", "0.0.0.0"]
Add Comment
Please, Sign In to add comment