From 4d25dbca2107c8455b4bbad13fb547f433e516f2 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 9 Jan 2025 13:38:13 +0100 Subject: [PATCH] Move some files around --- .devcontainer/Dockerfile | 4 +- .devcontainer/docker-compose.yml | 4 +- app/jobs/visit_suggesting_job.rb | 6 ++- ...70930_remove_points_without_coordinates.rb | 2 +- docker/Dockerfile | 2 +- docker/Dockerfile.dev | 41 --------------- docker/dev-docker-entrypoint.sh | 51 ------------------- docker/docker-compose.production.yml | 29 ++++++----- docker/docker-compose.yml | 10 ++-- ...ker-entrypoint.sh => docker-entrypoint.sh} | 2 +- 10 files changed, 32 insertions(+), 119 deletions(-) delete mode 100644 docker/Dockerfile.dev delete mode 100644 docker/dev-docker-entrypoint.sh rename docker/{prod-docker-entrypoint.sh => docker-entrypoint.sh} (97%) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 39a87c65..a2077946 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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 @@ -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. diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index e0bc7867..56fb8d5f 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -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: @@ -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 diff --git a/app/jobs/visit_suggesting_job.rb b/app/jobs/visit_suggesting_job.rb index 06883b64..b1a3e13d 100644 --- a/app/jobs/visit_suggesting_job.rb +++ b/app/jobs/visit_suggesting_job.rb @@ -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 diff --git a/db/data/20240610170930_remove_points_without_coordinates.rb b/db/data/20240610170930_remove_points_without_coordinates.rb index b8647672..85ef7684 100644 --- a/db/data/20240610170930_remove_points_without_coordinates.rb +++ b/db/data/20240610170930_remove_points_without_coordinates.rb @@ -12,7 +12,7 @@ class RemovePointsWithoutCoordinates < ActiveRecord::Migration[7.1] Rails.logger.info 'Points without coordinates removed.' - BulkStatsCalculatingJob.perform_later(User.pluck(:id)) + BulkStatsCalculatingJob.perform_later end def down diff --git a/docker/Dockerfile b/docker/Dockerfile index 73644a6a..330334bf 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -40,7 +40,7 @@ RUN bundle config set --local path 'vendor/bundle' \ COPY ../. ./ # Copy entrypoint scripts and grant execution permissions -COPY ./docker/prod-docker-entrypoint.sh /usr/local/bin/entrypoint.sh +COPY ./docker/docker-entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh EXPOSE $RAILS_PORT diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev deleted file mode 100644 index ad2336aa..00000000 --- a/docker/Dockerfile.dev +++ /dev/null @@ -1,41 +0,0 @@ -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 TMP_PATH=/tmp/ -ENV RAILS_LOG_TO_STDOUT=true -ENV RAILS_PORT=3000 - -# 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 \ - # gcompat for nokogiri on mac m1 - gcompat \ - && rm -rf /var/cache/apk/* \ - && mkdir -p $APP_PATH - -RUN gem install bundler --version "$BUNDLE_VERSION" \ - && rm -rf $GEM_HOME/cache/* - -# copy entrypoint scripts and grant execution permissions -COPY ./dev-docker-entrypoint.sh /usr/local/bin/dev-entrypoint.sh -COPY ./test-docker-entrypoint.sh /usr/local/bin/test-entrypoint.sh -RUN chmod +x /usr/local/bin/dev-entrypoint.sh && chmod +x /usr/local/bin/test-entrypoint.sh - -# navigate to app directory -WORKDIR $APP_PATH - -EXPOSE $RAILS_PORT - -ENTRYPOINT [ "bundle", "exec" ] diff --git a/docker/dev-docker-entrypoint.sh b/docker/dev-docker-entrypoint.sh deleted file mode 100644 index 90a8ddfd..00000000 --- a/docker/dev-docker-entrypoint.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -unset BUNDLE_PATH -unset BUNDLE_BIN - -set -e - -echo "Environment: $RAILS_ENV" - -# set env var defaults -DATABASE_HOST=${DATABASE_HOST:-"dawarich_db"} -DATABASE_PORT=${DATABASE_PORT:-5432} -DATABASE_USERNAME=${DATABASE_USERNAME:-"postgres"} -DATABASE_PASSWORD=${DATABASE_PASSWORD:-"password"} -DATABASE_NAME=${DATABASE_NAME:-"dawarich_development"} - -# Remove pre-existing puma/passenger server.pid -rm -f $APP_PATH/tmp/pids/server.pid - -# Wait for the database to be ready -until nc -zv $DATABASE_HOST ${DATABASE_PORT:-5432}; do - echo "Waiting for PostgreSQL to be ready..." - sleep 1 -done - -# Install gems -gem update --system 3.6.2 -gem install bundler --version '2.5.21' - -# Create the database -if [ "$(psql "postgres://$DATABASE_USERNAME:$DATABASE_PASSWORD@$DATABASE_HOST:$DATABASE_PORT" -XtAc "SELECT 1 FROM pg_database WHERE datname='$DATABASE_NAME'")" = '1' ]; then - echo "Database $DATABASE_NAME already exists, skipping creation..." -else - echo "Creating database $DATABASE_NAME..." - bundle exec rails db:create -fi - -# Run database migrations -echo "PostgreSQL is ready. Running database migrations..." -bundle exec rails db:migrate - -# Run data migrations -echo "Running DATA migrations..." -bundle exec rake data:migrate - -# Run seeds -echo "Running seeds..." -bundle exec rake db:seed - -# run passed commands -bundle exec ${@} diff --git a/docker/docker-compose.production.yml b/docker/docker-compose.production.yml index fea4fa75..ce5ba6db 100644 --- a/docker/docker-compose.production.yml +++ b/docker/docker-compose.production.yml @@ -8,7 +8,7 @@ services: networks: - dawarich volumes: - - shared_data:/var/shared/redis + - dawarich_redis_data:/var/shared/redis restart: always healthcheck: test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ] @@ -18,10 +18,10 @@ services: timeout: 10s dawarich_db: image: postgres:17-alpine + shm_size: 1G container_name: dawarich_db volumes: - - db_data:/var/lib/postgresql/data - - shared_data:/var/shared + - dawarich_db_data:/var/lib/postgresql/data networks: - dawarich environment: @@ -39,9 +39,9 @@ services: image: dawarich:prod container_name: dawarich_app volumes: - - gem_cache:/usr/local/bundle/gems_app - - public:/var/app/public - - watched:/var/app/tmp/imports/watched + - dawarich_gem_cache_app:/usr/local/bundle/gems + - dawarich_public:/var/app/public + - dawarich_watched:/var/app/tmp/imports/watched networks: - dawarich ports: @@ -99,9 +99,9 @@ services: image: dawarich:prod container_name: dawarich_sidekiq volumes: - - gem_cache:/usr/local/bundle/gems_sidekiq - - public:/var/app/public - - watched:/var/app/tmp/imports/watched + - dawarich_gem_cache_sidekiq:/usr/local/bundle/gems + - dawarich_public:/var/app/public + - dawarich_watched:/var/app/tmp/imports/watched networks: - dawarich stdin_open: true @@ -156,8 +156,9 @@ services: memory: '2G' # Limit memory usage to 2GB volumes: - db_data: - gem_cache: - shared_data: - public: - watched: + dawarich_db_data: + dawarich_redis_data: + dawarich_gem_cache_app: + dawarich_gem_cache_sidekiq: + dawarich_public: + dawarich_watched: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 53586a39..ea7f5789 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -38,7 +38,7 @@ services: timeout: 10s # command: postgres -c config_file=/etc/postgresql/postgresql.conf # Use custom config, uncomment if you want to use a custom config dawarich_app: - image: freikin/dawarich:latest + image: dawarich:prod container_name: dawarich_app volumes: - dawarich_gem_cache_app:/usr/local/bundle/gems @@ -51,8 +51,8 @@ services: # - 9394:9394 # Prometheus exporter, uncomment if needed stdin_open: true tty: true - entrypoint: dev-entrypoint.sh - command: ['bin/dev'] + entrypoint: entrypoint.sh + command: ['bin/rails', 'server', '-p', '3000', '-b', '::'] restart: on-failure environment: RAILS_ENV: development @@ -94,7 +94,7 @@ services: cpus: '0.50' # Limit CPU usage to 50% of one core memory: '2G' # Limit memory usage to 2GB dawarich_sidekiq: - image: freikin/dawarich:latest + image: dawarich:prod container_name: dawarich_sidekiq volumes: - dawarich_gem_cache_sidekiq:/usr/local/bundle/gems @@ -104,7 +104,7 @@ services: - dawarich stdin_open: true tty: true - entrypoint: dev-entrypoint.sh + entrypoint: entrypoint.sh command: ['sidekiq'] restart: on-failure environment: diff --git a/docker/prod-docker-entrypoint.sh b/docker/docker-entrypoint.sh similarity index 97% rename from docker/prod-docker-entrypoint.sh rename to docker/docker-entrypoint.sh index 50ff835c..1fe36928 100644 --- a/docker/prod-docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -5,7 +5,7 @@ unset BUNDLE_BIN set -e -echo "Environment: $RAILS_ENV" +echo "⚠️ Environment: $RAILS_ENV ⚠️" # Parse DATABASE_URL if present, otherwise use individual variables if [ -n "$DATABASE_URL" ]; then