Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################
- # Stage: Builder
- FROM ruby:2.5-slim as Builder
- # Alpine syntax:
- #RUN apk add --update --no-cache \
- # build-base \
- # git \
- # nodejs-current \
- # postgresql-dev \
- # tzdata
- RUN echo "deb http://ftp.sg.debian.org/debian/ stable main contrib non-free" > /etc/apt/sources.list \
- && echo "deb http://ftp.sg.debian.org/debian/ stable-updates main contrib non-free" >> /etc/apt/sources.list \
- && echo "deb http://security.debian.org/ stable/updates main" >> /etc/apt/sources.list \
- && echo "deb http://ftp.debian.org/debian stretch-backports main" >> /etc/apt/sources.list
- # Debian syntax:
- RUN apt-get update -qq \
- && apt-get install --no-install-recommends --fix-missing -y \
- build-essential \
- curl \
- git \
- gnupg \
- libpq-dev \
- && curl -sL https://deb.nodesource.com/setup_8.x | bash - \
- && apt-get install --no-install-recommends --fix-missing -y \
- nodejs \
- && rm -rf /var/lib/apt/lists/*
- ARG arg_rails_root=/myapp
- ARG arg_rails_env=production
- ENV RAILS_ENV=$arg_rails_env
- RUN mkdir -p $arg_rails_root
- WORKDIR $arg_rails_root
- # bundle gem dependencies
- # next two steps will be cached unless Gemfile or Gemfile.lock changes.
- # --jobs $(nproc) runs bundler in parallel with the amount of CPUs processes.
- COPY Gemfile $arg_rails_root/Gemfile
- COPY Gemfile.lock $arg_rails_root/Gemfile.lock
- RUN bundle config --global frozen 1 \
- && bundle install --jobs $(nproc) --retry 5 --without development test \
- # Remove unneeded files (cached *.gem, *.o, *.c)
- && rm -rf /usr/local/bundle/cache/*.gem \
- && find /usr/local/bundle/gems/ -name "*.c" -delete \
- && find /usr/local/bundle/gems/ -name "*.o" -delete \
- && find /usr/local/bundle/gems/ -name "*.a" -delete
- COPY . $arg_rails_root
- RUN mv config/database.example.yml config/database.yml \
- && mv config/app_config.example.yml config/app_config.yml \
- && mv .env.example .env
- # We compile the assets. When running the rake task, DATABASE_URL is required and we pass a dummy value.
- RUN RAILS_ENV=$arg_rails_env SECRET_KEY_BASE=$(bundle exec rake secret) bundle exec rake DATABASE_URL=postgresql:does_not_exist assets:precompile \
- && rm -rf $arg_rails_root/node_modules \
- $arg_rails_root/tmp/cache \
- $arg_rails_root/app/assets \
- $arg_rails_root/vendor/assets \
- $arg_rails_root/lib/assets \
- $arg_rails_root/spec
- # The tmp folder gets created during asset pre-compilation. We will remove it from the image because it will be mounted
- # as a tmpfs volume. If the folder is already there, the mount does not work properly.
- RUN rm -rf $arg_rails_root/tmp config/database.yml config/app_config.yml .env
- ###############################
- # Stage Final
- FROM ruby:2.5-slim
- # Alpine syntax:
- #RUN apk add --update --no-cache \
- # gettext \
- # postgresql-client \
- # tzdata
- RUN echo "deb http://ftp.sg.debian.org/debian/ stable main contrib non-free" > /etc/apt/sources.list \
- && echo "deb http://ftp.sg.debian.org/debian/ stable-updates main contrib non-free" >> /etc/apt/sources.list \
- && echo "deb http://security.debian.org/ stable/updates main" >> /etc/apt/sources.list \
- && echo "deb http://ftp.debian.org/debian stretch-backports main" >> /etc/apt/sources.list
- # Debian synatx:
- RUN apt-get update -qq \
- && apt-get install --no-install-recommends --fix-missing -y \
- libpq-dev \
- && rm -rf /var/lib/apt/lists/*
- ARG deploy_user=deploy
- ARG arg_rails_root=/myapp
- ARG arg_rails_env=production
- ENV RAILS_ENV=$arg_rails_env
- ENV RAILS_SERVE_STATIC_FILES true
- ENV RAILS_LOG_TO_STDOUT true
- ENV EXECJS_RUNTIME Disabled
- # Create non privileged user, set ownership and change user
- # Alpine syntax:
- #RUN addgroup -g 1000 -S $deploy_user \
- # && adduser -u 1000 -S $deploy_user -G $deploy_user
- # Debian syntax.
- RUN addgroup --gid 1000 $deploy_user \
- && adduser --uid 1000 --gid 1000 --disabled-password --gecos "" $deploy_user
- USER $deploy_user
- # Copy app with gems from former build stage
- COPY --from=Builder /usr/local/bundle/ /usr/local/bundle/
- COPY --from=Builder --chown=deploy:deploy $arg_rails_root $arg_rails_root
- WORKDIR $arg_rails_root
- EXPOSE 3000
- # Save timestamp of image building
- RUN date -u > BUILD_TIME
Add Comment
Please, Sign In to add comment