Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kimihito
Last active December 24, 2022 19:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kimihito/b2e98307b86a2f92eb47e590ae0de939 to your computer and use it in GitHub Desktop.
Save kimihito/b2e98307b86a2f92eb47e590ae0de939 to your computer and use it in GitHub Desktop.
Using Fullstaq Ruby on Heroku
{
"stack": "container",
"formation": {
"web": {
"quantity": 1,
"size": "free"
}
},
"addons": [{
"plan": "heroku-postgresql:hobby-dev",
"as": "DATABASE"
},
{
"plan": "heroku-redis:hobby-dev",
"as": "REDIS"
}
],
"env": {
"SECRET_KEY_BASE": {
"required": true,
"generator": "secret"
}
}
}
# base dockerfile from https://github.com/evilmartians/terraforming-rails/blob/567566348a6a9893e10b9f857f1e5e58ba581b41/examples/dockerdev/.dockerdev/Dockerfile
# See explanation below
ARG RUBY_VERSION
FROM quay.io/evl.ms/fullstaq-ruby:$RUBY_VERSION-jemalloc-buster-slim as builder
ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG YARN_VERSION
ARG SECRET_KEY_BASE
# Common dependencies
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
zlib1g-dev \
liblzma-dev \
gnupg2 \
curl \
less \
git \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& truncate -s 0 /var/log/*log
# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
# Add NodeJS to sources list
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
# Add Yarn to the sources list
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list
# Application dependencies
# We use an external Aptfile for that, stay tuned
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
libpq-dev \
postgresql-client-$PG_MAJOR \
nodejs \
yarn=$YARN_VERSION-1 \
$(cat /tmp/Aptfile | xargs) &&\
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
truncate -s 0 /var/log/*log
# Configure bundler
ENV LANG=C.UTF-8 \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3
ENV RAILS_ENV=production
ENV NODE_ENV=production
ENV SECRET_KEY_BASE=$SECRET_KEY_BASE
# Uncomment this line if you store Bundler settings in the project's root
# ENV BUNDLE_APP_CONFIG=.bundle
# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec`
# ENV PATH /app/bin:$PATH
# Upgrade RubyGems and install required Bundler version
RUN gem update --system && \
gem install bundler:$BUNDLER_VERSION
# Create a directory for the app code
RUN mkdir -p /app
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install --without development test
COPY . .
RUN bundle exec rails assets:precompile \
&& yarn cache clean \
&& rm -rf node_modules tmp/cache
CMD [ "bundle", "exec", "puma", "-C", "config/puma.rb" ]
setup:
addons:
- plan: heroku-postgresql
as: DATABASE
- plan: heroku-redis
as: REDIS
build:
docker:
web: Dockerfile.prod
config:
RUBY_VERSION: '2.7.1'
PG_MAJOR: '12'
NODE_MAJOR: '12'
YARN_VERSION: '1.22.4'
BUNDLER_VERSION: '2.1.4'
SECRET_KEY_BASE: $SECRET_KEY_BASE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment