Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue-16/dev-tooling--add-basic-…
Browse files Browse the repository at this point in the history
…test-suite-setup-to-project' into marlen/dependency-bundle
  • Loading branch information
klondikemarlen committed Aug 8, 2023
2 parents 7b31dda + 00fe337 commit 6c5b127
Show file tree
Hide file tree
Showing 12 changed files with 12,941 additions and 5,388 deletions.
12 changes: 5 additions & 7 deletions bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,17 @@ class DevHelper

def debug
api_container_id = container_id('api')
puts 'Awaiting binding.pry to trigger...'
puts "'ctrl-c' to exit"
puts 'Waiting for breakpoint to trigger...'
puts "'ctrl-c' to exit."
command = "docker attach --detach-keys ctrl-c #{api_container_id}"
puts "Running: #{command}"
exec(command)
exit 0
end

# def mocha(*args, **kwargs)
# run(*%w[test npm run test], *args, **kwargs)
# end

# alias test mocha
def test(*args, **kwargs)
run(*%w[test npm run test], *args, **kwargs)
end

def npm(*args, **kwargs)
run(*%w[api npm], *args, **kwargs)
Expand Down
30 changes: 30 additions & 0 deletions db/bin/configure-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Wait 60 seconds for SQL Server to start up by ensuring that
# calling SQLCMD does not return an error code, which will ensure that sqlcmd is accessible
# and that system and user databases return "0" which means all databases are in an "online" state
# https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-databases-transact-sql?view=sql-server-2017

DBSTATUS=1
ERRCODE=1
i=0

while [[ $DBSTATUS -ne 0 ]] && [[ $i -lt 60 ]] && [[ $ERRCODE -ne 0 ]]; do
i=$i+1
DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P "$MSSQL_SA_PASSWORD" -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases")
ERRCODE=$?
sleep 1
done

if [[ $DBSTATUS -ne 0 ]] || [[ $ERRCODE -ne 0 ]]; then
echo "SQL Server took more than 60 seconds to start up or one or more databases are not in an ONLINE state"
exit 1
fi

# Run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd \
-S localhost \
-U sa \
-P "$MSSQL_SA_PASSWORD" \
-d master \
-i ./initializers/setup.sql
20 changes: 20 additions & 0 deletions db/db.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/mssql/server:2019-latest

# current user:group => $whoami:$(id -gn) => mssql:root
USER root
RUN mkdir -p /usr/src/db && chown mssql:root /usr/src/db
USER mssql

WORKDIR /usr/src/db

# Data
# COPY ./db/data /var/opt/mssql/data
# COPY ./db/log /var/opt/mssql/log
# COPY ./db/backups /var/opt/mssql/data/backups

# Intialization
COPY --chown=mssql:root --chmod=+x ./db/entrypoint.sh ./
COPY --chown=mssql:root --chmod=+x ./db/bin ./bin
COPY --chown=mssql:root ./db/initializers ./initializers

ENTRYPOINT ["/usr/src/db/entrypoint.sh"]
8 changes: 8 additions & 0 deletions db/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Start the script to create the DB and user
cd /usr/src/db
./bin/configure-db.sh &

# Start SQL Server
/opt/mssql/bin/sqlservr
21 changes: 21 additions & 0 deletions db/initializers/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Enter custom T-SQL here that would run after SQL Server has started up.
*/

IF NOT EXISTS (
SELECT name
FROM sys.databases
WHERE name = N'SFADB_DEV'
)
CREATE DATABASE SFADB_DEV;
GO

IF NOT EXISTS (
SELECT name
FROM sys.databases
WHERE name = N'sfa_client_test'
)
CREATE DATABASE sfa_client_test;
GO
46 changes: 40 additions & 6 deletions docker-compose.development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,64 @@ services:
dockerfile: development.Dockerfile
env_file:
- ./src/api/.env.development
environment:
environment: &environment-definition
NODE_ENV: development
DB_NAME: SFADB_DEV
DB_HOST: db
DB_USER: sa
DB_PASS: &password-definition Testing1122
DB_PORT: 1433
DB_DEFAULT_SCHEMA: sfa
API_PORT: ${API_PORT:-3000}
BASE_URL: "http://localhost:${API_PORT:-3000}"
tty: true
ports:
- "${API_PORT:-3000}:${API_PORT:-3000}"
volumes:
- ./src/api:/usr/src/api
depends_on:
- db
db:
condition: service_healthy

test:
build:
context: ./src/api
dockerfile: development.Dockerfile
command: /bin/true
env_file:
- ./src/api/.env.development
environment:
<<: *environment-definition
NODE_ENV: test
DB_NAME: sfa_client_test
tty: true
volumes:
- ./src/api:/usr/src/api
depends_on:
db:
condition: service_healthy
db:
image: mcr.microsoft.com/mssql/server:2019-latest
build:
context: .
dockerfile: ./db/db.Dockerfile
ports:
- "1433:1433"
user: root
env_file:
- db/sqlserver.env
- db/sapassword.env
environment:
MSSQL_SA_PASSWORD: *password-definition
ACCEPT_EULA: "Y"
volumes:
- ./db/bin:/usr/src/db/bin
- ./db/initializers:/usr/src/db/initializers
- ./db/data:/var/opt/mssql/data
- ./db/log:/var/opt/mssql/log
- ./db/backups:/var/opt/mssql/data/backups
healthcheck: # https://github.com/Microsoft/mssql-docker/issues/133
test: "/opt/mssql-tools/bin/sqlcmd -U sa -P \"$$MSSQL_SA_PASSWORD\" -Q \"SELECT 1\" || exit 1"
interval: 5s
timeout: 10s
retries: 3
start_period: 5s
s3:
image: "minio/minio:latest"
ports:
Expand Down
11 changes: 11 additions & 0 deletions src/api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { JestConfigWithTsJest } from "ts-jest"

export const jestConfig: JestConfigWithTsJest = {
preset: "ts-jest",
testEnvironment: "node",
moduleNameMapper: {
"^@/(.*)$": ["<rootDir>/$1"],
},
}

export default jestConfig
Loading

0 comments on commit 6c5b127

Please sign in to comment.