Skip to content

Commit a01a6fd

Browse files
author
Mattia Roccoberton
committed
chore: Docker setup for MSSQL
1 parent 9857674 commit a01a6fd

4 files changed

Lines changed: 62 additions & 5 deletions

File tree

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
66
gemspec
77

88
group :development, :test do
9+
if ENV['DB_TEST'] == 'mssql'
10+
gem 'activerecord-sqlserver-adapter', '7.0.3.0'
11+
gem 'tiny_tds'
12+
end
913
gem 'mysql2' if ENV['DB_TEST'] == 'mysql'
1014
gem 'pg' if ['postgres', 'postgresql'].include? ENV['DB_TEST']
15+
1116
gem 'simplecov'
1217
gem 'simplecov-lcov'
1318

extra/Dockerfile_32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ruby:3.2-slim
33
ARG DB_TEST
44

55
RUN apt-get update
6-
RUN apt-get install --no-install-recommends -y build-essential curl file git nano netcat-traditional libmariadb-dev libpq-dev openssl tzdata
6+
RUN apt-get install --no-install-recommends -y build-essential curl file freetds-dev freetds-bin git nano netcat-traditional libmariadb-dev libpq-dev openssl tzdata
77

88
# App setup
99
WORKDIR /usr/src/app

extra/docker-compose.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22
version: "3.3"
33

44
x-defaults:
5+
tests_mssql: &tests_mssql
6+
environment:
7+
CI: 1
8+
DB_TEST: mssql
9+
DB_PORT: 1433
10+
MSSQL_DB_HOST: mssql
11+
MSSQL_DB_NAME: test_db
12+
MSSQL_DB_USERNAME: sa
13+
MSSQL_DB_PASSWORD: Pa%%w0rd
14+
RAILS: '7.0'
15+
RAILS_ENV: test
16+
command:
17+
- sh
18+
- -c
19+
- |
20+
while ! nc -z $${DB_TEST} $${DB_PORT} </dev/null
21+
do echo "Waiting for DB ($${DB_TEST})..." && sleep 5; done
22+
echo "DB is now available!"
23+
cd spec/dummy70
24+
bin/setup
25+
cd ../..
26+
bin/rspec
27+
volumes:
28+
- ..:/usr/src/app:delegated
29+
depends_on:
30+
- mssql
31+
532
tests_mysql: &tests_mysql
633
environment:
734
CI: 1
@@ -57,17 +84,24 @@ x-defaults:
5784
- postgres
5885

5986
services:
60-
postgres:
61-
image: postgres
87+
mssql:
88+
image: mcr.microsoft.com/mssql/server:2022-latest
89+
platform: linux/amd64
6290
environment:
63-
POSTGRES_PASSWORD: password
91+
ACCEPT_EULA: 'Y'
92+
SA_PASSWORD: Pa%%w0rd
6493

6594
mysql:
6695
image: mysql
6796
platform: linux/amd64
6897
environment:
6998
MYSQL_ROOT_PASSWORD: password
7099

100+
postgres:
101+
image: postgres
102+
environment:
103+
POSTGRES_PASSWORD: password
104+
71105
tests_30_mysql:
72106
<<: *tests_mysql
73107
build:
@@ -84,6 +118,14 @@ services:
84118
args:
85119
DB_TEST: postgres
86120

121+
tests_32_mssql:
122+
<<: *tests_mssql
123+
build:
124+
context: ..
125+
dockerfile: extra/Dockerfile_32
126+
args:
127+
DB_TEST: mssql
128+
87129
tests_32_mysql:
88130
<<: *tests_mysql
89131
build:

spec/dummy70/config/database.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<% case ENV['DB_TEST']
2-
when 'mysql' %>
2+
when 'mssql' %>
3+
test: &test
4+
adapter: sqlserver
5+
host: <%= ENV.fetch('MSSQL_DB_HOST') { '127.0.0.1' } %>
6+
# port: <%= ENV.fetch('MSSQL_DB_PORT') { 1433 } %>
7+
database: <%= ENV.fetch('MSSQL_DB_NAME') { ver = ENV.fetch('RAILS', '').tr('.', ''); "active_storage_db_#{ver}-test" } %>
8+
username: <%= ENV.fetch('MSSQL_DB_USERNAME') { '' } %>
9+
password: <%= ENV.fetch('MSSQL_DB_PASSWORD') { '' } %>
10+
encoding: utf8
11+
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
12+
<% when 'mysql' %>
313
test: &test
414
adapter: mysql2
515
host: <%= ENV.fetch('MYSQL_DB_HOST') { '127.0.0.1' } %>

0 commit comments

Comments
 (0)