build: local development with oracle (#7881)

This commit is contained in:
MG 2021-11-09 10:00:14 +01:00 committed by GitHub
parent 1371ac3b6e
commit 4aaafdffe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 191 additions and 5 deletions

2
.gitignore vendored
View File

@ -5,7 +5,7 @@
build/
coverage/
node_modules/
ormconfig.json
/ormconfig.json
ormlogs.log
npm-debug.log
/test/github-issues/799/tmp/*

View File

@ -134,7 +134,7 @@ npm test
You should execute test suites before submitting a PR to github.
All the tests are executed on our Continuous Integration infrastructure and a PR could only be merged once the tests pass.
**Executing only some tests**: When you are creating tests to some specific code, you may want only execute the tests that you're creating, so you waste less time to verify your code. To do this, you can temporarily modify your tests definitions adding `.only` *mocha* commands **(describe, it)**. Example:
**Executing only some tests**: When you are creating tests to some specific code, you may want only execute the tests that you're creating, so you waste less time to verify your code. To do this, you can temporarily modify your tests definitions adding `.only` *mocha* commands **(describe, it)**. Example:
```
describe.only('your describe test', ....)
@ -165,3 +165,41 @@ in the root of the project. Once all images are fetched and run you can run test
- The docker image of mssql-server needs at least 3.25GB of RAM.
- Make sure to assign enough memory to the Docker VM if you're running on Docker for Mac or Windows
### Oracle XE
In order to run tests on Oracle XE locally, we need to start 2 docker containers:
- a container with Oracle XE database
- a container with typeorm and its tests
#### 1. Booting Oracle XE database
Execute in shell the next command:
```shell
docker-compose up -d oracle
```
It will start an oracle instance only.
The instance will be run in background,
therefore, we need to stop it later on.
#### 2. Booting typeorm for Oracle
Execute in shell the next command:
```shell
docker-compose -f docker-compose.oracle.yml up
```
it will start a nodejs instance which builds typeorm and executes unit tests.
The instance exits after the run.
#### 3. Shutting down Oracle XE database
Execute in shell the next command:
```shell
docker-compose down
```

15
docker-compose.oracle.yml Normal file
View File

@ -0,0 +1,15 @@
version: "3"
services:
oracle-test:
build:
context: docker/oracle
volumes:
- .:/typeorm
- /typeorm/build
- /typeorm/node_modules
networks:
- typeorm
networks:
typeorm:

View File

@ -73,6 +73,9 @@ services:
container_name: "typeorm-oracle"
ports:
- "1521:1521"
networks:
- default
- typeorm
# sap hana (works only on linux)
# hanaexpress:
@ -116,3 +119,6 @@ services:
# - "6379:6379"
#volumes:
# volume-hana-xe:
networks:
typeorm:

18
docker/oracle/Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM node:12
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -qq -y install libaio1 && \
apt-get -q -y autoremove && \
rm -Rf /var/lib/apt/lists/*
WORKDIR /typeorm
ENTRYPOINT ["/docker-entrypoint.sh"]
COPY . /
RUN chmod 0755 /docker-entrypoint.sh
ENV PATH="$PATH:/typeorm/node_modules/.bin"
ENV LD_LIBRARY_PATH="/typeorm/node_modules/oracledb/instantclient_19_8/:$LD_LIBRARY_PATH"
ENV BLOB_URL="https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basiclite-linux.x64-19.8.0.0.0dbru.zip"
CMD ["npm", "run", "test-fast"]

View File

@ -0,0 +1,16 @@
[
{
"skip": false,
"name": "oracle",
"type": "oracle",
"host": "typeorm-oracle",
"username": "system",
"password": "oracle",
"port": 1521,
"sid": "XE",
"logging": false,
"extra": {
"connectString": "typeorm-oracle:1521/XE"
}
}
]

View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# exit when any command fails
set -e
if [[ $INSTALL == 0 ]] && [[ ! -f ./package.json ]]; then
exit 0
fi
INSTALL=0
if [[ $INSTALL == 0 ]] && [[ "$(ls ./node_modules/ | wc -l | tr -d '\n')" == '0' ]]; then
INSTALL=1
fi
if [[ $INSTALL == 0 ]] && [[ ! -f ./node_modules/.md5 ]]; then
INSTALL=1
fi
if [[ $INSTALL == 0 ]] && ! md5sum --check ./node_modules/.md5; then
INSTALL=1
fi
if [[ $INSTALL == 1 ]]; then
npm ci --no-optional --ignore-scripts
md5sum ./package-lock.json > ./node_modules/.md5
fi

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# exit when any command fails
set -e
if [ ! -d node_modules/oracledb/instantclient_19_8 ]; then
curl -sf -o node_modules/oracledb/instantclient.zip $BLOB_URL
unzip -qqo node_modules/oracledb/instantclient.zip -d node_modules/oracledb/
rm node_modules/oracledb/instantclient.zip
cp /lib/*/libaio.so.* node_modules/oracledb/instantclient_19_8/
fi

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# exit when any command fails
set -e
npx rimraf build/compiled
npx tsc
cp /config/ormconfig.json build/compiled/ormconfig.json
if [ ! -f ormconfig.json ]; then
cp ormconfig.json.dist ormconfig.json
fi

View File

@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -e
child_pid=0
parent_pid=$$
catch_exits() {
echo "${0}:stopping ${child_pid}"
kill ${child_pid} &
wait
echo "${0}:stopped ${child_pid}"
echo "${0}:exit"
exit 0
}
trap catch_exits TERM KILL INT SIGTERM SIGINT SIGKILL
fork() {
printf "'%s' " "${@}" | xargs -d "\n" -t sh -c
}
if [[ ! "${ENTRYPOINT_SKIP}" ]]; then
for file in `ls -v /docker-entrypoint.d/*.sh`
do
echo "${file}:starting"
fork ${file} &
child_pid=$!
echo "${file}:pid ${child_pid}"
wait ${child_pid}
echo "${file}:stopped ${child_pid}"
if [[ "${?}" != "0" ]]; then
exit 1;
fi
done
fi
echo "${0}:starting"
fork "${@}" &
child_pid=$!
echo "${0}:pid ${child_pid}"
wait ${child_pid}
echo "${0}:stopped ${child_pid}"

View File

@ -170,10 +170,12 @@ export function getTypeOrmConfig(): TestingConnectionOptions[] {
try {
try {
return require(__dirname + "/../../../../ormconfig.json");
} catch (err) {
// first checks build/compiled
// useful for docker containers in order to provide a custom config
return require(__dirname + "/../../ormconfig.json");
} catch (err) {
// fallbacks to the root config
return require(__dirname + "/../../../../ormconfig.json");
}
} catch (err) {