Skip to content

Instantly share code, notes, and snippets.

@hachi8833
Created September 1, 2022 06:25
Show Gist options
  • Save hachi8833/0a9ad178a0859ca150def8f9b1762e13 to your computer and use it in GitHub Desktop.
Save hachi8833/0a9ad178a0859ca150def8f9b1762e13 to your computer and use it in GitHub Desktop.
Dockerfile for
# .dockerdev/Dockerfile
ARG RUBY_VERSION
ARG DISTRO_NAME
FROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME
# Common dependencies
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
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
ARG PG_MAJOR
ARG DISTRO_NAME
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc |\
gpg --dearmor -o /usr/share/keyrings/postgres-archive-keyring.gpg\
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/postgres-archive-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/"\
$DISTRO_NAME-pgdg main $PG_MAJOR | tee /etc/apt/sources.list.d/postgres.list > /dev/null
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 \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& truncate -s 0 /var/log/*log
# Application dependencies
# We use an external Aptfile for this, stay tuned
COPY Aptfile /tmp/Aptfile
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
$(grep -Ev '^\s*#' /tmp/Aptfile | xargs) \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* \
&& 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
# 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
# See https://github.com/evilmartians/terraforming-rails/pull/24 for discussion
ARG BUNDLER_VERSION
RUN gem update --system && \
rm /usr/local/lib/ruby/gems/*/specifications/default/bundler-*.gemspec && \
gem uninstall bundler && \
gem install bundler -v $BUNDLER_VERSION
# Create a directory for the app code
RUN mkdir -p /app
WORKDIR /app
# Document that we're going to expose port 3000
EXPOSE 3000
# Use Bash as the default command
CMD ["/usr/bin/bash"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment