An attempt at docker
This commit is contained in:
parent
fe15365524
commit
76f10abe76
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
/public/assets
|
||||
/app/assets/builds
|
||||
65
Dockerfile
Normal file
65
Dockerfile
Normal file
@ -0,0 +1,65 @@
|
||||
# syntax = docker/dockerfile:1
|
||||
|
||||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
|
||||
ARG RUBY_VERSION=3.2.2
|
||||
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
|
||||
|
||||
# Rails app lives here
|
||||
WORKDIR /rails
|
||||
|
||||
# Set production environment
|
||||
ENV RAILS_ENV="production" \
|
||||
BUNDLE_DEPLOYMENT="1" \
|
||||
BUNDLE_PATH="/usr/local/bundle"
|
||||
|
||||
|
||||
# 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 libvips pkg-config curl sassc libsass-dev libjemalloc2 zlib1g-dev openssl libssl-dev
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Precompile bootsnap code for faster boot times
|
||||
RUN bundle exec bootsnap precompile app/ lib/
|
||||
|
||||
# Work around a bug in SASSC https://github.com/sass/sassc-ruby/issues/146
|
||||
ENV BUNDLE_BUILD__SASSC=--disable-march-tune-native
|
||||
|
||||
RUN RAILS_ENV=production BUILD_STAGE=docker ./bin/rails tailwindcss:build
|
||||
RUN RAILS_ENV=production BUILD_STAGE=docker ./bin/rails assets:precompile
|
||||
|
||||
|
||||
# Final stage for app image
|
||||
FROM base
|
||||
|
||||
# Install packages needed for deployment
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install --no-install-recommends -y libvips postgresql-client curl && \
|
||||
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
||||
|
||||
# Copy built artifacts: gems, application
|
||||
COPY --from=build /usr/local/bundle /usr/local/bundle
|
||||
COPY --from=build /rails /rails
|
||||
|
||||
# Run and own only the runtime files as a non-root user for security
|
||||
RUN useradd rails --home /rails --shell /bin/bash && \
|
||||
chown -R rails:rails db log storage tmp
|
||||
USER rails:rails
|
||||
|
||||
# Entrypoint prepares the database.
|
||||
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
||||
|
||||
# Start the server by default, this can be overwritten at runtime
|
||||
EXPOSE 3000
|
||||
@ -161,6 +161,8 @@ GEM
|
||||
net-smtp (0.4.0)
|
||||
net-protocol
|
||||
nio4r (2.5.9)
|
||||
nokogiri (1.15.4-aarch64-linux)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.15.4-arm64-darwin)
|
||||
racc (~> 1.4)
|
||||
pg (1.5.4)
|
||||
@ -225,7 +227,7 @@ GEM
|
||||
rexml (~> 3.2, >= 3.2.5)
|
||||
rubyzip (>= 1.2.2, < 3.0)
|
||||
websocket (~> 1.0)
|
||||
sidekiq (7.1.4)
|
||||
sidekiq (7.1.5)
|
||||
concurrent-ruby (< 2)
|
||||
connection_pool (>= 2.3.0)
|
||||
rack (>= 2.2.4)
|
||||
@ -240,6 +242,8 @@ GEM
|
||||
stimulus-rails (1.2.2)
|
||||
railties (>= 6.0.0)
|
||||
stringio (3.0.8)
|
||||
tailwindcss-rails (2.0.30-aarch64-linux)
|
||||
railties (>= 6.0.0)
|
||||
tailwindcss-rails (2.0.30-arm64-darwin)
|
||||
railties (>= 6.0.0)
|
||||
thor (1.2.2)
|
||||
@ -269,6 +273,7 @@ GEM
|
||||
zeitwerk (2.6.12)
|
||||
|
||||
PLATFORMS
|
||||
aarch64-linux
|
||||
arm64-darwin-22
|
||||
|
||||
DEPENDENCIES
|
||||
|
||||
12
bin/docker-entrypoint
Normal file
12
bin/docker-entrypoint
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
# Create new or migrate existing database
|
||||
./bin/rails db:prepare
|
||||
|
||||
# Start the server by default
|
||||
exec bin/rails server
|
||||
else
|
||||
# Allow other commands, like console or runner, to be called
|
||||
exec bin/rails "$@"
|
||||
fi
|
||||
Loading…
Reference in New Issue
Block a user