Skip to content

Commit

Permalink
Merge pull request #437 from Freika/feature/production_env
Browse files Browse the repository at this point in the history
Add production environment configuration
  • Loading branch information
Freika authored Jan 9, 2025
2 parents 0625a4f + 7766fcb commit ae60a38
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .app_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.21.6
0.22.0
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM ruby:3.3.4-alpine

ENV APP_PATH=/var/app
ENV BUNDLE_VERSION=2.5.9
ENV BUNDLE_VERSION=2.5.21
ENV BUNDLE_PATH=/usr/local/bundle/gems
ENV TMP_PATH=/tmp/
ENV RAILS_LOG_TO_STDOUT=true
Expand All @@ -27,7 +27,7 @@ RUN apk -U add --no-cache \
&& rm -rf /var/cache/apk/* \
&& mkdir -p $APP_PATH

RUN gem update --system 3.5.7 && gem install bundler --version "$BUNDLE_VERSION" \
RUN gem update --system 3.6.2 && gem install bundler --version "$BUNDLE_VERSION" \
&& rm -rf $GEM_HOME/cache/*

# FIXME It would be a good idea to use a other user than root, but this lead to permission error on export and maybe more yet.
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
PROMETHEUS_EXPORTER_PORT: 9394
ENABLE_TELEMETRY: false # More on telemetry: https://dawarich.app/docs/tutorials/telemetry
dawarich_redis:
image: redis:7.0-alpine
image: redis:7.4-alpine
container_name: dawarich_redis
command: redis-server
networks:
Expand All @@ -50,7 +50,7 @@ services:
start_period: 30s
timeout: 10s
dawarich_db:
image: postgres:14.2-alpine
image: postgres:17-alpine
container_name: dawarich_db
volumes:
- dawarich_db_data:/var/lib/postgresql/data
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
file: ./docker/Dockerfile.dev
push: true
tags: freikin/dawarich:latest,freikin/dawarich:${{ github.event.inputs.branch || github.ref_name }}
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

# 0.22.0 - 2025-01-09

⚠️ This release introduces a breaking change. ⚠️

Please read this release notes carefully before upgrading.

Docker-related files were moved to the `docker` directory and some of them were renamed. Before upgrading, study carefully changes in the `docker/docker-compose.yml` file and update your docker-compose file accordingly, so it uses the new files and commands. Copying `docker/docker-compose.yml` blindly may lead to errors.

No volumes were removed or renamed, so with a proper docker-compose file, you should be able to upgrade without any issues. To make it easier comparing your existing docker-compose file with the new one, you may use https://www.diffchecker.com/.

Although `docker-compose.production.yml` was added, it's not being used by default. It's just an example of how to configure Dawarich for production. The default `docker-compose.yml` file is still recommended for running the app.

### Changed

- All docker-related files were moved to the `docker` directory.
- Default memory limit for `dawarich_app` and `dawarich_sidekiq` services was increased to 4GB.
- `dawarich_app` and `dawarich_sidekiq` services now use separate entrypoint scripts.
- Gems (dependency libraries) are now being shipped as part of the Dawarich Docker image.

### Fixed

- Visit suggesting job does nothing if user has no tracked points.
- `BulkStatsCalculationJob` now being called without arguments in the data migration.

### Added

- A proper production Dockerfile, docker-compose and env files.

# 0.21.6 - 2025-01-07

### Changed
Expand Down
41 changes: 0 additions & 41 deletions Dockerfile.dev

This file was deleted.

1 change: 0 additions & 1 deletion app/controllers/api/v1/health_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ def index
render json: { status: 'ok' }
end
end

6 changes: 5 additions & 1 deletion app/jobs/visit_suggesting_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class VisitSuggestingJob < ApplicationJob
def perform(user_ids: [], start_at: 1.day.ago, end_at: Time.current)
users = user_ids.any? ? User.where(id: user_ids) : User.all

users.find_each { Visits::Suggest.new(_1, start_at:, end_at:).call }
users.find_each do |user|
next if user.tracked_points.empty?

Visits::Suggest.new(user, start_at:, end_at:).call
end
end
end
1 change: 0 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ test:
production:
<<: *default
database: <%= ENV['DATABASE_NAME'] || 'dawarich_production' %>
url: <%= ENV['DATABASE_URL'] %>
20 changes: 14 additions & 6 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
config.assets.compile = true

config.assets.content_type = {
geojson: 'application/geo+json'
}

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"
Expand All @@ -53,12 +57,12 @@
# config.assume_ssl = true

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
config.force_ssl = ENV.fetch('APPLICATION_PROTOCOL', 'http').downcase == 'https'

# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
# Direct logs to STDOUT
config.logger = Logger.new($stdout)
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
Expand Down Expand Up @@ -99,4 +103,8 @@
# ]
# Skip DNS rebinding protection for the default health check endpoint.
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',')

config.action_mailer.default_url_options = { host: hosts.first, port: 3000 }
config.hosts.concat(hosts) if hosts.present?
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def up

Rails.logger.info 'Points without coordinates removed.'

BulkStatsCalculatingJob.perform_later(User.pluck(:id))
BulkStatsCalculatingJob.perform_later
end

def down
Expand Down
51 changes: 0 additions & 51 deletions dev-docker-entrypoint.sh

This file was deleted.

21 changes: 0 additions & 21 deletions dev-docker-sidekiq-entrypoint.sh

This file was deleted.

File renamed without changes.
25 changes: 13 additions & 12 deletions Dockerfile → docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM ruby:3.3.4-alpine

ENV APP_PATH=/var/app
ENV BUNDLE_VERSION=2.5.9
ENV BUNDLE_VERSION=2.5.21
ENV BUNDLE_PATH=/usr/local/bundle/gems
ENV TMP_PATH=/tmp/
ENV RAILS_LOG_TO_STDOUT=true
ENV RAILS_PORT=3000

Expand All @@ -21,28 +20,30 @@ RUN apk -U add --no-cache \
tzdata \
less \
yaml-dev \
# gcompat for nokogiri on mac m1
gcompat \
&& rm -rf /var/cache/apk/* \
&& mkdir -p $APP_PATH

RUN gem install bundler --version "$BUNDLE_VERSION" \
# Update gem system and install bundler
RUN gem update --system 3.6.2 \
&& gem install bundler --version "$BUNDLE_VERSION" \
&& rm -rf $GEM_HOME/cache/*

# Navigate to app directory
WORKDIR $APP_PATH

COPY Gemfile Gemfile.lock vendor .ruby-version ./
COPY ../Gemfile ../Gemfile.lock ../vendor ../.ruby-version ./

# Install missing gems
# Install all gems including development and test
RUN bundle config set --local path 'vendor/bundle' \
&& bundle install --jobs 20 --retry 5
&& bundle install --jobs 4 --retry 3

COPY . ./
COPY ../. ./

# Copy entrypoint scripts and grant execution permissions
COPY ./dev-docker-entrypoint.sh /usr/local/bin/dev-entrypoint.sh
RUN chmod +x /usr/local/bin/dev-entrypoint.sh
COPY ./docker/web-entrypoint.sh /usr/local/bin/web-entrypoint.sh
RUN chmod +x /usr/local/bin/web-entrypoint.sh

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

EXPOSE $RAILS_PORT

Expand Down
55 changes: 55 additions & 0 deletions docker/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM ruby:3.3.4-alpine

ENV APP_PATH=/var/app
ENV BUNDLE_VERSION=2.5.21
ENV BUNDLE_PATH=/usr/local/bundle/gems
ENV RAILS_LOG_TO_STDOUT=true
ENV RAILS_PORT=3000
ENV RAILS_ENV=production

# Install dependencies for application
RUN apk -U add --no-cache \
build-base \
git \
postgresql-dev \
postgresql-client \
libxml2-dev \
libxslt-dev \
nodejs \
yarn \
imagemagick \
tzdata \
less \
yaml-dev \
gcompat \
&& mkdir -p $APP_PATH

# Update gem system and install bundler
RUN gem update --system 3.6.2 \
&& gem install bundler --version "$BUNDLE_VERSION" \
&& rm -rf $GEM_HOME/cache/*

WORKDIR $APP_PATH

COPY ../Gemfile ../Gemfile.lock ../vendor ../.ruby-version ./

# Install production gems only
RUN bundle config set --local path 'vendor/bundle' \
&& bundle install --jobs 4 --retry 3 --without development test

COPY ../. ./

# Precompile assets for production
RUN bundle exec rake assets:precompile \
&& rm -rf node_modules tmp/cache

# Copy entrypoint scripts and grant execution permissions
COPY ./docker/web-entrypoint.sh /usr/local/bin/web-entrypoint.sh
RUN chmod +x /usr/local/bin/web-entrypoint.sh

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

EXPOSE $RAILS_PORT

ENTRYPOINT [ "bundle", "exec" ]
Loading

0 comments on commit ae60a38

Please sign in to comment.