Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RAILS_ENV=production
POSTGRES_HOST=db
POSTGRES_DB=Budgy_production
POSTGRES_USER=Budgy
POSTGRES_PASSWORD=password123
RAILS_MASTER_KEY=6af8d01f85d81f971129fc7691e1bd4a

35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM ruby:3.0.2

RUN apt-get update -qq && \
apt-get install -y build-essential libvips bash bash-completion libffi-dev tzdata postgresql nodejs npm yarn && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man

WORKDIR /budget-app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .

# Set production environment
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
RAILS_ENV="production" \
BUNDLE_WITHOUT="development"

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile --gemfile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile

EXPOSE 3000

# ENTRYPOINT PREPARES THE DATABASE
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["/usr/bin/entrypoint.sh"]

# Start the Rails server
CMD ["rails", "server", "-b", "0.0.0.0"]


68 changes: 68 additions & 0 deletions Dockerfile.multi
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Build stage
FROM ruby:3.0.2 AS build
WORKDIR /app

# Install system dependencies and cleanup
RUN apt-get update -qq && \
apt-get install -y build-essential libvips bash bash-completion libffi-dev tzdata postgresql nodejs npm yarn && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man

# Copy Gemfile and Gemfile.lock to the build stage
COPY Gemfile Gemfile.lock ./

# Install gems (dependencies) for the application
RUN bundle install

# Copy the rest of the application source code
COPY . .

# Set production environment variables
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
RAILS_ENV="production" \
BUNDLE_WITHOUT="development"

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile --gemfile app/ lib/

# Build the application (you may customize this step)
RUN bundle exec rake assets:precompile

# Runtime stage
FROM ruby:3.0.2-slim
WORKDIR /app

# Install the PostgreSQL Client in the Runtime Stage
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
libpq-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man

# Set production environment variables
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
RAILS_ENV="production" \
BUNDLE_WITHOUT="development"

# Copy installed dependiencies gem
COPY --from=build /usr/local/bundle /usr/local/bundle

# Copy all of the application's assets to the production image (assets:precompile)
COPY --from=build app/public/assets /app/public/assets

# Copy bootsnap code for faster boot times
COPY --from=build app/tmp/cache/bootsnap /lib/

COPY . .
EXPOSE 3000

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh

ENTRYPOINT ["/usr/bin/entrypoint.sh"]

# Start your application (adjust the command as needed)
CMD ["rails", "server", "-b", "0.0.0.0"]

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.2'
ruby '3.0.2'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'rails', '~> 7.0.1'
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UkKuGgSd5mr6Fkc9OMiDA+BVvH1Hyl0LyFp15xDfbpJ0J+9i8N5714p/DU/u6uVA0KbZ5pyqyByYn3QLFRS+I9L3YGctvMMOSgF3uPnxa1x67uIhYHja99effFXDm/PqsvvlmtBbIOfzpglepefZtWffOPOAtXBhXFO3RTA2/rS60ZIU6fWCl2tUNwb/X6LbSA86R1H214rRd8xPb87Dm7IsdVre6+QD9SRa8YB9w6cdMcbTGs3hmw8h3/q/hXZd4Y5p43hJ5u3sGa1gSFF4TKuLGMFgQ1wgZiv7dTc2n3YQtbOeqPUoVxGgDnwlaclv9u0knBuYer+j0NixTLxmMkUSfsXAX184vIYr9cTe/oITIAL/f5yhVVpwqWjgm9QTP3orbCriSXSJ2i0issngOGPUzqysMu4YJY5o--6dkopLxTwTxcPVxA--Ohniv+we6M9EnlUQ/tPAYg==
Hy/O9uc0AarR2n8OSCnbQW+iq/A033SM1oPIYeZWxakfQwUnYI0Cs+CR0QxwEsZYmskG3AK2jzO7KL5n8Q9ZKqG2fMYX0Y+L2y8tVnvlcj1tK12tm5rg2NzE3AFxSFD9sDZCYtwQd0Ichb8BS932ne5Pki0DIEUN2I8HhtreZO7n8gmq4kWyLkt2qGHvM+Gxxytbp8juPbQOXQYRPuiGpeAAW7D1waM5xA5bQbv7KkTT7CncBDs9TdkVzoDPcp1jxq/0ogXkcmnMyJJ7QM3t8979/nKcuYa3Q0yPSZJ2cI2lXtio2mAkhyUWsXf+8VHImto2V9+FdbGmmGNB0Rq0Fyy5NEi9Iwh93NmnEbDPN8xYtR/SqicWg74kWzw1MrQVzj1Td0fAt6GMVzKDLfnJLEZEA2htW6qFXsLu--8wqkHMEbic8SXV1v--TJFtcZa5TnXwbSheY804WQ==
7 changes: 5 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
default: &default
adapter: postgresql
encoding: unicode
username: postgres
password: admin123

# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
Expand Down Expand Up @@ -82,5 +85,5 @@ test:
production:
<<: *default
database: Budgy_production
username: Budgy
password: <%= ENV["Budgy_DATABASE_PASSWORD"] %>
username: postgres
password: admin123
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'
services:
app:
build:
context: .
dockerfile: Dockerfile.multi
command: "rails server"
container_name: ruby-on-rails
environment:
- RAILS_ENV=${RAILS_ENV}
- POSTGRES_HOST=${POSTGRES_HOST}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
volumes:
- app-storage:/budget-app/storage
depends_on:
- db
ports:
- "3000:3000"
db:
image: postgres:14.2-alpine
container_name: demo_postgres
volumes:
- postgres_data:/var/lib/postgresql/data
command:
"postgres -c 'max_connections=500'"
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- "5433:5432"

volumes:
postgres_data: {}
app-storage: {}
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# If running the rails server then create or migrate existing database
if [ "${*}" = "./bin/rails server" ]; then
./bin/rails db:create
./bin/rails db:prepare
fi

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"