-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use modern Dockerfile, switch from Yarn -> npm
- Loading branch information
1 parent
b19c164
commit f8d25be
Showing
11 changed files
with
13,167 additions
and
7,864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
bin/yarn lint-staged | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,136 @@ | ||
# Declare arguments, with default values | ||
ARG DISTRO_NAME=bullseye | ||
ARG RUBY_VERSION=3.2.2 | ||
ARG NODE_MAJOR_VERSION=18 | ||
ARG YARN_VERSION=1.22.19 | ||
ARG POSTGRES_MAJOR_VERSION=14 | ||
ARG OVERMIND_VERSION=2.4.0 | ||
ARG CHROME_VERSION=stable | ||
|
||
# Configure base image | ||
FROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME | ||
|
||
# Re-declare arguments, since they are reset by the FROM instructions | ||
# | ||
# See: https://github.com/moby/moby/issues/34129 | ||
ARG DISTRO_NAME | ||
ARG RUBY_VERSION | ||
ARG NODE_MAJOR_VERSION | ||
ARG YARN_VERSION | ||
ARG POSTGRES_MAJOR_VERSION | ||
ARG OVERMIND_VERSION | ||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
# Install curl | ||
RUN apt-get update -qq \ | ||
&& apt-get install -yq --no-install-recommends curl \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | ||
&& truncate -s 0 /var/log/*log | ||
|
||
# Install Bundler | ||
ENV LANG=C.UTF-8 BUNDLE_JOBS=4 BUNDLE_RETRY=3 BUNDLE_APP_CONFIG=.bundle | ||
RUN gem update --system && gem install bundler | ||
|
||
# Install jemalloc | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends libjemalloc2 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 | ||
|
||
# Install NodeJS and Yarn | ||
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR_VERSION.x | bash - | ||
RUN apt-get update -qq \ | ||
&& apt-get -yq dist-upgrade \ | ||
&& apt-get install -yq --no-install-recommends nodejs \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | ||
&& truncate -s 0 /var/log/*log | ||
RUN npm install -g yarn@$YARN_VERSION | ||
# syntax = docker/dockerfile:1.2 | ||
|
||
|
||
# == System == | ||
FROM debian:bookworm-slim AS sys | ||
ENV OVERMIND_VERSION=2.5.1 | ||
ENV STARSHIP_VERSION=1.20.1 | ||
ENV DEVTOOLS="vim less" | ||
ENV APPLICATION_DEPS="libvips" | ||
|
||
# Configure workdir | ||
WORKDIR /app | ||
|
||
# Ensure packages are cached | ||
RUN rm /etc/apt/apt.conf.d/docker-clean | ||
|
||
# Install runtime programs and dependencies | ||
RUN --mount=type=cache,target=/var/cache,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ | ||
apt-get update -yq && \ | ||
echo "ca-certificates tmux $DEVTOOLS $APPLICATION_DEPS" | xargs apt-get install -yq --no-install-recommends && \ | ||
apt-get purge -yq --auto-remove -o APT::AutoRemove::RecommendsImportant=false llvm && \ | ||
rm -r /var/log/* && \ | ||
tmux -V | ||
|
||
# Install Ruby and Bundler | ||
COPY .ruby-version ./ | ||
ENV LANG=C.UTF-8 GEM_HOME=/usr/local/bundle | ||
ENV BUNDLE_SILENCE_ROOT_WARNING=1 BUNDLE_APP_CONFIG="$GEM_HOME" PATH="$GEM_HOME/bin:$PATH" | ||
RUN --mount=type=cache,target=/var/cache,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ | ||
BUILD_DEPS="git curl build-essential zlib1g-dev libssl-dev libgmp-dev libyaml-dev libjemalloc-dev" set -eux && \ | ||
RUNTIME_DEPS="libyaml-0-2 libjemalloc2" && \ | ||
apt-get update -yq && \ | ||
echo $BUILD_DEPS $RUNTIME_DEPS | xargs apt-get install -yq --no-install-recommends; \ | ||
git clone --depth 1 https://github.com/rbenv/ruby-build.git && \ | ||
PREFIX=/tmp ./ruby-build/install.sh && \ | ||
mkdir -p "$GEM_HOME" && chmod 1777 "$GEM_HOME" && \ | ||
RUBY_CONFIGURE_OPTS=--with-jemalloc /tmp/bin/ruby-build "$(cat .ruby-version)" /usr/local && \ | ||
echo $BUILD_DEPS | xargs apt-get purge -yq --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ | ||
rm -r ./ruby-build /tmp/* /var/log/* && \ | ||
ruby --version && gem --version && bundle --version | ||
|
||
# Install NodeJS | ||
COPY .node-version ./ | ||
ENV NODE_ENV=production | ||
RUN --mount=type=cache,target=/var/cache,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ | ||
BUILD_DEPS="git curl" set -eux && \ | ||
apt-get update -yq && \ | ||
echo $BUILD_DEPS | xargs apt-get install -yq --no-install-recommends; \ | ||
git clone --depth 1 https://github.com/nodenv/node-build.git && \ | ||
PREFIX=/tmp ./node-build/install.sh && \ | ||
/tmp/bin/node-build "$(cat .node-version)" /usr/local && \ | ||
echo $BUILD_DEPS | xargs apt-get purge -yq --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ | ||
rm -r ./node-build /var/log/* && \ | ||
node --version && npm --version | ||
|
||
# Install Overmind | ||
RUN apt-get update -qq \ | ||
&& apt-get install -yq --no-install-recommends tmux \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | ||
&& truncate -s 0 /var/log/*log \ | ||
&& curl -Lo /usr/bin/overmind.gz https://github.com/DarthSim/overmind/releases/download/v$OVERMIND_VERSION/overmind-v$OVERMIND_VERSION-linux-amd64.gz \ | ||
&& gzip -d /usr/bin/overmind.gz \ | ||
&& chmod u+x /usr/bin/overmind | ||
|
||
# Install Postgres client | ||
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ | ||
&& echo deb http://apt.postgresql.org/pub/repos/apt/ $DISTRO_NAME-pgdg main $POSTGRES_MAJOR_VERSION > /etc/apt/sources.list.d/pgdg.list | ||
RUN apt-get update -qq \ | ||
&& apt-get -yq dist-upgrade \ | ||
&& apt-get install -yq --no-install-recommends libpq-dev postgresql-client-$POSTGRES_MAJOR_VERSION \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | ||
&& truncate -s 0 /var/log/*log | ||
|
||
# Install Google Chrome | ||
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ | ||
&& echo deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main >> /etc/apt/sources.list.d/google-chrome.list | ||
RUN apt-get -y update -qq \ | ||
&& apt-get -yq dist-upgrade \ | ||
&& apt-get install -yq --no-install-recommends google-chrome-stable \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | ||
&& truncate -s 0 /var/log/*log | ||
|
||
# Install programs | ||
COPY Aptfile /tmp/Aptfile | ||
RUN apt-get update -qq \ | ||
&& apt-get -yq dist-upgrade \ | ||
&& apt-get install -yq --no-install-recommends $(grep -Ev '^\s*#' /tmp/Aptfile | xargs) \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | ||
&& truncate -s 0 /var/log/*log | ||
|
||
# Install Starship | ||
COPY starship.toml /root/.config/starship.toml | ||
RUN curl -sS https://starship.rs/install.sh | sh -s -- --yes | ||
RUN --mount=type=cache,target=/var/cache,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ | ||
BUILD_DEPS="curl" set -eux && \ | ||
apt-get update -yq && \ | ||
echo $BUILD_DEPS | xargs apt-get install -yq --no-install-recommends; \ | ||
curl -Lo /usr/bin/overmind.gz https://github.com/DarthSim/overmind/releases/download/v$OVERMIND_VERSION/overmind-v$OVERMIND_VERSION-linux-amd64.gz && \ | ||
gzip -d /usr/bin/overmind.gz && \ | ||
chmod u+x /usr/bin/overmind && \ | ||
echo $BUILD_DEPS | xargs apt-get purge -yq --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ | ||
rm -r /var/log/* && \ | ||
overmind --version | ||
|
||
# Configure shell | ||
COPY .zcustomizations .inputrc /root/ | ||
RUN echo '\n. "$HOME/.zcustomizations"' >> ~/.zshrc && chsh -s /bin/zsh | ||
ENV SHELL=/bin/bash | ||
RUN --mount=type=cache,target=/var/cache,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ | ||
BUILD_DEPS="curl" set -eux && \ | ||
apt-get update -yq && \ | ||
echo $BUILD_DEPS | xargs apt-get install -yq --no-install-recommends; \ | ||
curl -sS https://starship.rs/install.sh | sh -s -- -y -v="v$STARSHIP_VERSION" && \ | ||
echo $BUILD_DEPS | xargs apt-get purge -yq --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ | ||
rm -r /tmp/* /var/log/* && \ | ||
starship --version | ||
COPY .bash_profile .inputrc /root/ | ||
COPY starship.toml /root/.config/starship.toml | ||
|
||
# Configure workdir and environment | ||
WORKDIR /app | ||
ENV BUNDLE_WITHOUT="development test" RAILS_ENV=production RAILS_LOG_TO_STDOUT=true NODE_ENV=$RAILS_ENV | ||
|
||
# Copy dependency lists | ||
COPY Gemfile Gemfile.lock package.json yarn.lock ./ | ||
# == Dependencies == | ||
FROM sys AS deps | ||
|
||
# Install Ruby dependencies | ||
COPY Gemfile Gemfile.lock ./ | ||
ENV BUNDLE_WITHOUT="development test" | ||
RUN --mount=type=cache,target=/var/cache,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ | ||
BUILD_DEPS="build-essential libreadline-dev libjemalloc-dev libpq-dev" \ | ||
RUNTIME_DEPS="libpq5" set -eux && \ | ||
apt-get update -yq && \ | ||
echo $BUILD_DEPS $RUNTIME_DEPS | xargs apt-get install -yq --no-install-recommends; \ | ||
BUNDLE_IGNORE_MESSAGES=1 bundle install && \ | ||
echo $BUILD_DEPS | xargs apt-get purge -yq --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ | ||
rm -r /var/log/* | ||
|
||
# Install dependencies | ||
RUN bundle install && yarn install | ||
# Install NodeJS dependencies | ||
COPY package.json package-lock.json ./ | ||
ENV NODE_ENV=production | ||
RUN --mount=type=cache,target=/root/.npm,sharing=locked \ | ||
npm install && \ | ||
rm -r /tmp/* | ||
|
||
|
||
# == Application == | ||
FROM deps AS app | ||
ENV PORT=3000 | ||
|
||
# Copy application code | ||
COPY . ./ | ||
|
||
# Precompile bootsnap code for faster boot times | ||
RUN bundle exec bootsnap precompile --gemfile app/ lib/ | ||
|
||
# Configure application environment | ||
ENV RAILS_ENV=production RAILS_LOG_TO_STDOUT=true MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true" | ||
|
||
# Precompile assets | ||
RUN bundle exec rails assets:precompile RAILS_SECRET_KEY_BASE=dummy | ||
RUN --mount=type=cache,target=/root/.npm,sharing=locked \ | ||
SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile | ||
|
||
# Expose ports | ||
EXPOSE 3000 | ||
EXPOSE ${PORT} | ||
|
||
# Configure healthcheck | ||
HEALTHCHECK --interval=15s --timeout=2s --start-period=10s --retries=3 \ | ||
CMD curl -f http://127.0.0.1:3000/status || exit 1 | ||
CMD curl -f http://127.0.0.1:${PORT}/status | ||
|
||
# Set command | ||
CMD ["/app/bin/run"] | ||
# Set entrypoint and default command | ||
CMD [ "bin/run" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.