t_anjan

app.Dockerfile

Aug 16th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.30 KB | None | 0 0
  1. ######################
  2. # Stage: Builder
  3. FROM ruby:2.5-slim as Builder
  4.  
  5. # Alpine syntax:
  6. #RUN apk add --update --no-cache \
  7. #    build-base \
  8. #    git \
  9. #    nodejs-current \
  10. #    postgresql-dev \
  11. #    tzdata
  12.  
  13. RUN echo "deb http://ftp.sg.debian.org/debian/ stable main contrib non-free" > /etc/apt/sources.list \
  14.     && echo "deb http://ftp.sg.debian.org/debian/ stable-updates main contrib non-free" >> /etc/apt/sources.list \
  15.     && echo "deb http://security.debian.org/ stable/updates main" >> /etc/apt/sources.list \
  16.     && echo "deb http://ftp.debian.org/debian stretch-backports main" >> /etc/apt/sources.list
  17.  
  18. # Debian syntax:
  19. RUN apt-get update -qq \
  20.     && apt-get install --no-install-recommends --fix-missing -y \
  21.            build-essential \
  22.            curl \
  23.            git \
  24.            gnupg \
  25.            libpq-dev \
  26.     && curl -sL https://deb.nodesource.com/setup_8.x | bash - \
  27.     && apt-get install --no-install-recommends --fix-missing -y \
  28.            nodejs \
  29.     && rm -rf /var/lib/apt/lists/*
  30.  
  31. ARG arg_rails_root=/myapp
  32. ARG arg_rails_env=production
  33. ENV RAILS_ENV=$arg_rails_env
  34.  
  35. RUN mkdir -p $arg_rails_root
  36. WORKDIR $arg_rails_root
  37.  
  38. # bundle gem dependencies
  39. # next two steps will be cached unless Gemfile or Gemfile.lock changes.
  40. # --jobs $(nproc) runs bundler in parallel with the amount of CPUs processes.
  41. COPY Gemfile $arg_rails_root/Gemfile
  42. COPY Gemfile.lock $arg_rails_root/Gemfile.lock
  43.  
  44. RUN bundle config --global frozen 1 \
  45.     && bundle install --jobs $(nproc) --retry 5 --without development test \
  46.     # Remove unneeded files (cached *.gem, *.o, *.c)
  47.     && rm -rf /usr/local/bundle/cache/*.gem \
  48.     && find /usr/local/bundle/gems/ -name "*.c" -delete \
  49.     && find /usr/local/bundle/gems/ -name "*.o" -delete \
  50.     && find /usr/local/bundle/gems/ -name "*.a" -delete
  51.  
  52. COPY . $arg_rails_root
  53. RUN mv config/database.example.yml config/database.yml \
  54.     && mv config/app_config.example.yml config/app_config.yml \
  55.     && mv .env.example .env
  56.  
  57. # We compile the assets. When running the rake task, DATABASE_URL is required and we pass a dummy value.
  58. RUN RAILS_ENV=$arg_rails_env SECRET_KEY_BASE=$(bundle exec rake secret) bundle exec rake DATABASE_URL=postgresql:does_not_exist assets:precompile \
  59.     && rm -rf $arg_rails_root/node_modules \
  60.        $arg_rails_root/tmp/cache \
  61.        $arg_rails_root/app/assets \
  62.        $arg_rails_root/vendor/assets \
  63.        $arg_rails_root/lib/assets \
  64.        $arg_rails_root/spec
  65.  
  66. # The tmp folder gets created during asset pre-compilation. We will remove it from the image because it will be mounted
  67. # as a tmpfs volume. If the folder is already there, the mount does not work properly.
  68. RUN rm -rf $arg_rails_root/tmp config/database.yml config/app_config.yml .env
  69.  
  70. ###############################
  71. # Stage Final
  72. FROM ruby:2.5-slim
  73.  
  74. # Alpine syntax:
  75. #RUN apk add --update --no-cache \
  76. #    gettext \
  77. #    postgresql-client \
  78. #    tzdata
  79.  
  80. RUN echo "deb http://ftp.sg.debian.org/debian/ stable main contrib non-free" > /etc/apt/sources.list \
  81.     && echo "deb http://ftp.sg.debian.org/debian/ stable-updates main contrib non-free" >> /etc/apt/sources.list \
  82.     && echo "deb http://security.debian.org/ stable/updates main" >> /etc/apt/sources.list \
  83.     && echo "deb http://ftp.debian.org/debian stretch-backports main" >> /etc/apt/sources.list
  84.  
  85. # Debian synatx:
  86. RUN apt-get update -qq \
  87.     && apt-get install --no-install-recommends --fix-missing -y \
  88.            libpq-dev \
  89.     && rm -rf /var/lib/apt/lists/*
  90.  
  91. ARG deploy_user=deploy
  92. ARG arg_rails_root=/myapp
  93. ARG arg_rails_env=production
  94. ENV RAILS_ENV=$arg_rails_env
  95. ENV RAILS_SERVE_STATIC_FILES true
  96. ENV RAILS_LOG_TO_STDOUT true
  97. ENV EXECJS_RUNTIME Disabled
  98.  
  99. # Create non privileged user, set ownership and change user
  100. # Alpine syntax:
  101. #RUN addgroup -g 1000 -S $deploy_user \
  102. #    && adduser -u 1000 -S $deploy_user -G $deploy_user
  103. # Debian syntax.
  104. RUN addgroup --gid 1000 $deploy_user \
  105.     && adduser --uid 1000 --gid 1000 --disabled-password --gecos "" $deploy_user
  106. USER $deploy_user
  107.  
  108. # Copy app with gems from former build stage
  109. COPY --from=Builder /usr/local/bundle/ /usr/local/bundle/
  110. COPY --from=Builder --chown=deploy:deploy $arg_rails_root $arg_rails_root
  111.  
  112. WORKDIR $arg_rails_root
  113.  
  114. EXPOSE 3000
  115.  
  116. # Save timestamp of image building
  117. RUN date -u > BUILD_TIME
Add Comment
Please, Sign In to add comment