mirror of
https://github.com/czhu12/canine.git
synced 2025-12-21 10:49:49 -06:00
100 lines
4.0 KiB
Docker
100 lines
4.0 KiB
Docker
# syntax = docker/dockerfile:1
|
|
|
|
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
|
|
# docker build -t my-app .
|
|
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
|
|
|
|
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
|
|
ARG RUBY_VERSION=3.3.4
|
|
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
|
|
|
|
# Rails app lives here
|
|
WORKDIR /rails
|
|
|
|
# Install base packages
|
|
RUN apt-get update -qq && \
|
|
apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
|
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
|
|
# Set production environment
|
|
ENV RAILS_ENV="production" \
|
|
BUNDLE_DEPLOYMENT="1" \
|
|
BUNDLE_PATH="/usr/local/bundle" \
|
|
BUNDLE_WITHOUT="development"
|
|
|
|
# Throw-away build stage to reduce size of final image
|
|
FROM base AS build
|
|
|
|
# Install packages needed to build gems
|
|
RUN apt-get update -qq && \
|
|
apt-get install --no-install-recommends -y build-essential git libpq-dev pkg-config && \
|
|
curl -k -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -k -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
|
|
chmod +x ./kubectl && \
|
|
mv ./kubectl /usr/local/bin/kubectl && \
|
|
curl -k -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 && \
|
|
chmod +x get_helm.sh && \
|
|
./get_helm.sh && \
|
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
|
|
RUN curl -fL https://app.getambassador.io/download/tel2oss/releases/download/v2.21.1/telepresence-linux-amd64 -o /usr/local/bin/telepresence && \
|
|
chmod a+x /usr/local/bin/telepresence
|
|
|
|
# Install pack CLI for Cloud Native Buildpacks
|
|
RUN curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.38.2/pack-v0.38.2-linux.tgz" | tar -xz -C /usr/local/bin
|
|
|
|
# Install application gems
|
|
COPY Gemfile Gemfile.lock ./
|
|
RUN bundle install && \
|
|
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
|
|
bundle exec bootsnap precompile --gemfile
|
|
|
|
# Install javascript dependencies
|
|
ARG NODE_VERSION=20.11.0
|
|
ARG YARN_VERSION=1.22.21
|
|
ENV PATH=/usr/local/node/bin:$PATH
|
|
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
|
|
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
|
|
npm install -g yarn@$YARN_VERSION && \
|
|
rm -rf /tmp/node-build-master
|
|
|
|
COPY package.json yarn.lock /rails/
|
|
RUN yarn install
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Precompile bootsnap code for faster boot times
|
|
RUN bundle exec bootsnap precompile app/ lib/
|
|
|
|
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
|
|
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
|
|
|
|
|
|
|
|
# Final stage for app image
|
|
FROM base
|
|
|
|
RUN apt-get update -qq && \
|
|
apt-get install --no-install-recommends -y git ca-certificates gnupg && \
|
|
install -m 0755 -d /etc/apt/keyrings && \
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
|
|
chmod a+r /etc/apt/keyrings/docker.asc && \
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list && \
|
|
apt-get update -qq && \
|
|
apt-get install --no-install-recommends -y docker-ce-cli docker-buildx-plugin && \
|
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
|
|
# Copy built artifacts: gems, application
|
|
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
|
|
COPY --from=build /rails /rails
|
|
COPY --from=build /usr/local/bin/kubectl /usr/local/bin/kubectl
|
|
COPY --from=build /usr/local/bin/helm /usr/local/bin/helm
|
|
COPY --from=build /usr/local/bin/telepresence /usr/local/bin/telepresence
|
|
COPY --from=build /usr/local/bin/pack /usr/local/bin/pack
|
|
|
|
# Entrypoint prepares the database.
|
|
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
|
|
|
EXPOSE 3000
|
|
CMD ["./bin/rails", "server"]
|