Skip to content

Commit 8253e36

Browse files
committed
build: Improve dev setup
1 parent 74790fc commit 8253e36

File tree

8 files changed

+45
-36
lines changed

8 files changed

+45
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/_misc/
99
/coverage/
1010
/spec/dummy/db/*.sqlite3*
11+
/spec/dummy/db/schema-dev.rb
1112
/spec/dummy/log/
1213
/spec/dummy/storage/
1314
/spec/dummy/tmp/

Gemfile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@
22

33
source 'https://rubygems.org'
44

5+
def eval_version(dependency, version)
6+
return [dependency] if version.empty?
7+
8+
version.count('.') < 2 ? [dependency, "~> #{version}.0"] : [dependency, version]
9+
end
10+
511
if ENV['DEVEL'] == '1'
612
gem 'activeadmin_quill_editor', path: './'
713
else
814
gemspec
915
end
1016

1117
ruby_ver = ENV.fetch('RUBY_VERSION', '')
12-
rails_ver = ENV.fetch('RAILS_VERSION', '')
13-
activeadmin_ver = ENV.fetch('ACTIVEADMIN_VERSION', '')
1418

15-
rails = rails_ver.empty? ? ['rails'] : ['rails', "~> #{rails_ver}"]
19+
rails_ver = ENV.fetch('RAILS_VERSION', '')
20+
rails = eval_version('rails', rails_ver)
1621
gem(*rails)
1722

18-
activeadmin = activeadmin_ver.empty? ? ['activeadmin'] : ['activeadmin', "~> #{activeadmin_ver}"]
19-
gem(*activeadmin)
23+
active_admin_ver = ENV.fetch('ACTIVEADMIN_VERSION', '')
24+
active_admin = eval_version('activeadmin', active_admin_ver)
25+
gem(*active_admin)
2026

21-
ruby32 = Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2')
22-
rails72 = Gem::Version.new(rails_ver) >= Gem::Version.new('7.2')
23-
sqlite3 = ruby32 || rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4']
27+
ruby32 = ruby_ver.empty? || Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2')
28+
rails72 = rails_ver.empty? || Gem::Version.new(rails_ver) >= Gem::Version.new('7.2')
29+
sqlite3 = ruby32 && rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4']
2430
gem(*sqlite3)
2531

32+
gem 'zeitwerk', '~> 2.6.18' unless ruby32
33+
2634
# NOTE: to avoid error: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger
2735
gem 'concurrent-ruby', '1.3.4'
2836

Makefile

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

33
help:
4-
@echo "Main targets: build / specs / up / server / specs / shell"
4+
@echo -e "${COMPOSE_PROJECT_NAME} - Main project commands:\n\
5+
make up # starts the dev services (optional env vars: RUBY / RAILS / ACTIVEADMIN)\n\
6+
make specs # run the tests (after up)\n\
7+
make lint # run the linters (after up)\n\
8+
make server # run the server (after up)\n\
9+
make shell # open a shell (after up)\n\
10+
make down # cleanup (after up)\n\
11+
Example: RUBY=3.2 RAILS=7.1 ACTIVEADMIN=3.2.0 make up"
512

613
# System commands
714

@@ -10,7 +17,7 @@ build:
1017
@docker compose -f extra/docker-compose.yml build
1118

1219
db_reset:
13-
@docker compose -f extra/docker-compose.yml run --rm app bin/rails db:reset db:test:prepare
20+
@docker compose -f extra/docker-compose.yml run --rm app bin/rails db:create db:migrate db:test:prepare
1421

1522
up: build db_reset
1623
@docker compose -f extra/docker-compose.yml up
@@ -23,13 +30,16 @@ down:
2330

2431
# App commands
2532

26-
console:
33+
seed:
34+
@docker compose -f extra/docker-compose.yml exec app bin/rails db:seed
35+
36+
console: seed
2737
@docker compose -f extra/docker-compose.yml exec app bin/rails console
2838

2939
lint:
3040
@docker compose -f extra/docker-compose.yml exec app bin/rubocop
3141

32-
server:
42+
server: seed
3343
@docker compose -f extra/docker-compose.yml exec app bin/rails server -b 0.0.0.0 -p ${SERVER_PORT}
3444

3545
specs:

extra/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ ENV ACTIVEADMIN_VERSION=$ACTIVEADMIN_VERSION
2626
WORKDIR /app
2727
COPY . /app
2828
RUN bundle install
29-
RUN mkdir -p /app/spec/dummy/db && chown -R app:app /app/spec/dummy/db /usr/local/bundle
29+
RUN chown -R app:app /usr/local/bundle
3030

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

extra/dev_setup.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ export DEVEL=1
44

55
export RAILS_VERSION=7.2.2.1
66
export ACTIVEADMIN_VERSION=3.3.0
7-
8-
export RAILS_ENV=development

extra/development.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
## Development
22

3-
Overcommit can be used to ensure that Conventional commits are good.
4-
53
### Dev setup
64

7-
There 2 ways to interact with this project:
5+
There are 2 ways to interact with this project:
86

97
1) Using Docker:
108

119
```sh
12-
# Run rails server on the dummy app (=> http://localhost:3000 to access to ActiveAdmin):
13-
make up
14-
# Enter in a Rails console (with the dummy app started):
15-
make console
16-
# Enter in a shell (with the dummy app started):
17-
make shell
18-
# Run the linter on the project (with the dummy app started):
19-
make lint
20-
# Run the test suite (with the dummy app started):
21-
make specs
22-
# Remove container and image:
23-
make cleanup
24-
# To try different versions of Ruby/Rails/ActiveAdmin:
25-
RUBY=3.2 RAILS=7.1.0 ACTIVEADMIN=3.2.0 make up
26-
# For more commands please check the Makefile
10+
make up # starts the dev services (optional env vars: RUBY / RAILS / ACTIVEADMIN)
11+
make specs # run the tests (after up)
12+
make lint # run the linters (after up)
13+
make server # run the server (after up)
14+
make shell # open a shell (after up)
15+
make down # cleanup (after up)
16+
17+
# Example using specific versions:
18+
RUBY=3.2 RAILS=7.1 ACTIVEADMIN=3.2.0 make up
2719
```
2820

2921
2) With a local setup:

extra/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ services:
44
context: ..
55
dockerfile: extra/Dockerfile
66
args:
7-
ACTIVEADMIN_VERSION: ${ACTIVEADMIN:-}
87
BUNDLER_VERSION: ${BUNDLER_VERSION}
9-
RAILS_VERSION: ${RAILS:-}
108
RUBY_IMAGE: ruby:${RUBY:-3.4}-slim
9+
RAILS_VERSION: ${RAILS:-}
10+
ACTIVEADMIN_VERSION: ${ACTIVEADMIN:-}
1111
UID: ${UID}
1212
user: ${UID}:${GID}
1313
ports:

spec/dummy/config/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ default: &default
66
development:
77
<<: *default
88
database: db/development.sqlite3
9-
schema_dump: schema_development.rb
9+
schema_dump: schema-dev.rb
1010

1111
test:
1212
<<: *default

0 commit comments

Comments
 (0)