From 9077889b404aeeffc60a33a0f10335107dc325d9 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 23 Jan 2025 14:03:08 +0100 Subject: [PATCH 01/61] Add PostGIS adapter --- Gemfile | 1 + Gemfile.lock | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Gemfile b/Gemfile index 1066cbfa..92c6d14f 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ gem 'lograge' gem 'oj' gem 'pg' gem 'prometheus_exporter' +gem 'activerecord-postgis-adapter', github: 'StoneGod/activerecord-postgis-adapter', branch: 'rails-8' gem 'puma' gem 'pundit' gem 'rails', '~> 8.0' diff --git a/Gemfile.lock b/Gemfile.lock index 43f74521..5460cf07 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +GIT + remote: https://github.com/StoneGod/activerecord-postgis-adapter.git + revision: 147fd43191ef703e2a1b3654f31d9139201a87e8 + branch: rails-8 + specs: + activerecord-postgis-adapter (10.0.1) + activerecord (~> 8.0.0) + rgeo-activerecord (~> 8.0.0) + GIT remote: https://github.com/alexreisner/geocoder.git revision: 04ee2936a30b30a23ded5231d7faf6cf6c27c099 @@ -314,6 +323,10 @@ GEM actionpack (>= 5.2) railties (>= 5.2) rexml (3.3.8) + rgeo (3.0.1) + rgeo-activerecord (8.0.0) + activerecord (>= 7.0) + rgeo (>= 3.0) rspec-core (3.13.2) rspec-support (~> 3.13.0) rspec-expectations (3.13.3) @@ -443,6 +456,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + activerecord-postgis-adapter! bootsnap chartkick data_migrate From 66930a340f28ff44c4d8e3b4c3d3d906394a1cdc Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 23 Jan 2025 15:36:10 +0100 Subject: [PATCH 02/61] Update CHANGELOG.md --- .app_version | 2 +- CHANGELOG.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.app_version b/.app_version index f6de0017..df47809d 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.23.5 +0.23.6 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f117299..1b70a9eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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.23.6 - 2025-01-23 + +### Added + +- Enabled Postgis extension for PostgreSQL. + # 0.23.5 - 2025-01-22 ### Added From 63b92f695f14365e97a41197b0baa35daea70ba5 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 23 Jan 2025 15:53:32 +0100 Subject: [PATCH 03/61] Enable Postgis extension for PostgreSQL --- db/migrate/20250123145155_enable_postgis_extension.rb | 7 +++++++ db/schema.rb | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250123145155_enable_postgis_extension.rb diff --git a/db/migrate/20250123145155_enable_postgis_extension.rb b/db/migrate/20250123145155_enable_postgis_extension.rb new file mode 100644 index 00000000..e9d816dd --- /dev/null +++ b/db/migrate/20250123145155_enable_postgis_extension.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class EnablePostgisExtension < ActiveRecord::Migration[8.0] + def change + enable_extension 'postgis' + end +end diff --git a/db/schema.rb b/db/schema.rb index ebf1007e..f865b48d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_01_20_154555) do +ActiveRecord::Schema[8.0].define(version: 2025_01_23_145155) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" + enable_extension "postgis" create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false @@ -177,6 +178,14 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_20_154555) do t.index ["visit_id"], name: "index_points_on_visit_id" end + create_table "spatial_ref_sys", primary_key: "srid", id: :integer, default: nil, force: :cascade do |t| + t.string "auth_name", limit: 256 + t.integer "auth_srid" + t.string "srtext", limit: 2048 + t.string "proj4text", limit: 2048 + t.check_constraint "srid > 0 AND srid <= 998999", name: "spatial_ref_sys_srid_check" + end + create_table "stats", force: :cascade do |t| t.integer "year", null: false t.integer "month", null: false From 774de9991b71b099a75d0bb5b55170ad0342fd48 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 23 Jan 2025 16:03:21 +0100 Subject: [PATCH 04/61] Add tracks model --- app/models/track.rb | 7 +++++++ app/models/user.rb | 3 ++- config/database.yml | 2 +- db/migrate/20250123145954_create_tracks.rb | 14 ++++++++++++++ db/schema.rb | 21 ++++++++++++--------- spec/factories/tracks.rb | 10 ++++++++++ spec/models/track_spec.rb | 15 +++++++++++++++ spec/models/user_spec.rb | 1 + 8 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 app/models/track.rb create mode 100644 db/migrate/20250123145954_create_tracks.rb create mode 100644 spec/factories/tracks.rb create mode 100644 spec/models/track_spec.rb diff --git a/app/models/track.rb b/app/models/track.rb new file mode 100644 index 00000000..41e673b4 --- /dev/null +++ b/app/models/track.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Track < ApplicationRecord + belongs_to :user + + validates :path, :started_at, :ended_at, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb index b3112130..90ff2fb0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,7 +13,8 @@ class User < ApplicationRecord has_many :visits, dependent: :destroy has_many :points, through: :imports has_many :places, through: :visits - has_many :trips, dependent: :destroy + has_many :trips, dependent: :destroy + has_many :tracks, dependent: :destroy after_create :create_api_key before_save :strip_trailing_slashes diff --git a/config/database.yml b/config/database.yml index fca7a51c..79ad2b3b 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,5 +1,5 @@ default: &default - adapter: postgresql + adapter: postgis encoding: unicode database: <%= ENV['DATABASE_NAME'] %> username: <%= ENV['DATABASE_USERNAME'] %> diff --git a/db/migrate/20250123145954_create_tracks.rb b/db/migrate/20250123145954_create_tracks.rb new file mode 100644 index 00000000..168d2c12 --- /dev/null +++ b/db/migrate/20250123145954_create_tracks.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class CreateTracks < ActiveRecord::Migration[8.0] + def change + create_table :tracks do |t| + t.datetime :started_at, null: false + t.datetime :ended_at, null: false + t.references :user, null: false, foreign_key: true + t.line_string :path, srid: 3785, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f865b48d..a85c60bd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_01_23_145155) do +ActiveRecord::Schema[8.0].define(version: 2025_01_23_145954) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" enable_extension "postgis" @@ -178,14 +178,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_145155) do t.index ["visit_id"], name: "index_points_on_visit_id" end - create_table "spatial_ref_sys", primary_key: "srid", id: :integer, default: nil, force: :cascade do |t| - t.string "auth_name", limit: 256 - t.integer "auth_srid" - t.string "srtext", limit: 2048 - t.string "proj4text", limit: 2048 - t.check_constraint "srid > 0 AND srid <= 998999", name: "spatial_ref_sys_srid_check" - end - create_table "stats", force: :cascade do |t| t.integer "year", null: false t.integer "month", null: false @@ -201,6 +193,16 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_145155) do t.index ["year"], name: "index_stats_on_year" end + create_table "tracks", force: :cascade do |t| + t.datetime "started_at", null: false + t.datetime "ended_at", null: false + t.bigint "user_id", null: false + t.geometry "path", limit: {:srid=>3785, :type=>"line_string"}, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_tracks_on_user_id" + end + create_table "trips", force: :cascade do |t| t.string "name", null: false t.datetime "started_at", null: false @@ -261,6 +263,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_145155) do add_foreign_key "points", "users" add_foreign_key "points", "visits" add_foreign_key "stats", "users" + add_foreign_key "tracks", "users" add_foreign_key "trips", "users" add_foreign_key "visits", "areas" add_foreign_key "visits", "places" diff --git a/spec/factories/tracks.rb b/spec/factories/tracks.rb new file mode 100644 index 00000000..32603460 --- /dev/null +++ b/spec/factories/tracks.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :track do + started_at { DateTime.new(2025, 1, 23, 15, 59, 55) } + ended_at { DateTime.new(2025, 1, 23, 16, 0, 0) } + user + path { 'LINESTRING(0 0, 1 1, 2 2)' } + end +end diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb new file mode 100644 index 00000000..051b8ae8 --- /dev/null +++ b/spec/models/track_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Track, type: :model do + describe 'validations' do + it { is_expected.to validate_presence_of(:path) } + it { is_expected.to validate_presence_of(:started_at) } + it { is_expected.to validate_presence_of(:ended_at) } + end + + describe 'associations' do + it { is_expected.to belong_to(:user) } + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 398e436f..a9ce1d1e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -14,6 +14,7 @@ RSpec.describe User, type: :model do it { is_expected.to have_many(:visits).dependent(:destroy) } it { is_expected.to have_many(:places).through(:visits) } it { is_expected.to have_many(:trips).dependent(:destroy) } + it { is_expected.to have_many(:tracks).dependent(:destroy) } end describe 'callbacks' do From 7db7fb17d55d490ab1ad6b3b8849b80c91c3b11c Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 12:01:54 +0100 Subject: [PATCH 05/61] Add path to trips --- Gemfile | 1 + Gemfile.lock | 1 + .../controllers/trips_controller.js | 26 +++++++++++-------- app/jobs/trips/create_path_job.rb | 10 +++++++ app/models/trip.rb | 6 +++++ app/services/tracks/build_path.rb | 21 +++++++++++++++ app/views/trips/show.html.erb | 1 + config/initializers/03_dawarich_settings.rb | 8 ++++++ .../20250123151849_create_paths_for_trips.rb | 10 +++++++ db/migrate/20250123145954_create_tracks.rb | 2 +- .../20250123151657_add_path_to_trips.rb | 7 +++++ db/schema.rb | 5 ++-- spec/jobs/trips/create_path_job_spec.rb | 5 ++++ 13 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 app/jobs/trips/create_path_job.rb create mode 100644 app/services/tracks/build_path.rb create mode 100644 db/data/20250123151849_create_paths_for_trips.rb create mode 100644 db/migrate/20250123151657_add_path_to_trips.rb create mode 100644 spec/jobs/trips/create_path_job_spec.rb diff --git a/Gemfile b/Gemfile index 92c6d14f..592c2fd3 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem 'activerecord-postgis-adapter', github: 'StoneGod/activerecord-postgis-adapt gem 'puma' gem 'pundit' gem 'rails', '~> 8.0' +gem 'rgeo' gem 'rswag-api' gem 'rswag-ui' gem 'shrine', '~> 3.6' diff --git a/Gemfile.lock b/Gemfile.lock index 5460cf07..8407dd3a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -484,6 +484,7 @@ DEPENDENCIES pundit rails (~> 8.0) redis + rgeo rspec-rails rswag-api rswag-specs diff --git a/app/javascript/controllers/trips_controller.js b/app/javascript/controllers/trips_controller.js index 602c04be..f512a208 100644 --- a/app/javascript/controllers/trips_controller.js +++ b/app/javascript/controllers/trips_controller.js @@ -1,17 +1,21 @@ import { Controller } from "@hotwired/stimulus" import L from "leaflet" -import { osmMapLayer } from "../maps/layers" +import { + osmMapLayer, + osmHotMapLayer, + OPNVMapLayer, + openTopoMapLayer, + cyclOsmMapLayer, + esriWorldStreetMapLayer, + esriWorldTopoMapLayer, + esriWorldImageryMapLayer, + esriWorldGrayCanvasMapLayer +} from "../maps/layers" import { createPopupContent } from "../maps/popups" -import { osmHotMapLayer } from "../maps/layers" -import { OPNVMapLayer } from "../maps/layers" -import { openTopoMapLayer } from "../maps/layers" -import { cyclOsmMapLayer } from "../maps/layers" -import { esriWorldStreetMapLayer } from "../maps/layers" -import { esriWorldTopoMapLayer } from "../maps/layers" -import { esriWorldImageryMapLayer } from "../maps/layers" -import { esriWorldGrayCanvasMapLayer } from "../maps/layers" -import { fetchAndDisplayPhotos } from '../maps/helpers'; -import { showFlashMessage } from "../maps/helpers"; +import { + fetchAndDisplayPhotos, + showFlashMessage +} from '../maps/helpers'; export default class extends Controller { static targets = ["container", "startedAt", "endedAt"] diff --git a/app/jobs/trips/create_path_job.rb b/app/jobs/trips/create_path_job.rb new file mode 100644 index 00000000..f36fa7cd --- /dev/null +++ b/app/jobs/trips/create_path_job.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class Trips::CreatePathJob < ApplicationJob + queue_as :default + + def perform(trip_id) + trip = Trip.find(trip_id) + trip.create_path! + end +end diff --git a/app/models/trip.rb b/app/models/trip.rb index 4a2b0302..00c2774a 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -9,6 +9,12 @@ class Trip < ApplicationRecord before_save :calculate_distance + def create_path! + self.path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call + + save! + end + def points user.tracked_points.where(timestamp: started_at.to_i..ended_at.to_i).order(:timestamp) end diff --git a/app/services/tracks/build_path.rb b/app/services/tracks/build_path.rb new file mode 100644 index 00000000..4feaf49c --- /dev/null +++ b/app/services/tracks/build_path.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class Tracks::BuildPath + def initialize(coordinates) + @coordinates = coordinates + end + + def call + factory.line_string( + coordinates.map { |point| factory.point(point[1].to_f.round(5), point[0].to_f.round(5)) } + ) + end + + private + + attr_reader :coordinates + + def factory + @factory ||= RGeo::Geographic.spherical_factory(srid: 3857) + end +end diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index f399eb3f..9d6dc4ee 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -25,6 +25,7 @@ data-api_key="<%= current_user.api_key %>" data-user_settings="<%= current_user.settings.to_json %>" data-coordinates="<%= @coordinates.to_json %>" + data-path="<%= @trip.path.to_json %>" data-timezone="<%= Rails.configuration.time_zone %>">
diff --git a/config/initializers/03_dawarich_settings.rb b/config/initializers/03_dawarich_settings.rb index 87cf4817..451ed716 100644 --- a/config/initializers/03_dawarich_settings.rb +++ b/config/initializers/03_dawarich_settings.rb @@ -17,5 +17,13 @@ class DawarichSettings def geoapify_enabled? @geoapify_enabled ||= GEOAPIFY_API_KEY.present? end + + def meters_between_tracks + @meters_between_tracks ||= 300 + end + + def minutes_between_tracks + @minutes_between_tracks ||= 20 + end end end diff --git a/db/data/20250123151849_create_paths_for_trips.rb b/db/data/20250123151849_create_paths_for_trips.rb new file mode 100644 index 00000000..6abcfff4 --- /dev/null +++ b/db/data/20250123151849_create_paths_for_trips.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class CreatePathsForTrips < ActiveRecord::Migration[8.0] + def up + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20250123145954_create_tracks.rb b/db/migrate/20250123145954_create_tracks.rb index 168d2c12..35c6afa1 100644 --- a/db/migrate/20250123145954_create_tracks.rb +++ b/db/migrate/20250123145954_create_tracks.rb @@ -6,7 +6,7 @@ class CreateTracks < ActiveRecord::Migration[8.0] t.datetime :started_at, null: false t.datetime :ended_at, null: false t.references :user, null: false, foreign_key: true - t.line_string :path, srid: 3785, null: false + t.line_string :path, srid: 3857, null: false t.timestamps end diff --git a/db/migrate/20250123151657_add_path_to_trips.rb b/db/migrate/20250123151657_add_path_to_trips.rb new file mode 100644 index 00000000..a5f121e7 --- /dev/null +++ b/db/migrate/20250123151657_add_path_to_trips.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPathToTrips < ActiveRecord::Migration[8.0] + def change + add_column :trips, :path, :line_string, srid: 3857 + end +end diff --git a/db/schema.rb b/db/schema.rb index a85c60bd..7e9cca52 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_01_23_145954) do +ActiveRecord::Schema[8.0].define(version: 2025_01_23_151657) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" enable_extension "postgis" @@ -197,7 +197,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_145954) do t.datetime "started_at", null: false t.datetime "ended_at", null: false t.bigint "user_id", null: false - t.geometry "path", limit: {:srid=>3785, :type=>"line_string"}, null: false + t.geometry "path", limit: {:srid=>3857, :type=>"line_string"}, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["user_id"], name: "index_tracks_on_user_id" @@ -211,6 +211,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_145954) do t.bigint "user_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.geometry "path", limit: {:srid=>3857, :type=>"line_string"} t.index ["user_id"], name: "index_trips_on_user_id" end diff --git a/spec/jobs/trips/create_path_job_spec.rb b/spec/jobs/trips/create_path_job_spec.rb new file mode 100644 index 00000000..1dd711ef --- /dev/null +++ b/spec/jobs/trips/create_path_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Trips::CreatePathJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 1e7efbc9afbb8ed89cdd252a802f24386f6884a7 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 14:54:10 +0100 Subject: [PATCH 06/61] Render trips using precalculated paths instead of list of coordinates --- CHANGELOG.md | 2 + app/controllers/trips_controller.rb | 5 -- .../controllers/trips_controller.js | 51 ++++++++++++++----- app/views/trips/show.html.erb | 1 - 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b70a9eb..e66d12ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Enabled Postgis extension for PostgreSQL. +- Trips are now store their paths in the database independently of the points. +- Trips are now being rendered on the map using their precalculated paths instead of list of coordinates. # 0.23.5 - 2025-01-22 diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 2a9a26d2..038d4842 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -10,11 +10,6 @@ class TripsController < ApplicationController end def show - @coordinates = @trip.points.pluck( - :latitude, :longitude, :battery, :altitude, :timestamp, :velocity, :id, - :country - ).map { [_1.to_f, _2.to_f, _3.to_s, _4.to_s, _5.to_s, _6.to_s, _7.to_s, _8.to_s] } - @photo_previews = Rails.cache.fetch("trip_photos_#{@trip.id}", expires_in: 1.day) do @trip.photo_previews end diff --git a/app/javascript/controllers/trips_controller.js b/app/javascript/controllers/trips_controller.js index f512a208..c40b1426 100644 --- a/app/javascript/controllers/trips_controller.js +++ b/app/javascript/controllers/trips_controller.js @@ -27,9 +27,9 @@ export default class extends Controller { } console.log("Trips controller connected") - this.coordinates = JSON.parse(this.containerTarget.dataset.coordinates) + this.apiKey = this.containerTarget.dataset.api_key - this.userSettings = JSON.parse(this.containerTarget.dataset.user_settings) + this.userSettings = JSON.parse(this.containerTarget.dataset.user_settings || '{}') this.timezone = this.containerTarget.dataset.timezone this.distanceUnit = this.containerTarget.dataset.distance_unit @@ -46,16 +46,12 @@ export default class extends Controller { // Move map initialization to separate method initializeMap() { // Initialize layer groups - this.markersLayer = L.layerGroup() this.polylinesLayer = L.layerGroup() this.photoMarkers = L.layerGroup() // Set default center and zoom for world view - const hasValidCoordinates = this.coordinates && Array.isArray(this.coordinates) && this.coordinates.length > 0 - const center = hasValidCoordinates - ? [this.coordinates[0][0], this.coordinates[0][1]] - : [20, 0] // Roughly centers the world map - const zoom = hasValidCoordinates ? 14 : 2 + const center = [20, 0] // Roughly centers the world map + const zoom = 2 // Initialize map this.map = L.map(this.containerTarget).setView(center, zoom) @@ -72,7 +68,6 @@ export default class extends Controller { }).addTo(this.map) const overlayMaps = { - "Points": this.markersLayer, "Route": this.polylinesLayer, "Photos": this.photoMarkers } @@ -116,6 +111,27 @@ export default class extends Controller { this.addPolyline() this.fitMapToBounds() } + + // After map initialization, add the path if it exists + if (this.containerTarget.dataset.path) { + const pathData = this.containerTarget.dataset.path.replace(/^"|"$/g, ''); // Remove surrounding quotes + const coordinates = this.parseLineString(pathData); + + const polyline = L.polyline(coordinates, { + color: 'blue', + opacity: 0.8, + weight: 3, + zIndexOffset: 400 + }); + + polyline.addTo(this.polylinesLayer); + this.polylinesLayer.addTo(this.map); + + // Fit the map to the polyline bounds + if (coordinates.length > 0) { + this.map.fitBounds(polyline.getBounds(), { padding: [50, 50] }); + } + } } disconnect() { @@ -153,9 +169,6 @@ export default class extends Controller { const popupContent = createPopupContent(coord, this.timezone, this.distanceUnit) marker.bindPopup(popupContent) - - // Add to markers layer instead of directly to map - marker.addTo(this.markersLayer) }) } @@ -191,7 +204,6 @@ export default class extends Controller { ]).sort((a, b) => a[4] - b[4]); // Clear existing layers - this.markersLayer.clearLayers() this.polylinesLayer.clearLayers() this.photoMarkers.clearLayers() @@ -202,4 +214,17 @@ export default class extends Controller { this.fitMapToBounds() } } + + // Add this method to parse the LineString format + parseLineString(lineString) { + // Remove LINESTRING and parentheses, then split into coordinate pairs + const coordsString = lineString.replace('LINESTRING (', '').replace(')', ''); + const coords = coordsString.split(', '); + + // Convert each coordinate pair to [lat, lng] format + return coords.map(coord => { + const [lng, lat] = coord.split(' ').map(Number); + return [lat, lng]; // Swap to lat, lng for Leaflet + }); + } } diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index 9d6dc4ee..44a4ce53 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -24,7 +24,6 @@ data-distance_unit="<%= DISTANCE_UNIT %>" data-api_key="<%= current_user.api_key %>" data-user_settings="<%= current_user.settings.to_json %>" - data-coordinates="<%= @coordinates.to_json %>" data-path="<%= @trip.path.to_json %>" data-timezone="<%= Rails.configuration.time_zone %>">
From 380dd9235d711db77ae61d3fa4964f8e244dd486 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 15:03:57 +0100 Subject: [PATCH 07/61] Calculate path and distance before saving trip --- app/assets/stylesheets/actiontext.css | 3 ++- app/javascript/controllers/datetime_controller.js | 4 ++++ app/javascript/controllers/trips_controller.js | 7 ++++++- app/models/trip.rb | 7 ++++--- app/views/trips/_form.html.erb | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/actiontext.css b/app/assets/stylesheets/actiontext.css index b849676e..ae5522ab 100644 --- a/app/assets/stylesheets/actiontext.css +++ b/app/assets/stylesheets/actiontext.css @@ -40,6 +40,7 @@ background-color: white !important; } -.trix-content { +.trix-content-editor { min-height: 10rem; + width: 100%; } diff --git a/app/javascript/controllers/datetime_controller.js b/app/javascript/controllers/datetime_controller.js index 04c9061b..b56f07e3 100644 --- a/app/javascript/controllers/datetime_controller.js +++ b/app/javascript/controllers/datetime_controller.js @@ -1,3 +1,7 @@ +// This controller is being used on: +// - trips/new +// - trips/edit + import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/javascript/controllers/trips_controller.js b/app/javascript/controllers/trips_controller.js index c40b1426..1d2e8c7e 100644 --- a/app/javascript/controllers/trips_controller.js +++ b/app/javascript/controllers/trips_controller.js @@ -1,3 +1,8 @@ +// This controller is being used on: +// - trips/show +// - trips/edit +// - trips/new + import { Controller } from "@hotwired/stimulus" import L from "leaflet" import { @@ -192,7 +197,7 @@ export default class extends Controller { this.map.fitBounds(bounds, { padding: [50, 50] }) } - // Add this new method to update coordinates and refresh the map + // Update coordinates and refresh the map updateMapWithCoordinates(newCoordinates) { // Transform the coordinates to match the expected format this.coordinates = newCoordinates.map(point => [ diff --git a/app/models/trip.rb b/app/models/trip.rb index 00c2774a..4043e8c7 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -7,12 +7,13 @@ class Trip < ApplicationRecord validates :name, :started_at, :ended_at, presence: true - before_save :calculate_distance + before_save :create_path! def create_path! - self.path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call + trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call + distance = calculate_distance - save! + update_columns(path: trip_path, distance: distance) # Avoids recursion with `after_save` end def points diff --git a/app/views/trips/_form.html.erb b/app/views/trips/_form.html.erb index cf5518ff..40dc57e3 100644 --- a/app/views/trips/_form.html.erb +++ b/app/views/trips/_form.html.erb @@ -62,7 +62,7 @@
<%= form.label :notes %> - <%= form.rich_text_area :notes %> + <%= form.rich_text_area :notes, class: 'trix-content-editor' %>
From 401ac8ca31e7acc677b9c38cd4510fac276e4a22 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 15:19:05 +0100 Subject: [PATCH 08/61] Use path instead of coordinates on trips#index --- .../controllers/trip_map_controller.js | 76 +++++++++++++++---- app/views/trips/_trip.html.erb | 2 +- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/app/javascript/controllers/trip_map_controller.js b/app/javascript/controllers/trip_map_controller.js index b2a18bfb..1bbdc207 100644 --- a/app/javascript/controllers/trip_map_controller.js +++ b/app/javascript/controllers/trip_map_controller.js @@ -1,10 +1,13 @@ +// This controller is being used on: +// - trips/index + import { Controller } from "@hotwired/stimulus" import L from "leaflet" export default class extends Controller { static values = { tripId: Number, - coordinates: Array, + path: String, apiKey: String, userSettings: Object, timezone: String, @@ -12,6 +15,8 @@ export default class extends Controller { } connect() { + console.log("TripMap controller connected") + setTimeout(() => { this.initializeMap() }, 100) @@ -23,7 +28,7 @@ export default class extends Controller { zoomControl: false, dragging: false, scrollWheelZoom: false, - attributionControl: true // Disable default attribution control + attributionControl: true }) // Add the tile layer @@ -33,24 +38,69 @@ export default class extends Controller { }).addTo(this.map) // If we have coordinates, show the route - if (this.hasCoordinatesValue && this.coordinatesValue.length > 0) { + if (this.hasPathValue && this.pathValue) { this.showRoute() + } else { + console.log("No path value available") } } showRoute() { - const points = this.coordinatesValue.map(coord => [coord[0], coord[1]]) + const points = this.parseLineString(this.pathValue) - const polyline = L.polyline(points, { - color: 'blue', - opacity: 0.8, - weight: 3, - zIndexOffset: 400 - }).addTo(this.map) + // Only create polyline if we have points + if (points.length > 0) { + const polyline = L.polyline(points, { + color: 'blue', + opacity: 0.8, + weight: 3, + zIndexOffset: 400 + }) - this.map.fitBounds(polyline.getBounds(), { - padding: [20, 20] - }) + // Add the polyline to the map + polyline.addTo(this.map) + + // Fit the map bounds + this.map.fitBounds(polyline.getBounds(), { + padding: [20, 20] + }) + } else { + console.error("No valid points to create polyline") + } + } + + parseLineString(linestring) { + try { + // Remove 'LINESTRING (' from start and ')' from end + const coordsString = linestring + .replace(/LINESTRING\s*\(/, '') // Remove LINESTRING and opening parenthesis + .replace(/\)$/, '') // Remove closing parenthesis + .trim() // Remove any leading/trailing whitespace + + // Split into coordinate pairs and parse + const points = coordsString.split(',').map(pair => { + // Clean up any extra whitespace and remove any special characters + const cleanPair = pair.trim().replace(/[()"\s]+/g, ' ') + const [lng, lat] = cleanPair.split(' ').filter(Boolean).map(Number) + + // Validate the coordinates + if (isNaN(lat) || isNaN(lng) || !lat || !lng) { + console.error("Invalid coordinates:", cleanPair) + return null + } + + return [lat, lng] // Leaflet uses [lat, lng] order + }).filter(point => point !== null) // Remove any invalid points + + // Validate we have points before returning + if (points.length === 0) { + return [] + } + + return points + } catch (error) { + return [] + } } disconnect() { diff --git a/app/views/trips/_trip.html.erb b/app/views/trips/_trip.html.erb index e0b14ba8..f7a198b6 100644 --- a/app/views/trips/_trip.html.erb +++ b/app/views/trips/_trip.html.erb @@ -13,7 +13,7 @@ class="rounded-lg z-0" data-controller="trip-map" data-trip-map-trip-id-value="<%= trip.id %>" - data-trip-map-coordinates-value="<%= trip.points.pluck(:latitude, :longitude, :battery, :altitude, :timestamp, :velocity, :id, :country).to_json %>" + data-trip-map-path-value="<%= trip.path.to_json %>" data-trip-map-api-key-value="<%= current_user.api_key %>" data-trip-map-user-settings-value="<%= current_user.settings.to_json %>" data-trip-map-timezone-value="<%= Rails.configuration.time_zone %>" From 9c102c1de8ccc6278e9e63341c2b581cd27f6777 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 15:22:46 +0100 Subject: [PATCH 09/61] Fix rendering polyline on trip editing page --- app/views/trips/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/trips/_form.html.erb b/app/views/trips/_form.html.erb index 40dc57e3..b70c5704 100644 --- a/app/views/trips/_form.html.erb +++ b/app/views/trips/_form.html.erb @@ -20,7 +20,7 @@ data-distance_unit="<%= DISTANCE_UNIT %>" data-api_key="<%= current_user.api_key %>" data-user_settings="<%= current_user.settings.to_json %>" - data-coordinates="<%= @coordinates.to_json %>" + data-path="<%= trip.path.to_json %>" data-timezone="<%= Rails.configuration.time_zone %>">
From 6e9c981329794a0486a9afedc5868bd9409f5812 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 15:35:35 +0100 Subject: [PATCH 10/61] Fix photos fetching with trip dates --- .../controllers/trips_controller.js | 36 +++++++++++++++---- app/views/trips/_form.html.erb | 2 ++ app/views/trips/show.html.erb | 2 ++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/javascript/controllers/trips_controller.js b/app/javascript/controllers/trips_controller.js index 1d2e8c7e..974feb30 100644 --- a/app/javascript/controllers/trips_controller.js +++ b/app/javascript/controllers/trips_controller.js @@ -43,7 +43,6 @@ export default class extends Controller { // Add event listener for coordinates updates this.element.addEventListener('coordinates-updated', (event) => { - console.log("Coordinates updated:", event.detail.coordinates) this.updateMapWithCoordinates(event.detail.coordinates) }) } @@ -84,6 +83,15 @@ export default class extends Controller { this.map.on('overlayadd', (e) => { if (e.name !== 'Photos') return; + const startedAt = this.element.dataset.started_at; + const endedAt = this.element.dataset.ended_at; + + console.log('Dataset values:', { + startedAt, + endedAt, + path: this.element.dataset.path + }); + if ((!this.userSettings.immich_url || !this.userSettings.immich_api_key) && (!this.userSettings.photoprism_url || !this.userSettings.photoprism_api_key)) { showFlashMessage( 'error', @@ -92,13 +100,26 @@ export default class extends Controller { return; } - if (!this.coordinates?.length) return; + // Try to get dates from coordinates first, then fall back to path data + let startDate, endDate; - const firstCoord = this.coordinates[0]; - const lastCoord = this.coordinates[this.coordinates.length - 1]; - - const startDate = new Date(firstCoord[4] * 1000).toISOString().split('T')[0]; - const endDate = new Date(lastCoord[4] * 1000).toISOString().split('T')[0]; + if (this.coordinates?.length) { + const firstCoord = this.coordinates[0]; + const lastCoord = this.coordinates[this.coordinates.length - 1]; + startDate = new Date(firstCoord[4] * 1000).toISOString().split('T')[0]; + endDate = new Date(lastCoord[4] * 1000).toISOString().split('T')[0]; + } else if (startedAt && endedAt) { + // Parse the dates and format them correctly + startDate = new Date(startedAt).toISOString().split('T')[0]; + endDate = new Date(endedAt).toISOString().split('T')[0]; + } else { + console.log('No date range available for photos'); + showFlashMessage( + 'error', + 'No date range available for photos. Please ensure the trip has start and end dates.' + ); + return; + } fetchAndDisplayPhotos({ map: this.map, @@ -174,6 +195,7 @@ export default class extends Controller { const popupContent = createPopupContent(coord, this.timezone, this.distanceUnit) marker.bindPopup(popupContent) + marker.addTo(this.polylinesLayer) }) } diff --git a/app/views/trips/_form.html.erb b/app/views/trips/_form.html.erb index b70c5704..847c2df2 100644 --- a/app/views/trips/_form.html.erb +++ b/app/views/trips/_form.html.erb @@ -21,6 +21,8 @@ data-api_key="<%= current_user.api_key %>" data-user_settings="<%= current_user.settings.to_json %>" data-path="<%= trip.path.to_json %>" + data-started_at="<%= trip.started_at %>" + data-ended_at="<%= trip.ended_at %>" data-timezone="<%= Rails.configuration.time_zone %>"> diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index 44a4ce53..f4709aa5 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -25,6 +25,8 @@ data-api_key="<%= current_user.api_key %>" data-user_settings="<%= current_user.settings.to_json %>" data-path="<%= @trip.path.to_json %>" + data-started_at="<%= @trip.started_at %>" + data-ended_at="<%= @trip.ended_at %>" data-timezone="<%= Rails.configuration.time_zone %>">
From 01275d0d2e39490f452bd02876ea19589b474065 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 15:58:44 +0100 Subject: [PATCH 11/61] Add some tests --- app/models/trip.rb | 4 +-- .../20250123151849_create_paths_for_trips.rb | 3 ++ spec/factories/trips.rb | 2 ++ spec/jobs/trips/create_path_job_spec.rb | 20 ++++++++++- spec/models/trip_spec.rb | 4 +++ spec/services/tracks/build_path_spec.rb | 35 +++++++++++++++++++ 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 spec/services/tracks/build_path_spec.rb diff --git a/app/models/trip.rb b/app/models/trip.rb index 4043e8c7..cd4f7225 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -11,9 +11,9 @@ class Trip < ApplicationRecord def create_path! trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call - distance = calculate_distance - update_columns(path: trip_path, distance: distance) # Avoids recursion with `after_save` + self.distance = calculate_distance + self.path = trip_path end def points diff --git a/db/data/20250123151849_create_paths_for_trips.rb b/db/data/20250123151849_create_paths_for_trips.rb index 6abcfff4..c78cffff 100644 --- a/db/data/20250123151849_create_paths_for_trips.rb +++ b/db/data/20250123151849_create_paths_for_trips.rb @@ -2,6 +2,9 @@ class CreatePathsForTrips < ActiveRecord::Migration[8.0] def up + Trip.find_each do |trip| + Trips::CreatePathJob.perform_later(trip.id) + end end def down diff --git a/spec/factories/trips.rb b/spec/factories/trips.rb index 4ef4041a..5986e882 100644 --- a/spec/factories/trips.rb +++ b/spec/factories/trips.rb @@ -7,6 +7,8 @@ FactoryBot.define do started_at { DateTime.new(2024, 11, 27, 17, 16, 21) } ended_at { DateTime.new(2024, 11, 29, 17, 16, 21) } notes { FFaker::Lorem.sentence } + distance { 100 } + path { 'LINESTRING(1 1, 2 2, 3 3)' } trait :with_points do after(:build) do |trip| diff --git a/spec/jobs/trips/create_path_job_spec.rb b/spec/jobs/trips/create_path_job_spec.rb index 1dd711ef..60d288e3 100644 --- a/spec/jobs/trips/create_path_job_spec.rb +++ b/spec/jobs/trips/create_path_job_spec.rb @@ -1,5 +1,23 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Trips::CreatePathJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" + let!(:trip) { create(:trip, :with_points) } + let(:points) { trip.points } + let(:trip_path) do + "LINESTRING (#{points.map do |point| + "#{point.longitude.to_f.round(5)} #{point.latitude.to_f.round(5)}" + end.join(', ')})" + end + + before do + trip.update(path: nil, distance: nil) + end + + it 'creates a path for a trip' do + described_class.perform_now(trip.id) + + expect(trip.reload.path.to_s).to eq(trip_path) + end end diff --git a/spec/models/trip_spec.rb b/spec/models/trip_spec.rb index 032185bd..f56daf20 100644 --- a/spec/models/trip_spec.rb +++ b/spec/models/trip_spec.rb @@ -21,6 +21,10 @@ RSpec.describe Trip, type: :model do it 'sets the distance' do expect(trip.distance).to eq(calculated_distance) end + + it 'sets the path' do + expect(trip.path).to be_present + end end describe '#countries' do diff --git a/spec/services/tracks/build_path_spec.rb b/spec/services/tracks/build_path_spec.rb new file mode 100644 index 00000000..1d2db10a --- /dev/null +++ b/spec/services/tracks/build_path_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Tracks::BuildPath do + describe '#call' do + let(:coordinates) do + [ + [45.123456, -122.654321], # [lat, lng] + [45.234567, -122.765432], + [45.345678, -122.876543] + ] + end + + let(:service) { described_class.new(coordinates) } + let(:result) { service.call } + + it 'returns an RGeo::Geographic::SphericalLineString' do + expect(result).to be_a(RGeo::Geographic::SphericalLineStringImpl) + end + + it 'creates a line string with the correct number of points' do + expect(result.num_points).to eq(coordinates.length) + end + + it 'correctly converts coordinates to points with rounded values' do + points = result.points + + coordinates.each_with_index do |(lat, lng), index| + expect(points[index].x).to eq(lng.to_f.round(5)) + expect(points[index].y).to eq(lat.to_f.round(5)) + end + end + end +end From 5bd6a6c072935d6392e270ff5283b660307f8392 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 24 Jan 2025 16:37:28 +0100 Subject: [PATCH 12/61] Don't trim time from start and end dates --- CHANGELOG.md | 4 ++++ app/javascript/controllers/maps_controller.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e66d12ac..95de7bbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Trips are now store their paths in the database independently of the points. - Trips are now being rendered on the map using their precalculated paths instead of list of coordinates. +### Changed + +- Requesting photos on the Map page now uses the start and end dates from the URL params. #589 + # 0.23.5 - 2025-01-22 ### Added diff --git a/app/javascript/controllers/maps_controller.js b/app/javascript/controllers/maps_controller.js index 313b477d..997821da 100644 --- a/app/javascript/controllers/maps_controller.js +++ b/app/javascript/controllers/maps_controller.js @@ -218,8 +218,8 @@ export default class extends Controller { } const urlParams = new URLSearchParams(window.location.search); - const startDate = urlParams.get('start_at')?.split('T')[0] || new Date().toISOString().split('T')[0]; - const endDate = urlParams.get('end_at')?.split('T')[0] || new Date().toISOString().split('T')[0]; + const startDate = urlParams.get('start_at') || new Date().toISOString(); + const endDate = urlParams.get('end_at')|| new Date().toISOString(); await fetchAndDisplayPhotos({ map: this.map, photoMarkers: this.photoMarkers, From fd47bf7d5dca6f84e0c1f6850df14f67d7a470c8 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 29 Jan 2025 11:43:02 +0100 Subject: [PATCH 13/61] Update trip path calculation --- CONTRIBUTING.md | 2 +- README.md | 2 +- app/jobs/trips/create_path_job.rb | 5 ++++- app/models/trip.rb | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 00214a48..d1470f1e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ #### **Did you write a patch that fixes a bug?** -* Open a new GitHub pull request with the patch. +* Open a new GitHub pull request with the patch against the `dev` branch. * Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. diff --git a/README.md b/README.md index a087aab4..0d21ed03 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Donate using crypto: [0x6bAd13667692632f1bF926cA9B421bEe7EaEB8D4](https://ethers - Explore statistics like the number of countries and cities visited, total distance traveled, and more! 📄 **Changelog**: Find the latest updates [here](CHANGELOG.md). - +👩‍💻 **Contribute**: See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute to Dawarich. --- ## ⚠️ Disclaimer diff --git a/app/jobs/trips/create_path_job.rb b/app/jobs/trips/create_path_job.rb index f36fa7cd..d64a39ec 100644 --- a/app/jobs/trips/create_path_job.rb +++ b/app/jobs/trips/create_path_job.rb @@ -5,6 +5,9 @@ class Trips::CreatePathJob < ApplicationJob def perform(trip_id) trip = Trip.find(trip_id) - trip.create_path! + + trip.calculate_path_and_distance + + trip.save! end end diff --git a/app/models/trip.rb b/app/models/trip.rb index cd4f7225..5e094078 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -7,15 +7,14 @@ class Trip < ApplicationRecord validates :name, :started_at, :ended_at, presence: true - before_save :create_path! + before_save :calculate_path_and_distance - def create_path! - trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call - - self.distance = calculate_distance - self.path = trip_path + def calculate_path_and_distance + calculate_path + calculate_distance end + def points user.tracked_points.where(timestamp: started_at.to_i..ended_at.to_i).order(:timestamp) end @@ -47,6 +46,13 @@ class Trip < ApplicationRecord vertical_photos.count > horizontal_photos.count ? vertical_photos : horizontal_photos end + def calculate_path + trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call + + self.path = trip_path + end + + def calculate_distance distance = 0 From 5913b65ca84770437359f92500c3e288647e9aea Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 29 Jan 2025 11:46:41 +0100 Subject: [PATCH 14/61] Update CircleCI config --- .circleci/config.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d0055f31..df09558f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,11 +10,15 @@ jobs: - image: cimg/ruby:3.3.4 environment: RAILS_ENV: test - - image: cimg/postgres:13.3 + - image: cimg/postgres:14.0 environment: POSTGRES_USER: postgres POSTGRES_DB: test_database POSTGRES_PASSWORD: mysecretpassword + POSTGRES_INITDB_ARGS: --enable-debug --data-checksums --encoding=UTF8 --lc-collate=C --lc-ctype=C + command: | + apt-get update + apt-get install -y postgis postgresql-14-postgis-3 - image: redis:7.0 steps: From 20d38625488f0c84295081507637a026f903971e Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 29 Jan 2025 11:49:15 +0100 Subject: [PATCH 15/61] Update database config for CI --- config/database.ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/database.ci.yml b/config/database.ci.yml index c5ee5c9d..d5e13575 100644 --- a/config/database.ci.yml +++ b/config/database.ci.yml @@ -1,8 +1,9 @@ # config/database.ci.yml test: - adapter: postgresql + adapter: postgis encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + host: localhost database: <%= ENV["POSTGRES_DB"] %> username: <%= ENV['POSTGRES_USER'] %> password: <%= ENV["POSTGRES_PASSWORD"] %> From cb9e11c18a6d1ba3cde685fab1c80936b02e555e Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 29 Jan 2025 11:53:02 +0100 Subject: [PATCH 16/61] Update CircleCI config --- .circleci/config.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index df09558f..210c03cb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,6 +10,10 @@ jobs: - image: cimg/ruby:3.3.4 environment: RAILS_ENV: test + POSTGRES_HOST: localhost + POSTGRES_USER: postgres + POSTGRES_PASSWORD: mysecretpassword + POSTGRES_DB: test_database - image: cimg/postgres:14.0 environment: POSTGRES_USER: postgres @@ -23,17 +27,28 @@ jobs: steps: - checkout + - run: + name: Install System Dependencies + command: | + sudo apt-get update + sudo apt-get install -y postgresql-client + wget https://github.com/jwilder/dockerize/releases/download/v0.6.1/dockerize-linux-amd64-v0.6.1.tar.gz + sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.6.1.tar.gz + rm dockerize-linux-amd64-v0.6.1.tar.gz - run: name: Install Bundler command: gem install bundler - run: name: Bundle Install command: bundle install --jobs=4 --retry=3 + - run: + name: Wait for PostgreSQL + command: dockerize -wait tcp://localhost:5432 -timeout 1m - run: name: Database Setup command: | - bundle exec rails db:create - bundle exec rails db:schema:load + cp config/database.ci.yml config/database.yml + bundle exec rails db:create db:schema:load - run: name: Run RSpec tests command: bundle exec rspec From 3139d2897130439de19fca890f5dacc70e006896 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 29 Jan 2025 11:55:33 +0100 Subject: [PATCH 17/61] Update CircleCI config --- .circleci/config.yml | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 210c03cb..bd38b09c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,11 +10,7 @@ jobs: - image: cimg/ruby:3.3.4 environment: RAILS_ENV: test - POSTGRES_HOST: localhost - POSTGRES_USER: postgres - POSTGRES_PASSWORD: mysecretpassword - POSTGRES_DB: test_database - - image: cimg/postgres:14.0 + - image: cimg/postgres:14.0-postgis environment: POSTGRES_USER: postgres POSTGRES_DB: test_database @@ -27,28 +23,17 @@ jobs: steps: - checkout - - run: - name: Install System Dependencies - command: | - sudo apt-get update - sudo apt-get install -y postgresql-client - wget https://github.com/jwilder/dockerize/releases/download/v0.6.1/dockerize-linux-amd64-v0.6.1.tar.gz - sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.6.1.tar.gz - rm dockerize-linux-amd64-v0.6.1.tar.gz - run: name: Install Bundler command: gem install bundler - run: name: Bundle Install command: bundle install --jobs=4 --retry=3 - - run: - name: Wait for PostgreSQL - command: dockerize -wait tcp://localhost:5432 -timeout 1m - run: name: Database Setup command: | - cp config/database.ci.yml config/database.yml - bundle exec rails db:create db:schema:load + bundle exec rails db:create + bundle exec rails db:schema:load - run: name: Run RSpec tests command: bundle exec rspec From e99e105ab8f95fb47e77e2309e734762ba5d5a32 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 29 Jan 2025 11:57:53 +0100 Subject: [PATCH 18/61] Update CircleCI config --- .circleci/config.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bd38b09c..460be1ea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,15 +10,11 @@ jobs: - image: cimg/ruby:3.3.4 environment: RAILS_ENV: test - - image: cimg/postgres:14.0-postgis + - image: cimg/postgres:13.3-postgis environment: POSTGRES_USER: postgres POSTGRES_DB: test_database POSTGRES_PASSWORD: mysecretpassword - POSTGRES_INITDB_ARGS: --enable-debug --data-checksums --encoding=UTF8 --lc-collate=C --lc-ctype=C - command: | - apt-get update - apt-get install -y postgis postgresql-14-postgis-3 - image: redis:7.0 steps: From 8a309a2186185580a280689672726b11cb0d889f Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 29 Jan 2025 12:18:03 +0100 Subject: [PATCH 19/61] Remove tracks --- CHANGELOG.md | 2 +- app/models/track.rb | 7 ------- app/models/user.rb | 1 - db/migrate/20250123145954_create_tracks.rb | 14 -------------- db/schema.rb | 11 ----------- spec/factories/tracks.rb | 10 ---------- spec/models/track_spec.rb | 15 --------------- spec/models/user_spec.rb | 1 - 8 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 app/models/track.rb delete mode 100644 db/migrate/20250123145954_create_tracks.rb delete mode 100644 spec/factories/tracks.rb delete mode 100644 spec/models/track_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 95de7bbf..1dd4398c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ 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.23.6 - 2025-01-23 +# 0.23.6 - 2025-01-29 ### Added diff --git a/app/models/track.rb b/app/models/track.rb deleted file mode 100644 index 41e673b4..00000000 --- a/app/models/track.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class Track < ApplicationRecord - belongs_to :user - - validates :path, :started_at, :ended_at, presence: true -end diff --git a/app/models/user.rb b/app/models/user.rb index 90ff2fb0..b8d27f17 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,7 +14,6 @@ class User < ApplicationRecord has_many :points, through: :imports has_many :places, through: :visits has_many :trips, dependent: :destroy - has_many :tracks, dependent: :destroy after_create :create_api_key before_save :strip_trailing_slashes diff --git a/db/migrate/20250123145954_create_tracks.rb b/db/migrate/20250123145954_create_tracks.rb deleted file mode 100644 index 35c6afa1..00000000 --- a/db/migrate/20250123145954_create_tracks.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class CreateTracks < ActiveRecord::Migration[8.0] - def change - create_table :tracks do |t| - t.datetime :started_at, null: false - t.datetime :ended_at, null: false - t.references :user, null: false, foreign_key: true - t.line_string :path, srid: 3857, null: false - - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb index 7e9cca52..b431351f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -193,16 +193,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_151657) do t.index ["year"], name: "index_stats_on_year" end - create_table "tracks", force: :cascade do |t| - t.datetime "started_at", null: false - t.datetime "ended_at", null: false - t.bigint "user_id", null: false - t.geometry "path", limit: {:srid=>3857, :type=>"line_string"}, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["user_id"], name: "index_tracks_on_user_id" - end - create_table "trips", force: :cascade do |t| t.string "name", null: false t.datetime "started_at", null: false @@ -264,7 +254,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_151657) do add_foreign_key "points", "users" add_foreign_key "points", "visits" add_foreign_key "stats", "users" - add_foreign_key "tracks", "users" add_foreign_key "trips", "users" add_foreign_key "visits", "areas" add_foreign_key "visits", "places" diff --git a/spec/factories/tracks.rb b/spec/factories/tracks.rb deleted file mode 100644 index 32603460..00000000 --- a/spec/factories/tracks.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :track do - started_at { DateTime.new(2025, 1, 23, 15, 59, 55) } - ended_at { DateTime.new(2025, 1, 23, 16, 0, 0) } - user - path { 'LINESTRING(0 0, 1 1, 2 2)' } - end -end diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb deleted file mode 100644 index 051b8ae8..00000000 --- a/spec/models/track_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Track, type: :model do - describe 'validations' do - it { is_expected.to validate_presence_of(:path) } - it { is_expected.to validate_presence_of(:started_at) } - it { is_expected.to validate_presence_of(:ended_at) } - end - - describe 'associations' do - it { is_expected.to belong_to(:user) } - end -end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a9ce1d1e..398e436f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -14,7 +14,6 @@ RSpec.describe User, type: :model do it { is_expected.to have_many(:visits).dependent(:destroy) } it { is_expected.to have_many(:places).through(:visits) } it { is_expected.to have_many(:trips).dependent(:destroy) } - it { is_expected.to have_many(:tracks).dependent(:destroy) } end describe 'callbacks' do From 27714985de163f7bb421aad1c638faf2385e4579 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 1 Feb 2025 18:52:26 +0100 Subject: [PATCH 20/61] Change base image to slim --- Gemfile | 1 + Gemfile.lock | 1 + docker/Dockerfile.dev | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 592c2fd3..0a30ff39 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem 'activerecord-postgis-adapter', github: 'StoneGod/activerecord-postgis-adapt gem 'puma' gem 'pundit' gem 'rails', '~> 8.0' +gem 'racc', '~> 1.8', '>= 1.8.1' # Nokogiri dependency gem 'rgeo' gem 'rswag-api' gem 'rswag-ui' diff --git a/Gemfile.lock b/Gemfile.lock index 8407dd3a..144f3b3d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -482,6 +482,7 @@ DEPENDENCIES pry-rails puma pundit + racc (~> 1.8, >= 1.8.1) rails (~> 8.0) redis rgeo diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 37b04015..ba6a21fe 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:3.3.4-alpine +FROM ruby:3.3.4-slim ENV APP_PATH=/var/app ENV BUNDLE_VERSION=2.5.21 @@ -6,22 +6,27 @@ ENV BUNDLE_PATH=/usr/local/bundle/gems ENV RAILS_LOG_TO_STDOUT=true ENV RAILS_PORT=3000 ENV RAILS_ENV=development +ENV BUNDLE_FORCE_RUBY_PLATFORM=1 +ENV NOKOGIRI_USE_SYSTEM_LIBRARIES=1 # Install dependencies for application -RUN apk -U add --no-cache \ - build-base \ +RUN apt-get update -qq && apt-get install -y \ + build-essential \ git \ - postgresql-dev \ + libpq-dev \ postgresql-client \ + libxml2 \ libxml2-dev \ - libxslt-dev \ + libxslt1-dev \ nodejs \ - yarn \ + npm \ imagemagick \ tzdata \ less \ - yaml-dev \ - gcompat \ + libyaml-dev \ + pkg-config \ + && npm install -g yarn \ + && rm -rf /var/lib/apt/lists/* \ && mkdir -p $APP_PATH # Update gem system and install bundler @@ -35,7 +40,7 @@ COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ # Install all gems into the image RUN bundle config set --local path 'vendor/bundle' \ - && bundle install --jobs 4 --retry 3 \ + && bundle install --jobs 1 --retry 3 \ && rm -rf vendor/bundle/ruby/3.3.0/cache/*.gem # Copy the rest of the application From 8aa3e6818cba6b0dfbe2bc2318c57711674efd31 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 1 Feb 2025 19:49:57 +0100 Subject: [PATCH 21/61] Use dockerfile from 0.23.5 --- docker/Dockerfile.dev | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index ba6a21fe..37b04015 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:3.3.4-slim +FROM ruby:3.3.4-alpine ENV APP_PATH=/var/app ENV BUNDLE_VERSION=2.5.21 @@ -6,27 +6,22 @@ ENV BUNDLE_PATH=/usr/local/bundle/gems ENV RAILS_LOG_TO_STDOUT=true ENV RAILS_PORT=3000 ENV RAILS_ENV=development -ENV BUNDLE_FORCE_RUBY_PLATFORM=1 -ENV NOKOGIRI_USE_SYSTEM_LIBRARIES=1 # Install dependencies for application -RUN apt-get update -qq && apt-get install -y \ - build-essential \ +RUN apk -U add --no-cache \ + build-base \ git \ - libpq-dev \ + postgresql-dev \ postgresql-client \ - libxml2 \ libxml2-dev \ - libxslt1-dev \ + libxslt-dev \ nodejs \ - npm \ + yarn \ imagemagick \ tzdata \ less \ - libyaml-dev \ - pkg-config \ - && npm install -g yarn \ - && rm -rf /var/lib/apt/lists/* \ + yaml-dev \ + gcompat \ && mkdir -p $APP_PATH # Update gem system and install bundler @@ -40,7 +35,7 @@ COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ # Install all gems into the image RUN bundle config set --local path 'vendor/bundle' \ - && bundle install --jobs 1 --retry 3 \ + && bundle install --jobs 4 --retry 3 \ && rm -rf vendor/bundle/ruby/3.3.0/cache/*.gem # Copy the rest of the application From 8227c747f24b32ff0e070869603ffe5f29f7f061 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 1 Feb 2025 20:38:00 +0100 Subject: [PATCH 22/61] Revert older versions of actions --- .github/workflows/build_and_push.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 90c78ae1..198579b4 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -15,15 +15,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v2 with: ref: ${{ github.event.inputs.branch || github.ref_name }} - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@v1 - name: Cache Docker layers uses: actions/cache@v4 @@ -61,7 +60,7 @@ jobs: echo "tags=${TAGS}" >> $GITHUB_OUTPUT - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v2 with: context: . file: ./docker/Dockerfile.dev From 73fc46b1ec48e49d955437dd4522a12d39e71fbc Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 15:04:24 +0100 Subject: [PATCH 23/61] Remove arm64 from platforms as an experiment --- .github/workflows/build_and_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 198579b4..8b3adf89 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -66,6 +66,6 @@ jobs: file: ./docker/Dockerfile.dev push: true tags: ${{ steps.docker_meta.outputs.tags }} - platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 + platforms: linux/amd64,linux/arm/v7,linux/arm/v6 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache From 5bc1ea3b3657a76a6bc670e0f919f3844031d331 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 15:48:16 +0100 Subject: [PATCH 24/61] Return arm64 to the build matrix --- .github/workflows/build_and_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 8b3adf89..198579b4 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -66,6 +66,6 @@ jobs: file: ./docker/Dockerfile.dev push: true tags: ${{ steps.docker_meta.outputs.tags }} - platforms: linux/amd64,linux/arm/v7,linux/arm/v6 + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache From 6259c0c476029c14f80a6d907dce23e1f8fedf73 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 17:14:48 +0100 Subject: [PATCH 25/61] Update build and push action --- .github/workflows/build_and_push.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 198579b4..e51ed126 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -59,13 +59,24 @@ jobs: echo "tags=${TAGS}" >> $GITHUB_OUTPUT - - name: Build and push + - name: Build and push (arm64) uses: docker/build-push-action@v2 with: context: . file: ./docker/Dockerfile.dev push: true tags: ${{ steps.docker_meta.outputs.tags }} - platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 + platforms: linux/arm64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-arm64 + + - name: Build and push (other architectures) + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile.dev + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + platforms: linux/amd64,linux/arm/v7,linux/arm/v6 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache From f91e142a2f047626e6cc12ad167e616f1a9edcd5 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 17:33:16 +0100 Subject: [PATCH 26/61] Use v6 of build and push action --- .github/workflows/build_and_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index e51ed126..7269311a 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -60,7 +60,7 @@ jobs: echo "tags=${TAGS}" >> $GITHUB_OUTPUT - name: Build and push (arm64) - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v6 with: context: . file: ./docker/Dockerfile.dev From 267c4271b5894daaf5a1a21f26a3f1ede5d9c0ab Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 21:10:15 +0100 Subject: [PATCH 27/61] Remove cache from build and push action --- .github/workflows/build_and_push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 7269311a..63f963e4 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -67,8 +67,8 @@ jobs: push: true tags: ${{ steps.docker_meta.outputs.tags }} platforms: linux/arm64 - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-arm64 + # cache-from: type=local,src=/tmp/.buildx-cache + # cache-to: type=local,dest=/tmp/.buildx-cache-arm64 - name: Build and push (other architectures) uses: docker/build-push-action@v2 From ce472bd53a448208cb3fd23a654556e8feddd49e Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 21:41:41 +0100 Subject: [PATCH 28/61] Update CircleCI config --- .circleci/config.yml | 67 ++++++++++++++++++++++++++++ .github/workflows/build_and_push.yml | 4 +- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 460be1ea..13d57942 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,12 @@ version: 2.1 orbs: ruby: circleci/ruby@2.1.4 browser-tools: circleci/browser-tools@1.4.8 + docker: circleci/docker@2.4.0 + +parameters: + branch: + type: string + default: "master" jobs: test: @@ -36,7 +42,68 @@ jobs: - store_artifacts: path: coverage + build-and-push: + machine: + image: ubuntu-2204:current + steps: + - checkout + + - docker/setup-buildx + + - restore_cache: + keys: + - docker-layers-{{ .Branch }}-{{ .Revision }} + - docker-layers-{{ .Branch }} + - docker-layers- + + - run: + name: Install dependencies + command: npm install + + - run: + name: Login to DockerHub + command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + + - run: + name: Set Docker tags + command: | + VERSION=${CIRCLE_TAG:-latest} + TAGS="freikin/dawarich:${VERSION}" + + # Add :rc tag for pre-releases (assuming tag contains 'rc' for pre-releases) + if [[ $CIRCLE_TAG == *"rc"* ]]; then + TAGS="${TAGS},freikin/dawarich:rc" + fi + + # Add :latest tag only if not a pre-release + if [[ $CIRCLE_TAG != *"rc"* ]]; then + TAGS="${TAGS},freikin/dawarich:latest" + fi + + echo "export DOCKER_TAGS=${TAGS}" >> $BASH_ENV + + - docker/build: + image: freikin/dawarich + tag: ${DOCKER_TAGS} + dockerfile: ./docker/Dockerfile.dev + platform: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 + push: true + + - save_cache: + key: docker-layers-{{ .Branch }}-{{ .Revision }} + paths: + - /tmp/docker-cache + workflows: rspec: jobs: - test + version: 2 + build-and-deploy: + jobs: + - build-and-push: + filters: + tags: + only: /^v.*/ + branches: + only: master diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 63f963e4..7269311a 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -67,8 +67,8 @@ jobs: push: true tags: ${{ steps.docker_meta.outputs.tags }} platforms: linux/arm64 - # cache-from: type=local,src=/tmp/.buildx-cache - # cache-to: type=local,dest=/tmp/.buildx-cache-arm64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-arm64 - name: Build and push (other architectures) uses: docker/build-push-action@v2 From 4a9e8a083f93fec940770964a214636c2700f431 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 21:49:52 +0100 Subject: [PATCH 29/61] Update CircleCI config --- .circleci/config.yml | 106 ++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 13d57942..11bb56cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,14 +1,14 @@ version: 2.1 +executors: + docker-executor: + machine: + image: ubuntu-2204:current + orbs: ruby: circleci/ruby@2.1.4 browser-tools: circleci/browser-tools@1.4.8 - docker: circleci/docker@2.4.0 -parameters: - branch: - type: string - default: "master" jobs: test: @@ -41,69 +41,83 @@ jobs: command: bundle exec rspec - store_artifacts: path: coverage - build-and-push: - machine: - image: ubuntu-2204:current + executor: docker-executor + environment: + DOCKER_CLI_EXPERIMENTAL: enabled steps: - checkout - - docker/setup-buildx + - run: + name: Set branch variable + command: | + if [ -z "$CIRCLE_BRANCH" ]; then + echo 'export BUILD_BRANCH=master' >> $BASH_ENV + else + echo "export BUILD_BRANCH=$CIRCLE_BRANCH" >> $BASH_ENV + fi - - restore_cache: - keys: - - docker-layers-{{ .Branch }}-{{ .Revision }} - - docker-layers-{{ .Branch }} - - docker-layers- + - setup_remote_docker: + version: 20.10.24 + docker_layer_caching: true - run: - name: Install dependencies - command: npm install + name: Install dependencies + command: npm install - run: - name: Login to DockerHub - command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + name: Login to Docker Hub + command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin - run: - name: Set Docker tags - command: | - VERSION=${CIRCLE_TAG:-latest} - TAGS="freikin/dawarich:${VERSION}" + name: Set Docker tags + command: | + if [[ -n "$CIRCLE_TAG" ]]; then + VERSION="${CIRCLE_TAG}" + else + VERSION="latest" + fi - # Add :rc tag for pre-releases (assuming tag contains 'rc' for pre-releases) - if [[ $CIRCLE_TAG == *"rc"* ]]; then - TAGS="${TAGS},freikin/dawarich:rc" - fi + TAGS="freikin/dawarich:${VERSION}" - # Add :latest tag only if not a pre-release - if [[ $CIRCLE_TAG != *"rc"* ]]; then - TAGS="${TAGS},freikin/dawarich:latest" - fi + if [[ "$CIRCLE_TAG" =~ rc ]]; then + TAGS="${TAGS},freikin/dawarich:rc" + else + TAGS="${TAGS},freikin/dawarich:latest" + fi - echo "export DOCKER_TAGS=${TAGS}" >> $BASH_ENV + echo "export DOCKER_TAGS=\"$TAGS\"" >> $BASH_ENV - - docker/build: - image: freikin/dawarich - tag: ${DOCKER_TAGS} - dockerfile: ./docker/Dockerfile.dev - platform: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 - push: true + - run: + name: Build and push (arm64) + command: | + docker buildx create --use + docker buildx build --platform linux/arm64 \ + --file ./docker/Dockerfile.dev \ + --tag freikin/dawarich:${VERSION} \ + --push . - - save_cache: - key: docker-layers-{{ .Branch }}-{{ .Revision }} - paths: - - /tmp/docker-cache + - run: + name: Build and push (other architectures) + command: | + docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm/v6 \ + --file ./docker/Dockerfile.dev \ + --tag freikin/dawarich:${VERSION} \ + --push . workflows: + version: 2 rspec: jobs: - test - version: 2 - build-and-deploy: + + build-and-push: jobs: + - test - build-and-push: filters: - tags: - only: /^v.*/ branches: - only: master + only: + - master + tags: + only: /^v.*/ # Run only on version tags From a616c1568ef25d60451e3663e8726a08025188e1 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 21:51:32 +0100 Subject: [PATCH 30/61] Update CircleCI config --- .circleci/config.yml | 90 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 11bb56cc..36692f3c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,6 @@ orbs: ruby: circleci/ruby@2.1.4 browser-tools: circleci/browser-tools@1.4.8 - jobs: test: docker: @@ -41,6 +40,7 @@ jobs: command: bundle exec rspec - store_artifacts: path: coverage + build-and-push: executor: docker-executor environment: @@ -49,72 +49,70 @@ jobs: - checkout - run: - name: Set branch variable - command: | - if [ -z "$CIRCLE_BRANCH" ]; then - echo 'export BUILD_BRANCH=master' >> $BASH_ENV - else - echo "export BUILD_BRANCH=$CIRCLE_BRANCH" >> $BASH_ENV - fi + name: Set branch variable + command: | + if [ -z "$CIRCLE_BRANCH" ]; then + echo 'export BUILD_BRANCH=master' >> $BASH_ENV + else + echo "export BUILD_BRANCH=$CIRCLE_BRANCH" >> $BASH_ENV + fi - setup_remote_docker: - version: 20.10.24 - docker_layer_caching: true + version: 20.10.24 + docker_layer_caching: true - run: - name: Install dependencies - command: npm install + name: Install dependencies + command: npm install - run: - name: Login to Docker Hub - command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + name: Login to Docker Hub + command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin - run: - name: Set Docker tags - command: | - if [[ -n "$CIRCLE_TAG" ]]; then - VERSION="${CIRCLE_TAG}" - else - VERSION="latest" - fi + name: Set Docker tags + command: | + if [[ -n "$CIRCLE_TAG" ]]; then + VERSION="${CIRCLE_TAG}" + else + VERSION="latest" + fi - TAGS="freikin/dawarich:${VERSION}" + TAGS="freikin/dawarich:${VERSION}" - if [[ "$CIRCLE_TAG" =~ rc ]]; then - TAGS="${TAGS},freikin/dawarich:rc" - else - TAGS="${TAGS},freikin/dawarich:latest" - fi + if [[ "$CIRCLE_TAG" =~ rc ]]; then + TAGS="${TAGS},freikin/dawarich:rc" + else + TAGS="${TAGS},freikin/dawarich:latest" + fi - echo "export DOCKER_TAGS=\"$TAGS\"" >> $BASH_ENV + echo "export DOCKER_TAGS=\"$TAGS\"" >> $BASH_ENV - run: - name: Build and push (arm64) - command: | - docker buildx create --use - docker buildx build --platform linux/arm64 \ - --file ./docker/Dockerfile.dev \ - --tag freikin/dawarich:${VERSION} \ - --push . + name: Build and push (arm64) + command: | + docker buildx create --use + docker buildx build --platform linux/arm64 \ + --file ./docker/Dockerfile.dev \ + --tag freikin/dawarich:${VERSION} \ + --push . - run: - name: Build and push (other architectures) - command: | - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm/v6 \ - --file ./docker/Dockerfile.dev \ - --tag freikin/dawarich:${VERSION} \ - --push . + name: Build and push (other architectures) + command: | + docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm/v6 \ + --file ./docker/Dockerfile.dev \ + --tag freikin/dawarich:${VERSION} \ + --push . workflows: version: 2 - rspec: - jobs: - - test - - build-and-push: + build-and-test: jobs: - test - build-and-push: + requires: + - test # Ensures build happens only if tests pass filters: branches: only: From 193f251e3972528b36a85299164fc8e6d351e9ec Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 21:59:24 +0100 Subject: [PATCH 31/61] Update CircleCI config --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 36692f3c..1a5cd713 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -112,10 +112,11 @@ workflows: - test - build-and-push: requires: - - test # Ensures build happens only if tests pass + - test filters: branches: only: - master tags: - only: /^v.*/ # Run only on version tags + only: + - /^\d+\.\d+\.\d+$/ # Matches tags like 0.23.6 From e725128e30c0828ba0852bdcf21f3152650db956 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:02:21 +0100 Subject: [PATCH 32/61] Update CircleCI config --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a5cd713..651f278a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -118,5 +118,4 @@ workflows: only: - master tags: - only: - - /^\d+\.\d+\.\d+$/ # Matches tags like 0.23.6 + only: /.*/ # Match ANY tag name From fd5db13d4225178d44cf1cee2bc86ee9b04ca027 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:11:22 +0100 Subject: [PATCH 33/61] Update CircleCI config --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 651f278a..9aaa7f69 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,5 +117,6 @@ workflows: branches: only: - master + - dev tags: only: /.*/ # Match ANY tag name From 009c9d3995e70a15c77b83acb4b8ad709421c78d Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:17:10 +0100 Subject: [PATCH 34/61] Update CircleCI config --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9aaa7f69..2cfbdaa9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,8 +111,6 @@ workflows: jobs: - test - build-and-push: - requires: - - test filters: branches: only: From d937b9fa344ddd58bc91babce6b872f0b4d7580a Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:18:41 +0100 Subject: [PATCH 35/61] Update CircleCI config --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2cfbdaa9..91d5ca00 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,7 +42,8 @@ jobs: path: coverage build-and-push: - executor: docker-executor + docker: + - image: cimg/base:current environment: DOCKER_CLI_EXPERIMENTAL: enabled steps: From a2d67d8e387e5f770f02ea01a0b1b972362cff7e Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:23:20 +0100 Subject: [PATCH 36/61] Update CircleCI config --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 91d5ca00..74d96c6a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,7 +43,7 @@ jobs: build-and-push: docker: - - image: cimg/base:current + - image: cimg/node:current environment: DOCKER_CLI_EXPERIMENTAL: enabled steps: From 8c8ec576c463208d13c69e756b78bd09dc1d3885 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:25:37 +0100 Subject: [PATCH 37/61] Update CircleCI config --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 74d96c6a..0c7861d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,7 @@ jobs: - run: name: Login to Docker Hub - command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + command: echo "$DOCKERHUB_TOKEN" | docker login -username "$DOCKERHUB_USERNAME" --password-stdin - run: name: Set Docker tags From 7b0324710130e96c134de8f8f8b84b2c528d5cba Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:28:31 +0100 Subject: [PATCH 38/61] Update circle ci config --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0c7861d1..74d96c6a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,7 @@ jobs: - run: name: Login to Docker Hub - command: echo "$DOCKERHUB_TOKEN" | docker login -username "$DOCKERHUB_USERNAME" --password-stdin + command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin - run: name: Set Docker tags From 75112f3dc49e2b5be8a61221440a41145ce09485 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:30:45 +0100 Subject: [PATCH 39/61] Update circle ci config --- .circleci/config.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 74d96c6a..015bf33b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,6 +8,7 @@ executors: orbs: ruby: circleci/ruby@2.1.4 browser-tools: circleci/browser-tools@1.4.8 + docker: circleci/docker@2.2.1 jobs: test: @@ -66,9 +67,9 @@ jobs: name: Install dependencies command: npm install - - run: - name: Login to Docker Hub - command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + - docker/login: + username: << pipeline.parameters.DOCKERHUB_USERNAME >> + password: << pipeline.parameters.DOCKERHUB_TOKEN >> - run: name: Set Docker tags From 005b74eb652c1e54e43a5e5f0de1a448dc80761a Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:35:25 +0100 Subject: [PATCH 40/61] Update circle ci config --- .circleci/config.yml | 91 +++++++++++++------------------------------- 1 file changed, 26 insertions(+), 65 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 015bf33b..420e9203 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ executors: orbs: ruby: circleci/ruby@2.1.4 browser-tools: circleci/browser-tools@1.4.8 - docker: circleci/docker@2.2.1 + docker: circleci/docker@2.8.2 jobs: test: @@ -43,69 +43,29 @@ jobs: path: coverage build-and-push: - docker: - - image: cimg/node:current - environment: - DOCKER_CLI_EXPERIMENTAL: enabled + executor: + name: docker/docker + # You can also specify a different image if required. + parameters: + tag: + type: string + default: "rc" steps: - checkout - - - run: - name: Set branch variable - command: | - if [ -z "$CIRCLE_BRANCH" ]; then - echo 'export BUILD_BRANCH=master' >> $BASH_ENV - else - echo "export BUILD_BRANCH=$CIRCLE_BRANCH" >> $BASH_ENV - fi - - - setup_remote_docker: - version: 20.10.24 - docker_layer_caching: true - - - run: - name: Install dependencies - command: npm install - + # Login to Docker Hub using the orb command. The orb expects environment + # variables DOCKERHUB_USERNAME and DOCKERHUB_PASSWORD (or DOCKERHUB_TOKEN). - docker/login: - username: << pipeline.parameters.DOCKERHUB_USERNAME >> - password: << pipeline.parameters.DOCKERHUB_TOKEN >> - - - run: - name: Set Docker tags - command: | - if [[ -n "$CIRCLE_TAG" ]]; then - VERSION="${CIRCLE_TAG}" - else - VERSION="latest" - fi - - TAGS="freikin/dawarich:${VERSION}" - - if [[ "$CIRCLE_TAG" =~ rc ]]; then - TAGS="${TAGS},freikin/dawarich:rc" - else - TAGS="${TAGS},freikin/dawarich:latest" - fi - - echo "export DOCKER_TAGS=\"$TAGS\"" >> $BASH_ENV - - - run: - name: Build and push (arm64) - command: | - docker buildx create --use - docker buildx build --platform linux/arm64 \ - --file ./docker/Dockerfile.dev \ - --tag freikin/dawarich:${VERSION} \ - --push . - - - run: - name: Build and push (other architectures) - command: | - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm/v6 \ - --file ./docker/Dockerfile.dev \ - --tag freikin/dawarich:${VERSION} \ - --push . + username: "$DOCKERHUB_USERNAME" + password: "$DOCKERHUB_TOKEN" + # Build and publish the Docker image. + - docker/build-publish: + image: "freikin/dawarich:<< parameters.tag >>" + dockerfile: ./docker/Dockerfile.dev + # Set additional options if needed: + build-args: "" + extra-build-args: "--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6" + registry: "docker.io" + push: true workflows: version: 2 @@ -113,10 +73,11 @@ workflows: jobs: - test - build-and-push: + requires: + - test filters: branches: - only: - - master - - dev + ignore: /.*/ # Ignore branches; run only on tag builds (or adjust as needed) tags: - only: /.*/ # Match ANY tag name + only: /.*/ # Run for any tag; adjust regex if you want more specific tag matching + tag: "<< pipeline.parameters.tag >>" From 6b0c6e1ed0365359c2c8f74fcb91385af909458f Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:38:06 +0100 Subject: [PATCH 41/61] Update circle ci config --- .circleci/config.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 420e9203..6e023a08 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,7 +22,6 @@ jobs: POSTGRES_DB: test_database POSTGRES_PASSWORD: mysecretpassword - image: redis:7.0 - steps: - checkout - run: @@ -45,23 +44,18 @@ jobs: build-and-push: executor: name: docker/docker - # You can also specify a different image if required. parameters: tag: type: string default: "rc" steps: - checkout - # Login to Docker Hub using the orb command. The orb expects environment - # variables DOCKERHUB_USERNAME and DOCKERHUB_PASSWORD (or DOCKERHUB_TOKEN). - docker/login: username: "$DOCKERHUB_USERNAME" password: "$DOCKERHUB_TOKEN" - # Build and publish the Docker image. - docker/build-publish: image: "freikin/dawarich:<< parameters.tag >>" dockerfile: ./docker/Dockerfile.dev - # Set additional options if needed: build-args: "" extra-build-args: "--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6" registry: "docker.io" @@ -77,7 +71,6 @@ workflows: - test filters: branches: - ignore: /.*/ # Ignore branches; run only on tag builds (or adjust as needed) + ignore: /.*/ # Run only on tag builds tags: - only: /.*/ # Run for any tag; adjust regex if you want more specific tag matching - tag: "<< pipeline.parameters.tag >>" + only: /.*/ # Run for any tag From e512b415803670a81f2d3ed2e0f901e2e1f24211 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:38:42 +0100 Subject: [PATCH 42/61] Update circle ci config --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6e023a08..a2db6515 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,10 @@ version: 2.1 +parameters: + tag: + type: string + default: "rc" + executors: docker-executor: machine: @@ -74,3 +79,4 @@ workflows: ignore: /.*/ # Run only on tag builds tags: only: /.*/ # Run for any tag + tag: "<< pipeline.parameters.tag >>" From ac687f81240b190cba9a3d0b444e17fb1212d2aa Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:40:58 +0100 Subject: [PATCH 43/61] Update circle ci config --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a2db6515..4a46e64d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -56,8 +56,8 @@ jobs: steps: - checkout - docker/login: - username: "$DOCKERHUB_USERNAME" - password: "$DOCKERHUB_TOKEN" + docker-username: "$DOCKERHUB_USERNAME" + docker-password: "$DOCKERHUB_TOKEN" - docker/build-publish: image: "freikin/dawarich:<< parameters.tag >>" dockerfile: ./docker/Dockerfile.dev From f9cff143dd8bab1ce205525ce5ca6eed07204950 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:44:43 +0100 Subject: [PATCH 44/61] Update circle ci config --- .circleci/config.yml | 50 ++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4a46e64d..c0b865ea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,10 +1,5 @@ version: 2.1 -parameters: - tag: - type: string - default: "rc" - executors: docker-executor: machine: @@ -46,37 +41,24 @@ jobs: - store_artifacts: path: coverage - build-and-push: - executor: - name: docker/docker - parameters: - tag: - type: string - default: "rc" - steps: - - checkout - - docker/login: - docker-username: "$DOCKERHUB_USERNAME" - docker-password: "$DOCKERHUB_TOKEN" - - docker/build-publish: - image: "freikin/dawarich:<< parameters.tag >>" - dockerfile: ./docker/Dockerfile.dev - build-args: "" - extra-build-args: "--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6" - registry: "docker.io" - push: true + workflows: version: 2 - build-and-test: + test: jobs: - test - - build-and-push: - requires: - - test - filters: - branches: - ignore: /.*/ # Run only on tag builds - tags: - only: /.*/ # Run for any tag - tag: "<< pipeline.parameters.tag >>" + build-docker-image-only: + jobs: + - docker/publish: + image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME + update-description: true + build-docker-image-only-with-buildkit: + jobs: + - docker/publish: + image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME + remote-docker-version: 20.10.12 + update-description: true + use-buildkit: true + use-remote-docker: true + From 66f3c0ae909c715804ada241e04e1c9bd1cc7ec0 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:46:35 +0100 Subject: [PATCH 45/61] Update circle ci config --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index c0b865ea..1b74edf7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,8 +57,11 @@ workflows: jobs: - docker/publish: image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME + dockerfile: ./docker/Dockerfile.dev remote-docker-version: 20.10.12 update-description: true use-buildkit: true use-remote-docker: true + use-docker-credentials-store: true + tag: "rc" From 33b7dd09b922be8cb52fab5d4fd97b9d1576179c Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:47:19 +0100 Subject: [PATCH 46/61] Update circle ci config --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1b74edf7..392d441d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,4 +64,6 @@ workflows: use-remote-docker: true use-docker-credentials-store: true tag: "rc" + docker-username: "$DOCKERHUB_USERNAME" + docker-password: "$DOCKERHUB_TOKEN" From 15e2fde2f25466c77d50db54e7961ab43325e178 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sun, 2 Feb 2025 22:48:30 +0100 Subject: [PATCH 47/61] Update circle ci config --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 392d441d..c59e1c13 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,6 +64,6 @@ workflows: use-remote-docker: true use-docker-credentials-store: true tag: "rc" - docker-username: "$DOCKERHUB_USERNAME" - docker-password: "$DOCKERHUB_TOKEN" + docker-username: DOCKERHUB_USERNAME + docker-password: DOCKERHUB_TOKEN From 1a67878aaf2ffa977bf5cb93e289157f21e0d53c Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 3 Feb 2025 20:00:50 +0100 Subject: [PATCH 48/61] Return to simple CircleCI config --- .circleci/config.yml | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c59e1c13..460be1ea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,14 +1,8 @@ version: 2.1 -executors: - docker-executor: - machine: - image: ubuntu-2204:current - orbs: ruby: circleci/ruby@2.1.4 browser-tools: circleci/browser-tools@1.4.8 - docker: circleci/docker@2.8.2 jobs: test: @@ -22,6 +16,7 @@ jobs: POSTGRES_DB: test_database POSTGRES_PASSWORD: mysecretpassword - image: redis:7.0 + steps: - checkout - run: @@ -41,29 +36,7 @@ jobs: - store_artifacts: path: coverage - - workflows: - version: 2 - test: + rspec: jobs: - test - build-docker-image-only: - jobs: - - docker/publish: - image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME - update-description: true - build-docker-image-only-with-buildkit: - jobs: - - docker/publish: - image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME - dockerfile: ./docker/Dockerfile.dev - remote-docker-version: 20.10.12 - update-description: true - use-buildkit: true - use-remote-docker: true - use-docker-credentials-store: true - tag: "rc" - docker-username: DOCKERHUB_USERNAME - docker-password: DOCKERHUB_TOKEN - From 1df5d514e15e49f374c80c627c46b5b5ed4bc8f1 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 18:56:06 +0100 Subject: [PATCH 49/61] Update Ruby to 3.4.1 and replace alpine docker image with bookworm --- .circleci/docker.yml | 34 ++++++++++++++++++++++++++++++++++ .circleci/local_config.yml | 32 ++++++++++++++++++++++++++++++++ .ruby-version | 2 +- Gemfile | 1 + Gemfile.lock | 15 ++++++++------- docker/Dockerfile.dev | 18 ++++++++++-------- 6 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 .circleci/docker.yml create mode 100644 .circleci/local_config.yml diff --git a/.circleci/docker.yml b/.circleci/docker.yml new file mode 100644 index 00000000..5d9a5804 --- /dev/null +++ b/.circleci/docker.yml @@ -0,0 +1,34 @@ +version: 2.1 + +jobs: + build-and-push: + docker: + - image: cimg/base:stable + steps: + - checkout + - setup_remote_docker + - run: + name: Login to DockerHub + command: | + echo "Attempting to login to DockerHub..." + echo "$DOCKERHUB_TOKEN" | sudo docker login -u "$DOCKERHUB_USERNAME" --password-stdin + - run: + name: Build and push Docker images + command: | + # Get the short SHA or use 'latest' as fallback + SHORT_SHA=${CIRCLE_SHA1:-rc1} + + sudo docker buildx create --use + sudo docker buildx build \ + --platform linux/amd64 \ + -t freikin/dawarich:${SHORT_SHA} \ + -t freikin/dawarich:rc \ + -f docker/Dockerfile.dev \ + --push . + +workflows: + version: 2 + build-and-push: + jobs: + - build-and-push: + context: dockerhub diff --git a/.circleci/local_config.yml b/.circleci/local_config.yml new file mode 100644 index 00000000..e9c7f207 --- /dev/null +++ b/.circleci/local_config.yml @@ -0,0 +1,32 @@ +version: 2 +jobs: + build-and-push: + docker: + - image: cimg/base:stable + steps: + - checkout + - setup_remote_docker + - run: + name: Login to DockerHub + command: | + echo "Attempting to login to DockerHub..." + echo "$DOCKERHUB_TOKEN" | sudo docker login -u "$DOCKERHUB_USERNAME" --password-stdin + - run: + name: Build and push Docker images + command: | + # Get the short SHA or use 'latest' as fallback + SHORT_SHA=${CIRCLE_SHA1:-rc1} + + sudo docker buildx create --use + sudo docker buildx build \ + --platform linux/amd64 \ + -t freikin/dawarich:${SHORT_SHA} \ + -t freikin/dawarich:rc \ + -f docker/Dockerfile.dev \ + --push . +workflows: + version: 2 + build-and-push: + jobs: + - build-and-push: + context: dockerhub diff --git a/.ruby-version b/.ruby-version index a0891f56..47b322c9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.4 +3.4.1 diff --git a/Gemfile b/Gemfile index 0a30ff39..f4505e9b 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem 'puma' gem 'pundit' gem 'rails', '~> 8.0' gem 'racc', '~> 1.8', '>= 1.8.1' # Nokogiri dependency +gem 'nokogiri', '1.18.1' gem 'rgeo' gem 'rswag-api' gem 'rswag-ui' diff --git a/Gemfile.lock b/Gemfile.lock index 144f3b3d..6778fe11 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -223,18 +223,18 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.7.4) - nokogiri (1.18.2) + nokogiri (1.18.1) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.2-aarch64-linux-gnu) + nokogiri (1.18.1-aarch64-linux-gnu) racc (~> 1.4) - nokogiri (1.18.2-arm-linux-gnu) + nokogiri (1.18.1-arm-linux-gnu) racc (~> 1.4) - nokogiri (1.18.2-arm64-darwin) + nokogiri (1.18.1-arm64-darwin) racc (~> 1.4) - nokogiri (1.18.2-x86_64-darwin) + nokogiri (1.18.1-x86_64-darwin) racc (~> 1.4) - nokogiri (1.18.2-x86_64-linux-gnu) + nokogiri (1.18.1-x86_64-linux-gnu) racc (~> 1.4) oj (3.16.9) bigdecimal (>= 3.0) @@ -475,6 +475,7 @@ DEPENDENCIES importmap-rails kaminari lograge + nokogiri (= 1.18.1) oj pg prometheus_exporter @@ -507,7 +508,7 @@ DEPENDENCIES webmock RUBY VERSION - ruby 3.3.4p94 + ruby 3.4.1p0 BUNDLED WITH 2.5.21 diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 37b04015..710ad7d2 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:3.3.4-alpine +FROM ruby:3.4.1-bookworm ENV APP_PATH=/var/app ENV BUNDLE_VERSION=2.5.21 @@ -8,20 +8,22 @@ ENV RAILS_PORT=3000 ENV RAILS_ENV=development # Install dependencies for application -RUN apk -U add --no-cache \ - build-base \ +RUN apt-get update && apt-get install -y \ + build-essential \ git \ - postgresql-dev \ postgresql-client \ + libpq-dev \ libxml2-dev \ libxslt-dev \ nodejs \ - yarn \ + npm \ imagemagick \ tzdata \ less \ - yaml-dev \ - gcompat \ + libyaml-dev \ + && npm install -g yarn \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ && mkdir -p $APP_PATH # Update gem system and install bundler @@ -36,7 +38,7 @@ COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ # Install all gems into the image RUN bundle config set --local path 'vendor/bundle' \ && bundle install --jobs 4 --retry 3 \ - && rm -rf vendor/bundle/ruby/3.3.0/cache/*.gem + && rm -rf vendor/bundle/ruby/3.4.0/cache/*.gem # Copy the rest of the application COPY ../. ./ From b3cf8e50fcedc015c1b1d7c302759e5f1062e649 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 19:16:05 +0100 Subject: [PATCH 50/61] Add gcc, g++, make --- docker/Dockerfile.dev | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 710ad7d2..d07f1754 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -21,6 +21,9 @@ RUN apt-get update && apt-get install -y \ tzdata \ less \ libyaml-dev \ + gcc \ + g++ \ + make \ && npm install -g yarn \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ From d2166322210e74c110a1c745496e7e66d4601ab5 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 20:03:52 +0100 Subject: [PATCH 51/61] Remove unused files and return arm64 support --- .circleci/docker.yml | 34 ---------------------------- .circleci/local_config.yml | 32 -------------------------- .github/workflows/build_and_push.yml | 2 +- 3 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 .circleci/docker.yml delete mode 100644 .circleci/local_config.yml diff --git a/.circleci/docker.yml b/.circleci/docker.yml deleted file mode 100644 index 5d9a5804..00000000 --- a/.circleci/docker.yml +++ /dev/null @@ -1,34 +0,0 @@ -version: 2.1 - -jobs: - build-and-push: - docker: - - image: cimg/base:stable - steps: - - checkout - - setup_remote_docker - - run: - name: Login to DockerHub - command: | - echo "Attempting to login to DockerHub..." - echo "$DOCKERHUB_TOKEN" | sudo docker login -u "$DOCKERHUB_USERNAME" --password-stdin - - run: - name: Build and push Docker images - command: | - # Get the short SHA or use 'latest' as fallback - SHORT_SHA=${CIRCLE_SHA1:-rc1} - - sudo docker buildx create --use - sudo docker buildx build \ - --platform linux/amd64 \ - -t freikin/dawarich:${SHORT_SHA} \ - -t freikin/dawarich:rc \ - -f docker/Dockerfile.dev \ - --push . - -workflows: - version: 2 - build-and-push: - jobs: - - build-and-push: - context: dockerhub diff --git a/.circleci/local_config.yml b/.circleci/local_config.yml deleted file mode 100644 index e9c7f207..00000000 --- a/.circleci/local_config.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: 2 -jobs: - build-and-push: - docker: - - image: cimg/base:stable - steps: - - checkout - - setup_remote_docker - - run: - name: Login to DockerHub - command: | - echo "Attempting to login to DockerHub..." - echo "$DOCKERHUB_TOKEN" | sudo docker login -u "$DOCKERHUB_USERNAME" --password-stdin - - run: - name: Build and push Docker images - command: | - # Get the short SHA or use 'latest' as fallback - SHORT_SHA=${CIRCLE_SHA1:-rc1} - - sudo docker buildx create --use - sudo docker buildx build \ - --platform linux/amd64 \ - -t freikin/dawarich:${SHORT_SHA} \ - -t freikin/dawarich:rc \ - -f docker/Dockerfile.dev \ - --push . -workflows: - version: 2 - build-and-push: - jobs: - - build-and-push: - context: dockerhub diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 7269311a..cec9369f 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -77,6 +77,6 @@ jobs: file: ./docker/Dockerfile.dev push: true tags: ${{ steps.docker_meta.outputs.tags }} - platforms: linux/amd64,linux/arm/v7,linux/arm/v6 + platforms: linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache From b30cdee89a0dd361d8239fb6c760572574b18045 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 20:25:34 +0100 Subject: [PATCH 52/61] Address rgeo install issues --- docker/Dockerfile.dev | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index d07f1754..fafa864d 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -24,6 +24,8 @@ RUN apt-get update && apt-get install -y \ gcc \ g++ \ make \ + libgeos-dev \ + libproj-dev \ && npm install -g yarn \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ From e6faa8e4b83113ca9a7e39961c400ae958b97738 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 20:47:12 +0100 Subject: [PATCH 53/61] Unify build and push actions --- .github/workflows/build_and_push.yml | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index cec9369f..bee32d42 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -19,10 +19,10 @@ jobs: with: ref: ${{ github.event.inputs.branch || github.ref_name }} - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Cache Docker layers uses: actions/cache@v4 @@ -59,24 +59,13 @@ jobs: echo "tags=${TAGS}" >> $GITHUB_OUTPUT - - name: Build and push (arm64) + - name: Build and push uses: docker/build-push-action@v6 with: context: . file: ./docker/Dockerfile.dev push: true tags: ${{ steps.docker_meta.outputs.tags }} - platforms: linux/arm64 + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-arm64 - - - name: Build and push (other architectures) - uses: docker/build-push-action@v2 - with: - context: . - file: ./docker/Dockerfile.dev - push: true - tags: ${{ steps.docker_meta.outputs.tags }} - platforms: linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64 - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new From 21022d56a6e0365e6e146e81caf3570bf268e3af Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 21:23:46 +0100 Subject: [PATCH 54/61] Update Dockerfile for ARM64 --- docker/Dockerfile.dev | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index fafa864d..fde81d23 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -21,15 +21,17 @@ RUN apt-get update && apt-get install -y \ tzdata \ less \ libyaml-dev \ - gcc \ - g++ \ + gcc-11 \ + g++-11 \ make \ libgeos-dev \ libproj-dev \ && npm install -g yarn \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ - && mkdir -p $APP_PATH + && mkdir -p $APP_PATH \ + && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \ + && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 # Update gem system and install bundler RUN gem update --system 3.6.2 \ @@ -40,9 +42,11 @@ WORKDIR $APP_PATH COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ -# Install all gems into the image +# Install all gems into the image with reduced parallelism for ARM64 RUN bundle config set --local path 'vendor/bundle' \ - && bundle install --jobs 4 --retry 3 \ + && bundle config set --local jobs 2 \ + && bundle config set build.nokogiri --use-system-libraries \ + && bundle install --retry 3 \ && rm -rf vendor/bundle/ruby/3.4.0/cache/*.gem # Copy the rest of the application From 13be27d311356fe2e7002f0a150b3142481998e4 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 21:57:34 +0100 Subject: [PATCH 55/61] What do we have to lose --- docker/Dockerfile.dev | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index fde81d23..033ab493 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -21,8 +21,8 @@ RUN apt-get update && apt-get install -y \ tzdata \ less \ libyaml-dev \ - gcc-11 \ - g++-11 \ + gcc-10 \ + g++-10 \ make \ libgeos-dev \ libproj-dev \ @@ -30,8 +30,8 @@ RUN apt-get update && apt-get install -y \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && mkdir -p $APP_PATH \ - && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \ - && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 + && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 \ + && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 # Update gem system and install bundler RUN gem update --system 3.6.2 \ @@ -42,10 +42,17 @@ WORKDIR $APP_PATH COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ +# Set environment variables for compilation +ENV CFLAGS="-O2 -pipe -fstack-protector-strong" \ + CXXFLAGS="-O2 -pipe -fstack-protector-strong" \ + MAKEFLAGS="-j2" + # Install all gems into the image with reduced parallelism for ARM64 RUN bundle config set --local path 'vendor/bundle' \ && bundle config set --local jobs 2 \ && bundle config set build.nokogiri --use-system-libraries \ + && bundle config build.racc --with-cflags="-O2 -pipe" \ + && bundle config build.oj --with-cflags="-O2 -pipe" \ && bundle install --retry 3 \ && rm -rf vendor/bundle/ruby/3.4.0/cache/*.gem From 927ca31471e110302e205876aff87d8b0b9484da Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 22:05:14 +0100 Subject: [PATCH 56/61] Update Dockerfile for ARM64 --- docker/Dockerfile.dev | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 033ab493..813f0beb 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -21,17 +21,15 @@ RUN apt-get update && apt-get install -y \ tzdata \ less \ libyaml-dev \ - gcc-10 \ - g++-10 \ + gcc \ + g++ \ make \ libgeos-dev \ libproj-dev \ && npm install -g yarn \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ - && mkdir -p $APP_PATH \ - && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 \ - && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 + && mkdir -p $APP_PATH # Update gem system and install bundler RUN gem update --system 3.6.2 \ @@ -43,16 +41,16 @@ WORKDIR $APP_PATH COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ # Set environment variables for compilation -ENV CFLAGS="-O2 -pipe -fstack-protector-strong" \ - CXXFLAGS="-O2 -pipe -fstack-protector-strong" \ +ENV CFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing" \ + CXXFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing" \ MAKEFLAGS="-j2" # Install all gems into the image with reduced parallelism for ARM64 RUN bundle config set --local path 'vendor/bundle' \ && bundle config set --local jobs 2 \ && bundle config set build.nokogiri --use-system-libraries \ - && bundle config build.racc --with-cflags="-O2 -pipe" \ - && bundle config build.oj --with-cflags="-O2 -pipe" \ + && bundle config build.racc --with-cflags="-O2 -pipe -fno-strict-aliasing" \ + && bundle config build.oj --with-cflags="-O2 -pipe -fno-strict-aliasing" \ && bundle install --retry 3 \ && rm -rf vendor/bundle/ruby/3.4.0/cache/*.gem From 4662e97d067c244569960414010a3058b8658ae2 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 22:40:42 +0100 Subject: [PATCH 57/61] Remove gem specific compilation flags --- docker/Dockerfile.dev | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 813f0beb..6b9f01f2 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -43,14 +43,13 @@ COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ # Set environment variables for compilation ENV CFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing" \ CXXFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing" \ - MAKEFLAGS="-j2" + MAKEFLAGS="-j2" \ + BUNDLE_FORCE_RUBY_PLATFORM="true" # Install all gems into the image with reduced parallelism for ARM64 RUN bundle config set --local path 'vendor/bundle' \ && bundle config set --local jobs 2 \ && bundle config set build.nokogiri --use-system-libraries \ - && bundle config build.racc --with-cflags="-O2 -pipe -fno-strict-aliasing" \ - && bundle config build.oj --with-cflags="-O2 -pipe -fno-strict-aliasing" \ && bundle install --retry 3 \ && rm -rf vendor/bundle/ruby/3.4.0/cache/*.gem From 7579ad75f36ded90ea18e5623475dd13ba995b81 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Feb 2025 23:19:50 +0100 Subject: [PATCH 58/61] Update Dockerfile.dev for ARM64 --- docker/Dockerfile.dev | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 6b9f01f2..fed795ea 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -8,11 +8,13 @@ ENV RAILS_PORT=3000 ENV RAILS_ENV=development # Install dependencies for application -RUN apt-get update && apt-get install -y \ +RUN dpkg --add-architecture arm64 && \ + apt-get update && apt-get install -y \ build-essential \ git \ - postgresql-client \ - libpq-dev \ + postgresql-client:arm64 \ + libpq-dev:arm64 \ + libpq5:arm64 \ libxml2-dev \ libxslt-dev \ nodejs \ From ebd4694e9fa87c35f4a96b1038df44175fecd215 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 6 Feb 2025 18:01:22 +0100 Subject: [PATCH 59/61] Change to ubuntu-22.04 for github actions --- .github/workflows/build_and_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index bee32d42..a306871a 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -12,7 +12,7 @@ on: jobs: build-and-push-docker: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout code uses: actions/checkout@v2 From 9837c093fe9076429c40165980586693ad17112f Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 6 Feb 2025 18:06:03 +0100 Subject: [PATCH 60/61] Update github actions to use ubuntu-22.04 and use old actions file --- .github/workflows/build_and_push.yml | 7 ++--- docker/Dockerfile.dev | 39 ++++++++-------------------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index a306871a..49580227 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -15,9 +15,10 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.branch || github.ref_name }} + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -60,7 +61,7 @@ jobs: echo "tags=${TAGS}" >> $GITHUB_OUTPUT - name: Build and push - uses: docker/build-push-action@v6 + uses: docker/build-push-action@v5 with: context: . file: ./docker/Dockerfile.dev @@ -68,4 +69,4 @@ jobs: tags: ${{ steps.docker_meta.outputs.tags }} platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index fed795ea..41b65721 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:3.4.1-bookworm +FROM ruby:3.4.1-alpine ENV APP_PATH=/var/app ENV BUNDLE_VERSION=2.5.21 @@ -8,29 +8,20 @@ ENV RAILS_PORT=3000 ENV RAILS_ENV=development # Install dependencies for application -RUN dpkg --add-architecture arm64 && \ - apt-get update && apt-get install -y \ - build-essential \ +RUN apk -U add --no-cache \ + build-base \ git \ - postgresql-client:arm64 \ - libpq-dev:arm64 \ - libpq5:arm64 \ + postgresql-dev \ + postgresql-client \ libxml2-dev \ libxslt-dev \ nodejs \ - npm \ + yarn \ imagemagick \ tzdata \ less \ - libyaml-dev \ - gcc \ - g++ \ - make \ - libgeos-dev \ - libproj-dev \ - && npm install -g yarn \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ + yaml-dev \ + gcompat \ && mkdir -p $APP_PATH # Update gem system and install bundler @@ -42,18 +33,10 @@ WORKDIR $APP_PATH COPY ../Gemfile ../Gemfile.lock ../.ruby-version ../vendor ./ -# Set environment variables for compilation -ENV CFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing" \ - CXXFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing" \ - MAKEFLAGS="-j2" \ - BUNDLE_FORCE_RUBY_PLATFORM="true" - -# Install all gems into the image with reduced parallelism for ARM64 +# Install all gems into the image RUN bundle config set --local path 'vendor/bundle' \ - && bundle config set --local jobs 2 \ - && bundle config set build.nokogiri --use-system-libraries \ - && bundle install --retry 3 \ - && rm -rf vendor/bundle/ruby/3.4.0/cache/*.gem + && bundle install --jobs 4 --retry 3 \ + && rm -rf vendor/bundle/ruby/3.3.0/cache/*.gem # Copy the rest of the application COPY ../. ./ From 6072e46affcac0442772ee25197a6cd0b8a57600 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 6 Feb 2025 19:38:14 +0100 Subject: [PATCH 61/61] Update Ruby version in CircleCI --- .circleci/config.yml | 2 +- CHANGELOG.md | 3 ++- Gemfile | 2 -- Gemfile.lock | 2 -- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 460be1ea..ff43fbcc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ orbs: jobs: test: docker: - - image: cimg/ruby:3.3.4 + - image: cimg/ruby:3.4.1 environment: RAILS_ENV: test - image: cimg/postgres:13.3-postgis diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dd4398c..9024ee26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ 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.23.6 - 2025-01-29 +# 0.23.6 - 2025-02-06 ### Added @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- Ruby version was updated to 3.4.1. - Requesting photos on the Map page now uses the start and end dates from the URL params. #589 # 0.23.5 - 2025-01-22 diff --git a/Gemfile b/Gemfile index f4505e9b..592c2fd3 100644 --- a/Gemfile +++ b/Gemfile @@ -23,8 +23,6 @@ gem 'activerecord-postgis-adapter', github: 'StoneGod/activerecord-postgis-adapt gem 'puma' gem 'pundit' gem 'rails', '~> 8.0' -gem 'racc', '~> 1.8', '>= 1.8.1' # Nokogiri dependency -gem 'nokogiri', '1.18.1' gem 'rgeo' gem 'rswag-api' gem 'rswag-ui' diff --git a/Gemfile.lock b/Gemfile.lock index 6778fe11..4bf8fa71 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -475,7 +475,6 @@ DEPENDENCIES importmap-rails kaminari lograge - nokogiri (= 1.18.1) oj pg prometheus_exporter @@ -483,7 +482,6 @@ DEPENDENCIES pry-rails puma pundit - racc (~> 1.8, >= 1.8.1) rails (~> 8.0) redis rgeo