diff --git a/Dockerfile.development b/Dockerfile.development deleted file mode 100644 index 97c3b6f..0000000 --- a/Dockerfile.development +++ /dev/null @@ -1,49 +0,0 @@ -# syntax = docker/dockerfile:1 - -# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile -ARG RUBY_VERSION=3.3.5 -FROM ruby:$RUBY_VERSION-slim as base - -# Rails app lives here -WORKDIR /rails - -# Set production environment -ENV RAILS_ENV="development" \ - BUNDLE_PATH="/usr/local/bundle" - -# Throw-away build stage to reduce size of final image -FROM --platform=$TARGETPLATFORM base as build - -# Install packages needed to build gems -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y build-essential git libvips libpq-dev pkg-config nodejs - -# Install application gems -COPY Gemfile Gemfile.lock .ruby-version ./ -RUN bundle install && \ - rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git - -# Copy application code -COPY . . - -# 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 - -# Install packages needed for deployment -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libjemalloc2 libpq-dev libvips wkhtmltopdf nodejs && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives - -# Copy built artifacts: gems, application -COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" -COPY --from=build /rails /rails - -# Entrypoint prepares the application. -ENTRYPOINT ["/rails/bin/docker-entrypoint"] - -# Start the server by default, this can be overwritten at runtime -EXPOSE 3000 -CMD ["bin/rails", "s", "-b", "0.0.0.0"] diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 7ec4917..57567d6 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -1,8 +1,14 @@ #!/bin/bash -e # Enable jemalloc for reduced memory usage and latency. -if [ -f /usr/lib/*/libjemalloc.so.2 ]; then - export LD_PRELOAD="$(echo /usr/lib/*/libjemalloc.so.2) $LD_PRELOAD" +if [ -z "${LD_PRELOAD+x}" ]; then + LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit) + export LD_PRELOAD +fi + +# If running the rails server then create or migrate existing database +if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then + ./bin/rails db:prepare fi exec "${@}" diff --git a/config/application.rb b/config/application.rb index 7ddfced..e256a16 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,7 @@ module OpenGas class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.2 + config.load_defaults 8.0 # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. diff --git a/config/deploy.yml b/config/deploy.yml index 5e6d7cd..7515d65 100644 --- a/config/deploy.yml +++ b/config/deploy.yml @@ -7,13 +7,16 @@ image: baldarn/open-gas # Deploy to these servers. servers: web: - hosts: - - opengas.eu - options: - add-host: host.docker.internal:host-gateway - -# Enable SSL auto certification via Let's Encrypt (and allow for multiple apps on one server). -# Set ssl: false if using something like Cloudflare to terminate SSL (but keep host!). + - opengas.eu + # job: + # hosts: + # - 192.168.0.1 + # cmd: bin/jobs + +# Enable SSL auto certification via Let's Encrypt and allow for multiple apps on a single web server. +# Remove this section when using multiple web servers and ensure you terminate SSL at your load balancer. +# +# Note: If using Cloudflare, set encryption mode in SSL/TLS setting to "Full" to enable CF-to-app encryption. proxy: ssl: true host: opengas.eu @@ -24,15 +27,16 @@ registry: server: ghcr.io username: baldarn - # Always use an access token ratherg than real password when possible. + # Always use an access token rather than real password when possible. password: - KAMAL_REGISTRY_PASSWORD -# Inject ENV variables into containers (secrets come from .env). -# Remember to run `kamal env push` after making changes! +# Inject ENV variables into containers (secrets come from .kamal/secrets). env: + secret: + - RAILS_MASTER_KEY + - APP_VERSION clear: - APP_HOST: opengas.eu # Run the Solid Queue Supervisor inside the web server's Puma process to do jobs. # When you start using multiple servers, you should split out job processing to a dedicated machine. SOLID_QUEUE_IN_PUMA: true @@ -43,13 +47,13 @@ env: # Set number of cores available to the application on each server (default: 1). # WEB_CONCURRENCY: 2 + # Match this to any external database server to configure Active Record correctly + # Use open-gas-db for a db accessory server on same machine via local kamal docker network. + # DB_HOST: 192.168.0.2 + # Log everything from Rails # RAILS_LOG_LEVEL: debug - secret: - - RAILS_MASTER_KEY - - APP_VERSION - # Aliases are triggered with "bin/kamal ". You can overwrite arguments on invocation: # "bin/kamal logs -r job" will tail logs from the first server in the job section. aliases: @@ -64,10 +68,11 @@ aliases: volumes: - "open_gas_storage:/rails/storage" + # Bridge fingerprinted assets, like JS and CSS, between versions to avoid # hitting 404 on in-flight requests. Combines all files from new and old # version inside the asset_path. -asset_path: /rails/public/assets +# asset_path: /rails/public/assets # Configure the image builder. builder: @@ -89,3 +94,25 @@ ssh: # user: app # Use accessory services (secrets come from .kamal/secrets). +# accessories: +# db: +# image: mysql:8.0 +# host: 192.168.0.2 +# # Change to 3306 to expose port to the world instead of just local network. +# port: "127.0.0.1:3306:3306" +# env: +# clear: +# MYSQL_ROOT_HOST: '%' +# secret: +# - MYSQL_ROOT_PASSWORD +# files: +# - config/mysql/production.cnf:/etc/mysql/my.cnf +# - db/production.sql:/docker-entrypoint-initdb.d/setup.sql +# directories: +# - data:/var/lib/mysql +# redis: +# image: redis:7.0 +# host: 192.168.0.2 +# port: 6379 +# directories: +# - data:/data diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb deleted file mode 100644 index e8d0b2a..0000000 --- a/config/initializers/permissions_policy.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. - -# Define an application-wide HTTP permissions policy. For further -# information see: https://developers.google.com/web/updates/2018/06/feature-policy - -# Rails.application.config.permissions_policy do |policy| -# policy.camera :none -# policy.gyroscope :none -# policy.microphone :none -# policy.usb :none -# policy.fullscreen :self -# policy.payment :self, "https://secure.example.com" -# end diff --git a/config/initializers/sqlite3.rb b/config/initializers/sqlite3.rb deleted file mode 100644 index c83163a..0000000 --- a/config/initializers/sqlite3.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module SQLite3Configuration - private - - def configure_connection - super - - return unless @config[:retries] - - retries = self.class.type_cast_config_to_integer(@config[:retries]) - raw_connection.busy_handler do |count| - (count <= retries).tap { |result| sleep count * 0.001 if result } - end - end -end - -ActiveSupport.on_load :active_record do - ActiveSupport.on_load(:active_record_sqlite3adapter) { prepend SQLite3Configuration } -end