|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +ARG RUBY_VERSION |
| 4 | +ARG DISTRO_NAME=buster |
| 5 | + |
| 6 | +FROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME |
| 7 | + |
| 8 | +ARG DISTRO_NAME |
| 9 | + |
| 10 | +# Common dependencies |
| 11 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 12 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 13 | + --mount=type=tmpfs,target=/var/log \ |
| 14 | + rm -f /etc/apt/apt.conf.d/docker-clean; \ |
| 15 | + echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache; \ |
| 16 | + apt-get update -qq \ |
| 17 | + && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ |
| 18 | + build-essential \ |
| 19 | + gnupg2 \ |
| 20 | + curl \ |
| 21 | + less \ |
| 22 | + git |
| 23 | + |
| 24 | +# Install PostgreSQL dependencies |
| 25 | +ARG PG_MAJOR |
| 26 | +RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | \ |
| 27 | + gpg --dearmor -o /usr/share/keyrings/postgres-archive-keyring.gpg \ |
| 28 | + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/postgres-archive-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/" \ |
| 29 | + $DISTRO_NAME-pgdg main $PG_MAJOR | tee /etc/apt/sources.list.d/postgres.list > /dev/null |
| 30 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 31 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 32 | + --mount=type=tmpfs,target=/var/log \ |
| 33 | + apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \ |
| 34 | + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ |
| 35 | + libpq-dev \ |
| 36 | + postgresql-client-$PG_MAJOR |
| 37 | + |
| 38 | +# Install NodeJS and Yarn |
| 39 | +ARG NODE_MAJOR |
| 40 | +ARG YARN_VERSION=latest |
| 41 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 42 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 43 | + --mount=type=tmpfs,target=/var/log \ |
| 44 | + apt-get update && \ |
| 45 | + apt-get install -y curl software-properties-common && \ |
| 46 | + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \ |
| 47 | + echo "deb https://deb.nodesource.com/node_${NODE_MAJOR}.x $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/nodesource.list && \ |
| 48 | + apt-get update && \ |
| 49 | + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends nodejs |
| 50 | +RUN npm install -g yarn@$YARN_VERSION |
| 51 | + |
| 52 | +# Application dependencies |
| 53 | +# We use an external Aptfile for this, stay tuned |
| 54 | +COPY Aptfile /tmp/Aptfile |
| 55 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 56 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 57 | + --mount=type=tmpfs,target=/var/log \ |
| 58 | + apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \ |
| 59 | + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ |
| 60 | + $(grep -Ev '^\s*#' /tmp/Aptfile | xargs) |
| 61 | + |
| 62 | +# Configure bundler |
| 63 | +ENV LANG=C.UTF-8 \ |
| 64 | + BUNDLE_JOBS=4 \ |
| 65 | + BUNDLE_RETRY=3 |
| 66 | + |
| 67 | +# Store Bundler settings in the project's root |
| 68 | +ENV BUNDLE_APP_CONFIG=.bundle |
| 69 | + |
| 70 | +# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec` |
| 71 | +# ENV PATH /app/bin:$PATH |
| 72 | + |
| 73 | +# Upgrade RubyGems and install the latest Bundler version |
| 74 | +RUN gem install bundler -v 2.4.22 |
| 75 | + |
| 76 | +# Create a directory for the app code |
| 77 | +RUN mkdir -p /app |
| 78 | +WORKDIR /app |
| 79 | + |
| 80 | +# Document that we're going to expose port 3000 |
| 81 | +EXPOSE 3000 |
| 82 | +# Use Bash as the default command |
| 83 | +CMD ["/bin/bash"] |
0 commit comments