Merge pull request #50 from blocknotes/dev/docker-setup

chore: Docker dev setup
Этот коммит содержится в:
Mattia Roccoberton
2025-03-14 15:57:12 +01:00
коммит произвёл GitHub
родитель 21fc69c2c0 9d891f0602
Коммит 728e3fa097
12 изменённых файлов: 244 добавлений и 35 удалений

2
.env Обычный файл
Просмотреть файл

@@ -0,0 +1,2 @@
UID=1000
GID=1000

53
Gemfile
Просмотреть файл

@@ -2,29 +2,34 @@
source 'https://rubygems.org'
gemspec
if ENV["DEVEL"] == "1"
gem 'rails', '~> 7.1.0'
group :development, :test do
gem 'puma'
gem 'sassc'
gem 'sprockets-rails'
gem 'sqlite3'
# Testing
gem 'capybara'
gem 'cuprite'
gem 'rspec_junit_formatter'
gem 'rspec-rails'
gem 'rspec-retry'
# Linters
gem 'fasterer'
gem 'rubocop'
gem 'rubocop-packaging'
gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rspec'
# Tools
gem 'pry-rails'
gem 'activeadmin', '~> 3.3'
gem 'activeadmin_quill_editor', path: './'
else
gemspec
end
gem 'puma'
gem 'sassc'
gem 'sprockets-rails'
gem 'sqlite3'
# Testing
gem 'capybara'
gem 'cuprite'
gem 'rspec_junit_formatter'
gem 'rspec-rails'
gem 'rspec-retry'
# Linters
gem 'fasterer'
gem 'rubocop'
gem 'rubocop-packaging'
gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rspec'
# Tools
gem 'pry-rails'

38
Makefile Обычный файл
Просмотреть файл

@@ -0,0 +1,38 @@
help:
@echo "Main targets: up / down / console / shell"
# Docker commands
down:
docker compose down
up:
docker compose up
attach:
docker compose attach app
up_attach:
docker compose up -d && docker compose attach app
cleanup:
docker container rm -f activeadmin_quill_editor_app && docker image rm -f activeadmin_quill_editor-app
# Rails specific commands
console:
docker compose exec -e "PAGER=more" app bin/rails console
routes:
docker compose exec app bin/rails routes
specs:
docker compose exec app bin/rspec --fail-fast
# Other commands
bundle:
docker compose exec app bundle
shell:
docker compose exec -e "PAGER=more" app bash
lint:
docker compose exec app bin/rubocop

Просмотреть файл

@@ -101,9 +101,26 @@ Consider that this is just a basic example: images are uploaded as soon as they
the *upload_admin_post_path*) and it doesn't provide a way to remove images (just deleting them from
the editor will not destroy them, you'll need to implement a purge logic for that).
## Changelog
## Development
The changelog is available [here](CHANGELOG.md).
Project created by [Mattia Roccoberton](http://blocknot.es), thanks also to the good guys that opened issues and pull requests from time to time.
A Docker dev setup is provided if you like to work with it:
```sh
# Run rails server on the dummy app (=> http://localhost:3000 to access to ActiveAdmin):
make up
# Enter in a console of the dummy app after it has been started:
make console
# Enter in a shell of the dummy app after it has been started:
make shell
# Run the linter on the project:
make lint
# Remove container and image after stopping the app:
make cleanup
```
For more commands please check the [Makefile](Makefile).
## Do you like it? Star it!
@@ -111,11 +128,6 @@ If you use this component just star it. A developer is more motivated to improve
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
## Contributors
- [Mattia Roccoberton](http://blocknot.es): author
- The good guys that opened issues and pull requests from time to time
## License
The gem is available as open-source under the terms of the [MIT](LICENSE.txt).

Просмотреть файл

@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.files = Dir['{app,lib}/**/*', 'LICENSE.txt', 'Rakefile', 'README.md']
spec.require_paths = ['lib']
spec.add_runtime_dependency 'activeadmin', '>= 2.9', '< 4'
spec.add_runtime_dependency 'activeadmin', '>= 2.9', '< 4' # rubocop:disable Gemspec/AddRuntimeDependency
spec.add_development_dependency 'appraisal', '~> 2.4' # rubocop:disable Gemspec/DevelopmentDependencies
end

20
docker-compose.yml Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
services:
app:
container_name: 'activeadmin_quill_editor_app'
build:
context: .
dockerfile: ./extra/Dockerfile
args:
RUBY_VERSION: 3.3.6
UID: ${UID}
user: "${UID}:${GID}"
ports:
- '3000:3000'
working_dir: '/app'
volumes:
- '.:/app'
stdin_open: true
tty: true
entrypoint:
- /bin/sh
- ./extra/entrypoint.sh

26
extra/Dockerfile Обычный файл
Просмотреть файл

@@ -0,0 +1,26 @@
ARG RUBY_VERSION=3
FROM ruby:${RUBY_VERSION}
ARG UID
ENV DEVEL=1
ENV LANG=C.UTF-8
ENV RAILS_ENV=development
RUN apt-get update -qq
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends build-essential chromium libyaml-dev
RUN gem install bundler
RUN echo 'gem: --no-document' > /etc/gemrc
COPY . /app
RUN mkdir -p /home/app
RUN useradd -u ${UID} --shell /bin/bash app
RUN chown -R app /usr/local/bundle
RUN chown -R app:app /home/app && chown -R app:app /app
USER ${UID}
WORKDIR /app
RUN bundle update

2
extra/entrypoint.sh Обычный файл
Просмотреть файл

@@ -0,0 +1,2 @@
cd spec/dummy && bundle exec rails db:migrate
cd - && rm -f spec/dummy/tmp/pids/server.pid && bundle exec rails s -b 0.0.0.0

Просмотреть файл

@@ -3,6 +3,11 @@ default: &default
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
schema_dump: schema_development.rb
test:
<<: *default
database: db/test.sqlite3

Просмотреть файл

@@ -29,7 +29,7 @@ Rails.application.configure do
end
# Store uploaded files on the local file system (see config/storage.yml for options).
# config.active_storage.service = :local
config.active_storage.service = :local
# # Don't care if the mailer can't send.
# config.action_mailer.raise_delivery_errors = false

99
spec/dummy/db/schema_development.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,99 @@
# 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.1].define(version: 2018_06_07_053739) do
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace"
t.text "body"
t.string "resource_type"
t.integer "resource_id"
t.string "author_type"
t.integer "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
t.index ["namespace"], name: "index_active_admin_comments_on_namespace"
t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
end
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.integer "record_id", null: false
t.integer "blob_id", null: false
t.datetime "created_at", precision: nil, null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end
create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", precision: nil, null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end
create_table "authors", force: :cascade do |t|
t.string "name"
t.integer "age"
t.string "email"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
end
create_table "post_tags", force: :cascade do |t|
t.integer "post_id"
t.integer "tag_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["post_id"], name: "index_post_tags_on_post_id"
t.index ["tag_id"], name: "index_post_tags_on_tag_id"
end
create_table "posts", force: :cascade do |t|
t.string "title"
t.text "summary"
t.text "description"
t.integer "author_id"
t.string "category"
t.datetime "dt", precision: nil
t.float "position"
t.boolean "published"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["author_id"], name: "index_posts_on_author_id"
end
create_table "profiles", force: :cascade do |t|
t.text "description"
t.integer "author_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["author_id"], name: "index_profiles_on_author_id"
end
create_table "tags", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "post_tags", "posts"
add_foreign_key "post_tags", "tags"
add_foreign_key "posts", "authors"
add_foreign_key "profiles", "authors"
end

Просмотреть файл

@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'spec_helper'
require_relative 'spec_helper'
ENV['RAILS_ENV'] = 'test'
@@ -12,7 +12,7 @@ require 'rspec/rails'
require 'capybara/rails'
require 'rspec/retry'
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require_relative f }
# Force deprecations to raise an exception.
# ActiveSupport::Deprecation.behavior = :raise