File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- Makefile
2- MIT-LICENSE
3- README.md
1+ /Makefile
2+ /MIT-LICENSE
3+ /Gemfile.lock
4+ /extra /init.sh
5+
6+ /app
7+ /bin
8+ /config
9+ /coverage
10+ /db
11+ /gemfiles
12+ /spec /dummy /db /* .sqlite3
13+ /spec /dummy /log
14+ /spec /dummy /tmp
15+ /spec /dummy /** /* _spec.rb
16+
17+ /** /* .md
Original file line number Diff line number Diff line change 1- include .env
1+ include extra/ .env
22
33help :
4- @echo " Main targets: build / up / specs / console / shell"
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 "
55
6- # Docker commands
76build :
87 @rm -f Gemfile.lock
9- @docker compose build
10-
11- down :
12- @docker compose down
8+ @docker compose -f extra/docker-compose.yml build --build-arg DB_TEST=${DB} app_with_${DB}
139
1410up : build
15- @docker compose up
16-
17- cleanup :
18- docker compose rm -f
19- docker image rm -f ${COMPOSE_PROJECT_NAME} -app
11+ @docker compose -f extra/docker-compose.yml up app_with_${DB}
2012
21- # App commands
22- server : build
23- COMMAND=" bin/rails s -b 0.0.0.0 -p 4000" docker compose up
13+ shell :
14+ @docker compose -f extra/docker-compose.yml exec app_with_${DB} bash
2415
25- specs : build
26- COMMAND= " bin/rspec " docker compose up
16+ specs :
17+ @ docker compose -f extra/docker-compose.yml exec app_with_ ${DB} bin/rspec --fail-fast
2718
28- appraisal_update : build
29- COMMAND= " bin/appraisal update " docker compose up
19+ server :
20+ @docker compose -f extra/docker-compose.yml exec app_with_ ${DB} bin/rails s -b 0.0.0.0 -p ${SERVER_PORT}
3021
31- lint : build
32- COMMAND= " bin/rubocop " docker compose up
22+ appraisal_update :
23+ @ docker compose -f extra/docker-compose.yml exec app_with_ ${DB} bin/appraisal update
3324
34- console :
35- docker compose exec -e " PAGER=more " app bin/rails console
25+ lint :
26+ @ docker compose -f extra/docker-compose.yml exec app_with_ ${DB} bin/rubocop
3627
37- shell :
38- docker compose exec -e " PAGER=more " app bash
28+ cleanup :
29+ @ docker compose -f extra/docker-compose.yml down -v --rmi local --remove-orphans
Original file line number Diff line number Diff line change 11#!/usr/bin/env ruby
2- # This command will automatically be run when you run "rails" with Rails gems
3- # installed from the root of your application.
42
5- ENV [ 'DB_TEST' ] ||= 'postgres '
6- ENV [ 'RAILS_ENV' ] ||= 'test '
3+ ENV [ 'DB_TEST' ] ||= 'sqlite '
4+ ENV [ 'RAILS_ENV' ] ||= 'development '
75
86ENGINE_ROOT = File . expand_path ( '..' , __dir__ )
97ENGINE_PATH = File . expand_path ( '../lib/active_storage_db/engine' , __dir__ )
108APP_PATH = File . expand_path ( "../spec/dummy/config/application" , __dir__ )
119
12- # Set up gems listed in the Gemfile.
1310ENV [ 'BUNDLE_GEMFILE' ] ||= File . expand_path ( '../Gemfile' , __dir__ )
1411require 'bundler/setup' if File . exist? ( ENV [ 'BUNDLE_GEMFILE' ] )
1512
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,3 +2,5 @@ COMPOSE_PROJECT_NAME=active_storage_db
22
33UID = 1000
44GID = 1000
5+
6+ SERVER_PORT = 4000
Original file line number Diff line number Diff line change 11ARG RUBY_IMAGE=ruby:3
22FROM ${RUBY_IMAGE}
33
4- ARG DB_TEST=sqlite
5- ARG RAILS_VERSION
6- ARG UID
7-
8- ENV DB_TEST=$DB_TEST
9- ENV DEVEL=1
10- ENV PROJECT_PATH=/app
11- ENV RAILS_ENV=development
12- ENV RAILS_VERSION=$RAILS_VERSION
13-
144ENV DEBIAN_FRONTEND=noninteractive
5+ ENV DEVEL=1
156ENV LANG=C.UTF-8
167
178RUN apt-get update -qq
18- RUN apt-get install -yqq --no-install-recommends build-essential nano pkg-config
9+ RUN apt-get install -yqq --no-install-recommends build-essential nano netcat-traditional pkg-config
1910RUN apt-get install -yqq --no-install-recommends freetds-dev libmariadb-dev libpq-dev libvips42 libyaml-dev sqlite3
2011
2112RUN gem install bundler -v 2.5.23
2213RUN echo 'gem: --no-document' > /etc/gemrc
2314
15+ ARG UID
2416RUN useradd -u $UID --shell /bin/bash app
25- RUN mkdir /app_deps && mkdir -p /home/app
17+
18+ RUN mkdir -p /home/app
2619RUN chown -R app:app /home/app
2720RUN chown -R app /usr/local/bundle
2821
22+ ARG RAILS_VERSION
23+ ENV RAILS_VERSION=$RAILS_VERSION
24+
2925WORKDIR /app
3026COPY . /app
3127RUN bundle install
32- RUN bin/rails db:create db:migrate db:test:prepare
3328RUN chown -R app:app /app/spec/dummy/db
34-
35- ENTRYPOINT ["extra/entrypoint.sh" ]
Original file line number Diff line number Diff line change @@ -5,26 +5,26 @@ There 3 ways to interact with this project:
551 ) Using Docker:
66
77``` sh
8- # Run build the dummy app image/container:
9- make build
10- # Run rails server on the dummy app:
8+ # Set the test DB driver (mysql / mssql / postgres / sqlite)
9+ export DB=sqlite
10+ # Start the base service (in the test dummy app):
11+ make up
12+ # With the base service started, start the Rails server (default port 4000):
1113make server
12- # Enter in a Rails console (with the dummy app started):
13- make console
14- # Enter in a shell (with the dummy app started):
14+ # With the base service started, enter in a shell:
1515make shell
1616
17- # Run the test suite:
17+ # With the base service started, run the test suite:
1818make specs
19- # Run the linter on the project:
19+ # With the base service started, run the linter on the project:
2020make lint
2121
2222# Remove container and image:
2323make cleanup
2424# For more commands please check the Makefile
2525
26- # To use a different Ruby version :
27- RUBY=3.0 make build
26+ # To use a different db, Ruby and Rails :
27+ DB=postgres RUBY=3.4 RAILS=7.2 make up
2828```
2929
30302 ) Using Appraisal:
Original file line number Diff line number Diff line change 1+ services :
2+ app : &app
3+ build :
4+ context : ..
5+ dockerfile : extra/Dockerfile
6+ args :
7+ # Debian-based Ruby image:
8+ RUBY_IMAGE : ruby:${RUBY:-3.2}-slim
9+ RAILS_VERSION : ${RAILS:-}
10+ UID : ${UID}
11+ user : ${UID}:${GID}
12+ ports :
13+ - ${SERVER_PORT}:${SERVER_PORT}
14+ working_dir : /app
15+ volumes :
16+ - ..:/app
17+ stdin_open : true
18+ tty : true
19+ command : ${COMMAND:-extra/init.sh}
20+
21+ mssql :
22+ image : mcr.microsoft.com/mssql/server:2022-latest
23+ platform : linux/amd64
24+ environment :
25+ ACCEPT_EULA : Y
26+ SA_PASSWORD : Pa%%w0rd
27+
28+ mysql :
29+ image : mysql
30+ platform : linux/amd64
31+ environment :
32+ MYSQL_ROOT_PASSWORD : password
33+
34+ postgres :
35+ image : postgres
36+ environment :
37+ POSTGRES_PASSWORD : password
38+
39+ app_with_mysql :
40+ << : *app
41+ environment :
42+ DB_TEST : mysql
43+ DB_PORT : 3306
44+ MYSQL_DB_HOST : mysql
45+ MYSQL_DB_NAME : test_db
46+ MYSQL_DB_USERNAME : root
47+ MYSQL_DB_PASSWORD : password
48+ depends_on :
49+ - mysql
50+
51+ app_with_mssql :
52+ << : *app
53+ environment :
54+ DB_TEST : mssql
55+ DB_PORT : 1433
56+ MSSQL_DB_HOST : mssql
57+ MSSQL_DB_NAME : test_db
58+ MSSQL_DB_USERNAME : sa
59+ MSSQL_DB_PASSWORD : Pa%%w0rd
60+ depends_on :
61+ - mssql
62+
63+ app_with_postgres :
64+ << : *app
65+ environment :
66+ DB_TEST : postgres
67+ DB_PORT : 5432
68+ PG_DB_HOST : postgres
69+ PG_DB_NAME : test_db
70+ PG_DB_USERNAME : postgres
71+ PG_DB_PASSWORD : password
72+ depends_on :
73+ - postgres
74+
75+ app_with_sqlite :
76+ << : *app
77+ environment :
78+ DB_TEST : sqlite
79+ volumes :
80+ - ..:/app
81+ - /app/spec/dummy/db
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ # Wait the DB
4+ if [ " $DB_TEST " != " sqlite" ]; then
5+ while ! nc -z $DB_TEST $DB_PORT < /dev/null
6+ do echo " Waiting for DB ($DB_TEST )..." && sleep 3; done
7+ echo " DB is now available!"
8+ fi
9+
10+ # Setup database
11+ bin/rails db:reset db:test:prepare
12+
13+ #
14+ sh
You can’t perform that action at this time.
0 commit comments