Skip to content

Commit 6ef3ebc

Browse files
committed
build: Improve dev setup
1 parent ad77250 commit 6ef3ebc

21 files changed

Lines changed: 100 additions & 428 deletions

.dockerignore

Lines changed: 0 additions & 17 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pkg/
77
/spec/dummy/db/*.sqlite3
88
/spec/dummy/db/*.sqlite3-journal
99
/spec/dummy/db/*.sqlite3-*
10+
/spec/dummy/db/schema-dev*
1011
/spec/dummy/log/
1112
/spec/dummy/storage/
1213
/spec/dummy/tmp/

Gemfile

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,33 @@ end
1212
ruby_ver = ENV.fetch('RUBY_VERSION', '')
1313
rails_ver = ENV.fetch('RAILS_VERSION', '')
1414

15-
rails = rails_ver.empty? ? ['rails'] : ['rails', "~> #{rails_ver}"]
15+
rails =
16+
if rails_ver.empty?
17+
['rails']
18+
elsif rails_ver.count('.') < 2
19+
['rails', "~> #{rails_ver}"]
20+
else
21+
['rails', rails_ver]
22+
end
1623
gem(*rails)
1724

18-
ruby32 = Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2')
25+
ruby32 = ruby_ver.empty? || Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2')
1926
gem 'zeitwerk', '~> 2.6.18' unless ruby32
2027

21-
# DB driver: mssql
22-
gem 'activerecord-sqlserver-adapter'
23-
gem 'tiny_tds'
24-
25-
# DB driver: mysql
26-
gem 'mysql2'
27-
28-
# DB driver: postgres
29-
gem 'pg'
30-
31-
# DB driver: sqlite
32-
rails72 = Gem::Version.new(rails_ver) >= Gem::Version.new('7.2')
33-
sqlite3 = ruby32 || rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4']
34-
gem(*sqlite3)
28+
# DB driver
29+
case ENV.fetch('DB_TEST', nil)
30+
when 'mssql'
31+
gem 'activerecord-sqlserver-adapter'
32+
gem 'tiny_tds'
33+
when 'mysql'
34+
gem 'mysql2'
35+
when 'postgres'
36+
gem 'pg'
37+
else
38+
rails72 = rails_ver.empty? || Gem::Version.new(rails_ver) >= Gem::Version.new('7.2')
39+
sqlite3 = ruby32 && rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4']
40+
gem(*sqlite3)
41+
end
3542

3643
# NOTE: to avoid error: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger
3744
gem 'concurrent-ruby', '1.3.4'

Makefile

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
include extra/.env
22

3+
DB ?= sqlite
4+
35
help:
4-
@echo -e "Usage (with DB one value in sqlite / mysql / mssql / postgres):\n DB=sqlite make up # to start the base service\n DB=sqlite make shell # to enter in a shell\nCheck the Makefile for other commands"
6+
@echo -e "${COMPOSE_PROJECT_NAME} - Main project commands (required env var: DB with a value in sqlite / mysql / mssql / postgres):\n\
7+
make up # starts the dev services (optional env vars: RUBY / RAILS)\n\
8+
make specs # run the tests (after up)\n\
9+
make lint # run the linters (after up)\n\
10+
make server # run the server (after up)\n\
11+
make shell # open a shell (after up)\n\
12+
make down # cleanup (after up)\n\n\
13+
Example: DB=postgres RUBY=3.2 RAILS=7.1.0 make up"
14+
15+
# System commands
516

617
build:
7-
@rm -f Gemfile.lock
18+
@rm -f Gemfile.lock spec/dummy/db/*.sqlite3
819
@docker compose -f extra/docker-compose.yml build --build-arg DB_TEST=${DB} app_with_${DB}
920

10-
up: build
21+
db_reset:
22+
@docker compose -f extra/docker-compose.yml run --rm app_with_${DB} extra/init.sh
23+
24+
up: build db_reset
1125
@docker compose -f extra/docker-compose.yml up app_with_${DB}
1226

1327
shell:
1428
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bash
1529

16-
specs:
17-
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/rspec --fail-fast
30+
down:
31+
@docker compose -f extra/docker-compose.yml down --volumes --rmi local --remove-orphans
1832

19-
console:
20-
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/rails c
33+
# App commands
2134

22-
server:
23-
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/rails s -b 0.0.0.0 -p ${SERVER_PORT}
24-
25-
appraisal_update:
26-
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/appraisal update
35+
console:
36+
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/rails console
2737

2838
lint:
2939
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/rubocop
3040

31-
cleanup:
32-
@docker compose -f extra/docker-compose.yml down -v --rmi local --remove-orphans
41+
server:
42+
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/rails server -b 0.0.0.0 -p ${SERVER_PORT}
43+
44+
specs:
45+
@docker compose -f extra/docker-compose.yml exec app_with_${DB} bin/rspec --fail-fast

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
[![maintainability](https://api.codeclimate.com/v1/badges/92e1e703c308744a0f66/maintainability)](https://codeclimate.com/github/blocknotes/active_storage_db/maintainability)
66

77
[![linters](https://github.com/blocknotes/active_storage_db/actions/workflows/linters.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/linters.yml)
8-
[![Specs Postgres Ruby 3.4](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_ruby34.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_ruby34.yml)
9-
[![Specs MySQL Ruby 3.4](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_ruby34.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_ruby34.yml)
8+
[![Specs Postgres Rails 8.0](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_rails80.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_rails80.yml)
9+
[![Specs MySQL Rails 8.0](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_rails80.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_rails80.yml)
1010

1111
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database.
1212
Experimental support also for MSSQL and SQLite.

active_storage_db.gemspec

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,4 @@ Gem::Specification.new do |spec|
2626

2727
spec.add_dependency 'activestorage', '>= 6.0'
2828
spec.add_dependency 'rails', '>= 6.0'
29-
30-
spec.add_development_dependency 'appraisal', '~> 2.4' # rubocop:disable Gemspec/DevelopmentDependencies
31-
spec.add_development_dependency 'factory_bot_rails', '~> 6.1' # rubocop:disable Gemspec/DevelopmentDependencies
3229
end

bin/appraisal

Lines changed: 0 additions & 29 deletions
This file was deleted.

extra/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ RUN useradd -u $UID --shell /bin/bash app
1818

1919
RUN mkdir -p /home/app && chown -R app:app /home/app
2020

21+
ARG DB_TEST
22+
ENV DB_TEST=$DB_TEST
23+
2124
ARG RAILS_VERSION
2225
ENV RAILS_VERSION=$RAILS_VERSION
2326

2427
WORKDIR /app
2528
COPY . /app
2629
RUN bundle install
27-
RUN chown -R app:app /app/spec/dummy/db /usr/local/bundle
30+
RUN chown -R app:app /usr/local/bundle
2831

2932
RUN ln -s /app/extra/.bashrc /home/app/.bashrc

extra/Dockerfile.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore everything but the required files for bundle install
2+
/**/*
3+
4+
!/*.gemspec
5+
!/Gemfile
6+
!/lib

extra/dev_setup.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/sh
22

3-
export DB_TEST=sqlite
4-
export RAILS_VERSION=8.0.2
5-
63
export DEVEL=1
7-
export RAILS_ENV=development
4+
5+
export DB_TEST=sqlite
6+
export RAILS_VERSION=8.0

0 commit comments

Comments
 (0)