Skip to content

Commit

Permalink
chore: Docker setup for MSSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
blocknotes committed Nov 1, 2023
1 parent bcc8de3 commit 8b875f1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gemspec

group :development, :test do
if ENV['DB_TEST'] == 'mssql'
gem 'activerecord-sqlserver-adapter', '7.0.3.0'
gem 'tiny_tds'
end
gem 'mysql2' if ENV['DB_TEST'] == 'mysql'
gem 'pg' if ['postgres', 'postgresql'].include? ENV['DB_TEST']

gem 'simplecov'
gem 'simplecov-lcov'

Expand Down
2 changes: 1 addition & 1 deletion extra/Dockerfile_32
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ruby:3.2-slim
ARG DB_TEST

RUN apt-get update
RUN apt-get install --no-install-recommends -y build-essential curl file git nano netcat-traditional libmariadb-dev libpq-dev openssl tzdata
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

# App setup
WORKDIR /usr/src/app
Expand Down
48 changes: 45 additions & 3 deletions extra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@
version: "3.3"

x-defaults:
tests_mssql: &tests_mssql
environment:
CI: 1
DB_TEST: mssql
DB_PORT: 1433
MSSQL_DB_HOST: mssql
MSSQL_DB_NAME: test_db
MSSQL_DB_USERNAME: sa
MSSQL_DB_PASSWORD: Pa%%w0rd
RAILS: '7.0'
RAILS_ENV: test
command:
- sh
- -c
- |
while ! nc -z $${DB_TEST} $${DB_PORT} </dev/null
do echo "Waiting for DB ($${DB_TEST})..." && sleep 5; done
echo "DB is now available!"
cd spec/dummy70
bin/setup
cd ../..
bin/rspec
volumes:
- ..:/usr/src/app:delegated
depends_on:
- mssql

tests_mysql: &tests_mysql
environment:
CI: 1
Expand Down Expand Up @@ -57,17 +84,24 @@ x-defaults:
- postgres

services:
postgres:
image: postgres
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
platform: linux/amd64
environment:
POSTGRES_PASSWORD: password
ACCEPT_EULA: 'Y'
SA_PASSWORD: Pa%%w0rd

mysql:
image: mysql
platform: linux/amd64
environment:
MYSQL_ROOT_PASSWORD: password

postgres:
image: postgres
environment:
POSTGRES_PASSWORD: password

tests_30_mysql:
<<: *tests_mysql
build:
Expand All @@ -84,6 +118,14 @@ services:
args:
DB_TEST: postgres

tests_32_mssql:
<<: *tests_mssql
build:
context: ..
dockerfile: extra/Dockerfile_32
args:
DB_TEST: mssql

tests_32_mysql:
<<: *tests_mysql
build:
Expand Down
12 changes: 11 additions & 1 deletion spec/dummy70/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<% case ENV['DB_TEST']
when 'mysql' %>
when 'mssql' %>
test: &test
adapter: sqlserver
host: <%= ENV.fetch('MSSQL_DB_HOST') { '127.0.0.1' } %>
# port: <%= ENV.fetch('MSSQL_DB_PORT') { 3306 } %>
database: <%= ENV.fetch('MSSQL_DB_NAME') { ver = ENV.fetch('RAILS', '').tr('.', ''); "active_storage_db_#{ver}-test" } %>
username: <%= ENV.fetch('MSSQL_DB_USERNAME') { '' } %>
password: <%= ENV.fetch('MSSQL_DB_PASSWORD') { '' } %>
encoding: utf8
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
<% when 'mysql' %>
test: &test
adapter: mysql2
host: <%= ENV.fetch('MYSQL_DB_HOST') { '127.0.0.1' } %>
Expand Down

0 comments on commit 8b875f1

Please sign in to comment.