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-smtp (0.4.0)
|
||||||
net-protocol
|
net-protocol
|
||||||
nio4r (2.5.9)
|
nio4r (2.5.9)
|
||||||
|
nokogiri (1.15.4-aarch64-linux)
|
||||||
|
racc (~> 1.4)
|
||||||
nokogiri (1.15.4-arm64-darwin)
|
nokogiri (1.15.4-arm64-darwin)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
pg (1.5.4)
|
pg (1.5.4)
|
||||||
@ -225,7 +227,7 @@ GEM
|
|||||||
rexml (~> 3.2, >= 3.2.5)
|
rexml (~> 3.2, >= 3.2.5)
|
||||||
rubyzip (>= 1.2.2, < 3.0)
|
rubyzip (>= 1.2.2, < 3.0)
|
||||||
websocket (~> 1.0)
|
websocket (~> 1.0)
|
||||||
sidekiq (7.1.4)
|
sidekiq (7.1.5)
|
||||||
concurrent-ruby (< 2)
|
concurrent-ruby (< 2)
|
||||||
connection_pool (>= 2.3.0)
|
connection_pool (>= 2.3.0)
|
||||||
rack (>= 2.2.4)
|
rack (>= 2.2.4)
|
||||||
@ -240,6 +242,8 @@ GEM
|
|||||||
stimulus-rails (1.2.2)
|
stimulus-rails (1.2.2)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
stringio (3.0.8)
|
stringio (3.0.8)
|
||||||
|
tailwindcss-rails (2.0.30-aarch64-linux)
|
||||||
|
railties (>= 6.0.0)
|
||||||
tailwindcss-rails (2.0.30-arm64-darwin)
|
tailwindcss-rails (2.0.30-arm64-darwin)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
thor (1.2.2)
|
thor (1.2.2)
|
||||||
@ -269,6 +273,7 @@ GEM
|
|||||||
zeitwerk (2.6.12)
|
zeitwerk (2.6.12)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
aarch64-linux
|
||||||
arm64-darwin-22
|
arm64-darwin-22
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
|||||||
@ -21,4 +21,4 @@
|
|||||||
|
|
||||||
.lecture-cancelled {
|
.lecture-cancelled {
|
||||||
background: repeating-linear-gradient(45deg, rgb(254 226 226/var(--tw-bg-opacity)), rgb(254 226 226/var(--tw-bg-opacity)) 10px, white 10px, white 20px);
|
background: repeating-linear-gradient(45deg, rgb(254 226 226/var(--tw-bg-opacity)), rgb(254 226 226/var(--tw-bg-opacity)) 10px, white 10px, white 20px);
|
||||||
}
|
}
|
||||||
|
|||||||
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