diff --git a/Makefile b/Makefile index 25bad38519..73c8ed7d44 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,9 @@ clean: changelog: docker compose run web bundle exec github_changelog_generator +db: + docker compose up -d db + time-to-live ?= 3h review_cluster = ${shell ./playbook-website/bin/deployer ./playbook-website/bin/cluster_for_review_stack pr$(pr)} diff --git a/docker-compose.yml b/docker-compose.yml index 08164e4db4..1b2650db3a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,3 +19,48 @@ services: - bundle:/usr/local/bundle ports: - "8089:3000" + db: + platform: linux/x86_64 + image: percona:8.0.27-18@sha256:f649b06357456689c24601fe919d585dce5b289c623bb547f84acc458c34c0d0 + init: true + ports: + - "3306:3306" # Map the host port 3306 to the container port 3306 + environment: + MYSQL_ROOT_HOST: "%" + MYSQL_ROOT_PASSWORD: password + healthcheck: + test: ["CMD", "mysql", "-u", "root", "-ppassword", "-e", "SHOW DATABASES;"] + interval: 5s + timeout: 2s + retries: 5 + start_period: 20s + networks: + - main + redis: + image: redis:7.4.0-alpine@sha256:c35af3bbcef51a62c8bae5a9a563c6f1b60d7ebaea4cb5a3ccbcc157580ae098 + healthcheck: + test: ["CMD", "redis-cli", "PING"] + interval: 5s + timeout: 2s + retries: 5 + start_period: 20s + ports: + - 6379 + networks: + - main + influxdb: + image: influxdb:2.7.10@sha256:aac51f94d98041e591aa4a5f36294080dd7987c1033ff115febfab98adcda61d + container_name: influxdb + environment: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: admin + DOCKER_INFLUXDB_INIT_PASSWORD: passwordpasswordpassword + DOCKER_INFLUXDB_INIT_ORG: web + DOCKER_INFLUXDB_INIT_BUCKET: app_data + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: influxdbwebtoken + ports: + - 8086:8086 + networks: + - main +networks: + main: diff --git a/playbook-website/Gemfile b/playbook-website/Gemfile index e74c01ade0..4f5bc2f843 100644 --- a/playbook-website/Gemfile +++ b/playbook-website/Gemfile @@ -18,6 +18,7 @@ gem "bootsnap", ">= 1.1.0", require: false # livenessProbe and readinessProbe. See: https://github.com/powerhome/playbook/blob/master/playbook/config/deploy/templates/deployment.yaml.erb gem "health_check" +gem "mysql2", "0.5.6" gem "redcarpet", "~> 3.6" gem 'front_matter_parser', "~> 1.0.1" gem "rouge", "~> 3.15" diff --git a/playbook-website/Gemfile.lock b/playbook-website/Gemfile.lock index 3bc1bfb9fe..4bc4e355a4 100644 --- a/playbook-website/Gemfile.lock +++ b/playbook-website/Gemfile.lock @@ -140,6 +140,7 @@ GEM mini_mime (1.1.5) minitest (5.25.1) msgpack (1.7.2) + mysql2 (0.5.6) net-imap (0.4.15) date net-protocol @@ -332,6 +333,7 @@ DEPENDENCIES front_matter_parser (~> 1.0.1) health_check listen + mysql2 (= 0.5.6) playbook_ui! psych (< 4) puma (~> 6.3) diff --git a/playbook-website/app/models/application_record.rb b/playbook-website/app/models/application_record.rb new file mode 100644 index 0000000000..08dc537989 --- /dev/null +++ b/playbook-website/app/models/application_record.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/playbook-website/bin/rails b/playbook-website/bin/rails index 6fb4e4051c..efc0377492 100755 --- a/playbook-website/bin/rails +++ b/playbook-website/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../config/application', __dir__) +APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/playbook-website/bin/setup b/playbook-website/bin/setup index 1ac8ce0b7a..ec47b79b3b 100755 --- a/playbook-website/bin/setup +++ b/playbook-website/bin/setup @@ -2,7 +2,7 @@ require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -13,16 +13,21 @@ FileUtils.chdir APP_ROOT do # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") - # Install JavaScript dependencies - system! 'bin/yarn' + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/playbook-website/config/application.rb b/playbook-website/config/application.rb index 786e521774..a2ef4578b4 100644 --- a/playbook-website/config/application.rb +++ b/playbook-website/config/application.rb @@ -6,7 +6,7 @@ # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" -# require "active_record/railtie" +require "active_record/railtie" # require "active_storage/engine" require "action_controller/railtie" # require "action_mailer/railtie" diff --git a/playbook-website/config/database.yml b/playbook-website/config/database.yml new file mode 100644 index 0000000000..d328f8c1a6 --- /dev/null +++ b/playbook-website/config/database.yml @@ -0,0 +1,20 @@ +default: &default + adapter: mysql2 + encoding: utf8 + pool: 5 + username: root + password: password + host: 127.0.0.1 + port: 3306 + +development: + <<: *default + database: playbook_website_dev + +test: + <<: *default + database: playbook_website_test + +production: + <<: *default + database: playbook_website_prod diff --git a/playbook-website/db/schema.rb b/playbook-website/db/schema.rb new file mode 100644 index 0000000000..dc29ad706d --- /dev/null +++ b/playbook-website/db/schema.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.0].define(version: 0) do +end