Skip to content

Commit

Permalink
Fixed setup for Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
yatish27 committed May 15, 2024
1 parent 8c1dbe8 commit c246065
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 54 deletions.
29 changes: 0 additions & 29 deletions Dockerfile

This file was deleted.

37 changes: 37 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM registry.docker.com/library/ruby:3.3.1-slim

ENV APP_PATH /var/app
ENV BUNDLE_VERSION 2.5.10
ENV BUN_VERSION 1.1.8
ENV RAILS_PORT 3000
ENV BUNDLE_PATH /usr/local/bundle
ENV BUNDLE_PATH /usr/local/bundle
ENV GEM_PATH /usr/local/bundle
ENV GEM_HOME /usr/local/bundle
ENV BUN_INSTALL /usr/local/bun
ENV PATH $BUN_INSTALL/bin:$PATH

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh

RUN chmod +x /usr/local/bin/docker-entrypoint.sh

RUN <<EOF
apt-get update
apt-get install -y build-essential libpq-dev curl unzip
EOF

RUN curl -fsSL https://bun.sh/install | bash -s -- "bun-v${BUN_VERSION}"

RUN gem install bundler --version "$BUNDLE_VERSION"

WORKDIR $APP_PATH

COPY Gemfile Gemfile.lock ./
COPY package.json ./

RUN bundle check || bundle install --jobs=8
RUN bun install

COPY . .

EXPOSE $RAILS_PORT
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ group :development do
gem "bundler-audit", "~> 0.9.1", require: false
gem "erb_lint", "~> 0.5", require: false
gem "overmind"
gem "foreman", "~> 0.87", ">= 0.87.2"
gem "colorize", "~> 1.1"
gem "letter_opener", "~> 1.10"
gem "rubocop", "~> 1.63", ">= 1.63.5", require: false
Expand Down
8 changes: 2 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ GEM
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
foreman (0.88.1)
fugit (1.9.0)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
Expand Down Expand Up @@ -185,11 +186,6 @@ GEM
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
overmind (2.5.1)
overmind (2.5.1-arm-linux)
overmind (2.5.1-arm64-darwin)
overmind (2.5.1-x86-linux)
overmind (2.5.1-x86_64-darwin)
parallel (1.24.0)
parser (3.3.1.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -335,10 +331,10 @@ DEPENDENCIES
dotenv (~> 3.1, >= 3.1.2)
erb_lint (~> 0.5)
factory_bot_rails (~> 6.4, >= 6.4.3)
foreman (~> 0.87, >= 0.87.2)
jbuilder (~> 2.12)
letter_opener (~> 1.10)
minitest-reporters (~> 1.6, >= 1.6.1)
overmind
pg (~> 1.5, >= 1.5.6)
puma (~> 6.4, >= 6.4.2)
rails (~> 7.1, >= 7.1.3.2)
Expand Down
12 changes: 6 additions & 6 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ FileUtils.chdir APP_ROOT do
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
# Add necessary setup steps to this file.

unless File.exist?(".env")
if File.exist?(".env.sample") && !File.exist?(".env")
puts "\n== Copying env.sample files =="
FileUtils.cp ".env.sample", ".env"
puts "Copied .env.sample to .env".green
end

# Install system dependencies if Homebrew is installed
if Gem::Platform.local.os.include?("darwin") && command?("brew")
puts "\n== Installing packages with Homebrew =="
system("brew bundle check --no-lock --no-upgrade") || system!("brew bundle --no-upgrade --no-lock")
end
# # Install system dependencies if Homebrew is installed
# if Gem::Platform.local.os.include?("darwin") && command?("brew")
# puts "\n== Installing packages with Homebrew =="
# system("brew bundle check --no-lock --no-upgrade") || system!("brew bundle --no-upgrade --no-lock")
# end

puts "\n== Installing gems =="
system! "gem install bundler --conservative"
Expand Down
58 changes: 45 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,90 @@
networks:
development:
volumes:
dbdata:
driver: local
db_data:
gem_cache:
node_modules:
services:
db:
image: postgres:16.3
container_name: shore_db
networks:
- development
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
- dbdata:/var/lib/postgresql/data/pgdata
- db_data:/var/lib/postgresql/data/pgdata
web:
build: .
build:
context: .
dockerfile: Dockerfile.dev
networks:
- development
container_name: shore_app
stdin_open: true
tty: true
entrypoint: docker-entrypoint.sh
ports:
- "3000:3000"
environment:
- RAILS_ENV=development
- RACK_ENV=development
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_HOST=db
- RAILS_SERVE_STATIC_FILES=false
- VITE_RUBY_HOST=vite
# volumes:
# - .:/app
volumes:
- .:/var/app:cached
- gem_cache:/usr/local/bundle/gems
- node_modules:/var/app/node_modules
depends_on:
- db
command: bundle exec rails s -b 0.0.0.0 -p 3000
worker:
build: .
build:
context: .
dockerfile: Dockerfile.dev
networks:
- development
container_name: shore_worker
environment:
- RAILS_ENV=development
- RACK_ENV=development
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_HOST=db
- RAILS_SERVE_STATIC_FILES=false
# volumes:
# - .:/app
volumes:
- .:/var/app
- gem_cache:/usr/local/bundle/gems
- node_modules:/var/app/node_modules
depends_on:
- db
command: bundle exec rake solid_queue:start
vite:
build: .
build:
context: .
dockerfile: Dockerfile.dev
container_name: shore_vite
networks:
- development
environment:
- RAILS_ENV=development
- RACK_ENV=development
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_HOST=db
- RAILS_SERVE_STATIC_FILES=false
- VITE_RUBY_HOST=0.0.0.0
ports:
- "3036:3036"
- "3036:3036"
volumes:
- ./app/frontend:/app/app/frontend
- .:/var/app:cached
- gem_cache:/usr/local/bundle/gems
- node_modules:/var/app/node_modules
depends_on:
- db
command: bundle exec vite dev
command: bundle exec vite dev
15 changes: 15 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e
echo "ENVIRONMENT: $RAILS_ENV"

# remove any existing pid file
rm -f $APP_PATH/tmp/pids/server.pid

# database_config_path="$APP_PATH/config/database.yml"

# rm -f database_config_path
# cp $APP_PATH/config/database.yml.docker "$database_config_path"

# append bundle exec to every command
bundle exec ${@}

0 comments on commit c246065

Please sign in to comment.