diff --git a/.gitignore b/.gitignore index d87f3572d..9172f0fed 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ /public/system/attachments/* /public/system/thumbnails/* /public/ckeditor_assets +/public/assets/ # Ignore Byebug command history file. .byebug_history diff --git a/Dockerfile b/Dockerfile index b485668bf..0db8d3b5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,27 @@ -FROM ruby:2.7.8-buster +FROM ruby:3.3.8-slim AS base + +# Set working directory +WORKDIR /app + +# Set environment variables +ENV RAILS_ENV=production \ + RACK_ENV=production \ + BUNDLE_PATH=/gems \ + BUNDLE_WITHOUT="development test" \ + BUNDLE_BIN=/gems/bin \ + PATH="/gems/bin:$PATH" + +# Install bundler +RUN gem install bundler -v 2.5.22 + + +FROM base AS assets # Install basic Linux packages RUN apt-get update -qq && apt-get install -y \ build-essential \ - libpq-dev \ nodejs \ yarn \ - git \ - curl \ imagemagick \ libvips \ tzdata \ @@ -16,22 +30,7 @@ RUN apt-get update -qq && apt-get install -y \ libffi-dev \ libreadline-dev \ libssl-dev \ - zlib1g-dev \ - libsqlite3-dev \ - sqlite3 - -# Set working directory -WORKDIR /app - -# Set environment variables -ENV RAILS_ENV=production \ - RACK_ENV=production \ - BUNDLE_PATH=/gems \ - BUNDLE_BIN=/gems/bin \ - PATH="/gems/bin:$PATH" - -# Install bundler -RUN gem install bundler -v 2.4.12 + zlib1g-dev # Copy app code and install dependencies COPY . . @@ -41,21 +40,40 @@ RUN bundle install --without development test # These envs are used in the rails application. While they are entirely # unrelated to the docker build process, they are required for the app to run. # Without these build args the asset precompilation will fail. -ARG SECRET_KEY_BASE -ARG AWS_ACCESS_KEY_ID -ARG AWS_SECRET_ACCESS_KEY -ARG AWS_REGION -ARG AWS_S3_BUCKET -ARG SMTP_USERNAME -ARG SMTP_PASSWORD -ARG SMTP_SERVER -ARG SMTP_PORT # Precompile assets (if applicable) -RUN bundle exec rake assets:precompile +RUN SECRET_KEY_BASE=1 bundle exec rake assets:precompile + + +FROM base AS server + +RUN apt-get update -qq && apt-get install --no-install-recommends -y \ + imagemagick \ + libvips \ + tzdata \ + libxml2 \ + libxslt1.1 \ + libffi8 \ + libreadline8 \ + libssl3 \ + zlib1g \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + + + + +# Set working directory +WORKDIR /app + +COPY --from=assets /gems /gems +COPY --from=assets /app/public/assets /app/public/assets + +# Copy app code and install dependencies +COPY . . # Expose port (default Rails) EXPOSE 3000 # Start the server (customize to your app server if needed) -CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] \ No newline at end of file +CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 000000000..6f46cb118 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,4 @@ +/* + *= require_self + *= require awbw + */ diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/awbw.scss similarity index 100% rename from app/assets/stylesheets/application.scss rename to app/assets/stylesheets/awbw.scss diff --git a/bin/yarn b/bin/yarn deleted file mode 100755 index 460dd565b..000000000 --- a/bin/yarn +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env ruby -APP_ROOT = File.expand_path('..', __dir__) -Dir.chdir(APP_ROOT) do - begin - exec "yarnpkg", *ARGV - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end -end diff --git a/config/database.yml b/config/database.yml index d9651954f..8329cfdaa 100644 --- a/config/database.yml +++ b/config/database.yml @@ -14,3 +14,6 @@ test: <<: *base pool: 5 database: awbw_test + +production: + <<: *base diff --git a/config/environments/development.rb b/config/environments/development.rb index 213e04034..f2bce49d0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -50,6 +50,8 @@ # number of complex assets. config.assets.debug = true + config.assets.unknown_asset_fallback = false + # Suppress logger output for asset requests. config.assets.quiet = true diff --git a/config/environments/production.rb b/config/environments/production.rb index bb7ec0fd7..1dfe8dc51 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -20,7 +20,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = true # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass diff --git a/docker-compose.yml b/docker-compose.yml index 54edb6560..1cd917a11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,6 +45,25 @@ services: stdin_open: true restart: unless-stopped + + prod: + profiles: + - production + build: + context: . + dockerfile: Dockerfile + target: server + depends_on: + - database + environment: + DATABASE_URL: trilogy://root@database:3306/awbw_development + RAILS_LOG_TO_STDOUT: "true" + SECRET_KEY_BASE: "foobar" + ports: + - 3030:3000 + + + volumes: mysql-data: