mirror of
https://github.com/czhu12/canine.git
synced 2025-12-17 00:44:33 -06:00
113 lines
4.4 KiB
Docker
113 lines
4.4 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
|
|
ARG KUBECTL_VERSION=v1.31.0
|
|
ARG HELM_VERSION=v3.16.3
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
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/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl && \
|
|
chmod +x ./kubectl && \
|
|
mv ./kubectl /usr/local/bin/kubectl && \
|
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
|
|
RUN set -eux; \
|
|
os="${TARGETOS:-linux}"; \
|
|
arch="${TARGETARCH:-amd64}"; \
|
|
url="https://get.helm.sh/helm-${HELM_VERSION}-${os}-${arch}.tar.gz"; \
|
|
curl -fsSLO "$url"; \
|
|
curl -fsSLO "${url}.sha256sum"; \
|
|
sha256sum -c "helm-${HELM_VERSION}-${os}-${arch}.tar.gz.sha256sum"; \
|
|
tar -xzf "helm-${HELM_VERSION}-${os}-${arch}.tar.gz"; \
|
|
install -m 0755 "${os}-${arch}/helm" /usr/local/bin/helm; \
|
|
rm -rf "helm-${HELM_VERSION}-${os}-${arch}.tar.gz" "helm-${HELM_VERSION}-${os}-${arch}.tar.gz.sha256sum" "${os}-${arch}"
|
|
|
|
ARG TELEPRESENCE_VERSION=v2.21.1
|
|
RUN curl -fL https://app.getambassador.io/download/tel2oss/releases/download/${TELEPRESENCE_VERSION}/telepresence-linux-${TARGETARCH} -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"]
|