diff --git a/.dockerignore b/.dockerignore index 6be8c8f3..a54c434c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,7 @@ .git -.dockerignore +log/* +tmp/* +vendor/bundle +node_modules +.bundle +.DS_Store diff --git a/Dockerfile b/Dockerfile index 74c726d4..f8d1aec4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,34 @@ -FROM ruby:2.5 -RUN apt-get update -qq && apt-get install -y build-essential libmariadb-dev libcups2-dev libpq-dev nodejs tzdata -RUN mkdir /sxrestaurant -RUN mkdir -p /sxrestaurant/tmp/puma -ENV RAILS_ENV production -ENV RACK_ENV production -WORKDIR /sxrestaurant -#RUN gem install bundler -#COPY Gemfile /sxrestaurant/Gemfile -#COPY Gemfile.lock /sxrestaurant/Gemfile.lock -#RUN bundle install --without development test -RUN echo "Asia/Rangoon" > /etc/timezone -RUN dpkg-reconfigure -f noninteractive tzdata -RUN date -COPY . /sxrestaurant -RUN gem install bundler -#RUN bundle update --bundler -RUN bundle install --without development test -RUN bundle exec rake assets:precompile -CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"] +FROM ruby:2.6.10-slim-bullseye + +# Install dependencies (MySQL client + ImageMagick for CarrierWave/MiniMagick) +RUN apt-get update -qq && apt-get install -y --no-install-recommends \ + build-essential \ + default-libmysqlclient-dev \ + nodejs \ + git \ + curl \ + imagemagick \ + libmagickwand-dev \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Install gems +COPY Gemfile Gemfile.lock ./ +RUN bundle install --deployment --without development test --jobs 4 + +# Copy application +COPY . . + +# Create required directories +RUN mkdir -p tmp/pids tmp/puma tmp/cache tmp/sockets log storage public/uploads + +# Precompile assets +RUN RAILS_ENV=production SECRET_KEY_BASE=placeholder bundle exec rake assets:precompile 2>/dev/null || true + +EXPOSE 3000 + +COPY entrypoint.sh /app/entrypoint.sh +RUN chmod +x /app/entrypoint.sh + +CMD ["/app/entrypoint.sh"] diff --git a/config/puma_docker.rb b/config/puma_docker.rb new file mode 100644 index 00000000..e2152b34 --- /dev/null +++ b/config/puma_docker.rb @@ -0,0 +1,17 @@ +# Puma configuration for Docker deployment +application_path = File.expand_path('..', __dir__) +directory application_path + +environment ENV.fetch('RAILS_ENV') { 'production' } +pidfile "#{application_path}/tmp/puma/pid" +state_path "#{application_path}/tmp/puma/state" + +# Log to stdout/stderr in Docker +stdout_redirect '/dev/stdout', '/dev/stderr', true + +# Use PORT env var (default 3000 for Coolify) +port ENV.fetch('PORT') { 3000 } + +workers ENV.fetch('WEB_CONCURRENCY') { 3 } +preload_app! +threads 5, 16 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..afe399f9 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Start Sidekiq in background +bundle exec sidekiq -C config/sidekiq.yml -e production & + +# Start Puma on port 3000 +exec bundle exec puma -C config/puma_docker.rb