Move some files around

This commit is contained in:
Eugene Burmakin
2025-01-09 13:38:13 +01:00
parent 69af9710f5
commit 4d25dbca21
10 changed files with 32 additions and 119 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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" ]

View File

@@ -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 ${@}

View File

@@ -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:

View File

@@ -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:

View File

@@ -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