-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Dockerfile and docker-compose.yml for local development (#10)
- Loading branch information
Showing
5 changed files
with
86 additions
and
190 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 |
---|---|---|
@@ -1,77 +1,29 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# Note: This Dockerfile is optimized for production deployment and isn't a good base | ||
# for development enviroments. | ||
|
||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version | ||
ARG RUBY_VERSION=3.3.1 | ||
FROM registry.docker.com/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 | ||
|
||
# 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 install --no-install-recommends -y build-essential git libpq-dev pkg-config unzip | ||
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim | ||
RUN <<EOF | ||
apt-get update | ||
apt-get install -y build-essential libpq-dev curl unzip | ||
EOF | ||
|
||
ARG BUN_VERSION=1.1.8 | ||
ENV BUN_INSTALL=/usr/local/bun | ||
ENV PATH=/usr/local/bun/bin:$PATH | ||
ARG BUN_VERSION=1.1.8 | ||
RUN curl -fsSL https://bun.sh/install | bash -s -- "bun-v${BUN_VERSION}" | ||
|
||
# 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 node modules | ||
COPY package.json bun.lockb ./ | ||
RUN bun install --frozen-lockfile | ||
|
||
# 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 | ||
WORKDIR /tmp | ||
ADD Gemfile . | ||
ADD Gemfile.lock . | ||
RUN gem install bundler -v 2.5.10 | ||
RUN bundle install | ||
|
||
# Clean up installation packages to reduce image size | ||
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
WORKDIR /app | ||
ADD . /app | ||
|
||
# Copy built artifacts: gems, application | ||
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" | ||
COPY --from=build /rails /rails | ||
RUN bun install | ||
|
||
# Run and own only the runtime files as a non-root user for security | ||
RUN groupadd --system --gid 1000 rails && \ | ||
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ | ||
chown -R rails:rails db log storage tmp | ||
USER 1000:1000 | ||
RUN bin/rails assets:precompile | ||
|
||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["/rails/bin/docker-entrypoint"] | ||
ENV PORT 3000 | ||
EXPOSE $PORT | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
CMD ["./bin/rails", "server"] | ||
CMD rails s -b 0.0.0.0 -p $PORT |
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,28 +1,17 @@ | ||
default: &default | ||
adapter: postgresql | ||
encoding: unicode | ||
host: <%= ENV['POSTGRES_HOST'] %> | ||
pool: 5 | ||
username: <%= ENV['POSTGRES_USER'] %> | ||
password: <%= ENV['POSTGRES_PASSWORD'] %> | ||
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %> | ||
username: <%= ENV.fetch('POSTGRES_USER') { 'postgres' } %> | ||
password: <%= ENV.fetch('POSTGRES_PASSWORD') { 'password' } %> | ||
host: <%= ENV.fetch('POSTGRES_HOST') { 'db' } %> | ||
timeout: 5000 | ||
|
||
development: | ||
<<: *default | ||
database: "shore_development" | ||
|
||
database: shore_development | ||
test: | ||
<<: *default | ||
database: "shore_test" | ||
|
||
heroku: | ||
<<: *default | ||
database: "shore_heroku" | ||
|
||
staging: | ||
<<: *default | ||
database: "shore_staging" | ||
|
||
database: shore_test | ||
production: | ||
<<: *default | ||
database: "shore_production" | ||
database: shore_production |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
volumes: | ||
dbdata: | ||
driver: local | ||
services: | ||
db: | ||
image: postgres:16.3 | ||
environment: | ||
- PGDATA=/var/lib/postgresql/data/pgdata | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=password | ||
volumes: | ||
- dbdata:/var/lib/postgresql/data/pgdata | ||
web: | ||
build: . | ||
tty: true | ||
ports: | ||
- "3000:3000" | ||
environment: | ||
- RAILS_ENV=development | ||
- RACK_ENV=development | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=password | ||
- RAILS_SERVE_STATIC_FILES=false | ||
- VITE_RUBY_HOST=vite | ||
# volumes: | ||
# - .:/app | ||
depends_on: | ||
- db | ||
command: bundle exec rails s -b 0.0.0.0 -p 3000 | ||
worker: | ||
build: . | ||
environment: | ||
- RAILS_ENV=development | ||
- RACK_ENV=development | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=password | ||
- RAILS_SERVE_STATIC_FILES=false | ||
# volumes: | ||
# - .:/app | ||
depends_on: | ||
- db | ||
command: bundle exec rake solid_queue:start | ||
vite: | ||
build: . | ||
environment: | ||
- RAILS_ENV=development | ||
- RACK_ENV=development | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=password | ||
- RAILS_SERVE_STATIC_FILES=false | ||
- VITE_RUBY_HOST=0.0.0.0 | ||
ports: | ||
- "3036:3036" | ||
volumes: | ||
- ./app/frontend:/app/app/frontend | ||
depends_on: | ||
- db | ||
command: bundle exec vite dev |