Skip to content

Instantly share code, notes, and snippets.

@wittawasw
Created March 9, 2017 04:39
Show Gist options
  • Save wittawasw/bc97d0b219ec4d437a546eff90d06449 to your computer and use it in GitHub Desktop.
Save wittawasw/bc97d0b219ec4d437a546eff90d06449 to your computer and use it in GitHub Desktop.
FROM alpine:3.4
##################### Base dependencies #################################
RUN apk --no-cache add ruby ruby-irb ruby-json git ruby-bigdecimal ruby-rake \
ruby-io-console ruby-bundler libstdc++ tzdata postgresql-client nodejs \
libxml2 libxslt libgcrypt sqlite-libs pcre curl postgresql bash procps openssh \
&& cp /usr/bin/pg_dump /usr/bin/pg_restore /tmp/ \
&& apk del --purge postgresql \
&& mv /tmp/pg_dump /tmp/pg_restore /usr/bin/ \
&& echo "gem: --no-document" > /etc/gemrc
ENV PASSENGER_VERSION=5.0.30
RUN apk --no-cache add --virtual passenger-dependencies gcc g++ make \
linux-headers curl-dev pcre-dev ruby-dev \
&& gem install -v $PASSENGER_VERSION passenger \
&& echo "#undef LIBC_HAS_BACKTRACE_FUNC" > /usr/include/execinfo.h \
&& passenger-config install-standalone-runtime --auto \
&& passenger-config build-native-support \
&& apk del --purge passenger-dependencies
#########################################################################
##################### Cloning Project ###################################
RUN mkdir /root/.ssh/
RUN chmod -R 700 /root/.ssh
ADD path/to/deployer_rsa /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan giturl.com >> /root/.ssh/known_hosts
RUN git clone git@giturl.com/example/repo /app
WORKDIR /app
#########################################################################
####################### Bundle ##########################################
ENV BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_IGNORE_MESSAGES=1 \
BUNDLE_GITHUB__HTTPS=1 \
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 \
BUNDLE_FROZEN=1 \
BUNDLE_PATH=/app/vendor/bundle \
BUNDLE_BIN=/app/bin \
BUNDLE_GEMFILE=/app/Gemfile \
BUNDLE_WITHOUT=development:benchmark:test
RUN apk --no-cache add --virtual build-dependencies build-base ruby-dev \
curl-dev postgresql-dev libxml2-dev libxslt-dev libgcrypt-dev sqlite-dev libpq \
&& bundle install
#########################################################################
#################### Precompile assets##################################
ENV RAILS_ENV=production PATH=/app/bin:$PATH
RUN rake assets:precompile DATABASE_URL=sqlite3:///tmp/dummy.db SECRET_KEY_BASE=dummy
##########################################################################
#################### Deploy process ######################################
RUN chown -R nobody:nogroup /app
USER nobody
EXPOSE 5000
CMD ["passenger", "start", "-p", "5000", "-e", "production", "--app-type", "rack", "--auto"]
##########################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment