Skip to content

Commit

Permalink
Set seeded DB name by BE version
Browse files Browse the repository at this point in the history
* Set seeded DB name by BE version

* Update readme depending on env variable

* Run init script at startup when db changed
  • Loading branch information
minottic authored Apr 9, 2024
1 parent 6e8e4ee commit e5bf9ab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ Note: older versions might not contain certain functionality (e.g. archival mock
## Default setup

By running `docker-compose up -d` these steps take place:
1. a [mongodb](./services/mongodb/) container is created with some intial data.
1. a [mongodb**](./services/mongodb/) container is created with some intial data.
2. the SciCat [backend v3*](./services/backend/) container is created and connected to (1).
3. the SciCat [backend v4](./services/backendnext/) container is created and connected to (1).
4. the SciCat [frontend](./services/frontend/) container is created and connected to (3).
5. the SciCat [PaN searchapi](./services/searchapi/) container is created and connected to (3).
6. a reverse [proxy](./services/proxy) container is created and routes trafic to (2), (3), (4) and (5) through localhost subdomains, in the form: `http://${service}.localhost` (for the ones of need). The frontend is available at simply `http://localhost`.

We flag with `*` the services which have extra internal dependencies, which are not shared across the two backend versions. To view them, refer to the service README.
We flag with `*` the services which have extra internal dependencies, which are not shared across the two backend versions, and with `**` the ones which have a dependency on the `BE_VERSION` value. To view them, refer to the service README.


Here below we show the dependencies (if `B` depends on `A`, then we visualize as `A --> B`):

Expand All @@ -43,7 +44,7 @@ graph TD
backendnext
end
mongodb --> backends
mongodb[mongodb**] --> backends
backend --> frontend
backend --> searchapi
end
Expand All @@ -53,6 +54,10 @@ graph TD
proxy -.- searchapi
```

## Select the BE version to use

The user can select what backend (either `backend` or `backendnext`) version to use, by setting the BE_VERSION environment variable, [either](https://docs.docker.com/compose/environment-variables/envvars-precedence/) setting it in the shell or changing the [.env](./.env#L1) file. If this variable is blank, the system will default to `backendnext`. The services with `**` have a dependency on the `BE_VERSION` value.

## Select the services

The user can selectively decide the containers to spin up and the dependencies will be resolved accordingly. The available services are in the [services](./services/) folder and called consistently.
Expand Down
10 changes: 8 additions & 2 deletions services/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ To add more collections during the creation of the database:

These files are ingested into the database using mongo funcionalities and bypassing the backend, i.e. they are not to be taken as examples to use the backend API.

## Defaul configuration
## Default configuration

In the default configuration [init.js](./config/init.js), the seeding creates data in the [dacat](./config/init.js#L1) mongodb database used by the [backend container](../backend/).
In the default configuration [init.js](./config/init.js), the seeding creates data in the [dacat](./config/init.js#L1) mongodb database used by the [backend container](../backend/)

## Dependency on `BE_VERSION`

The seeded database is controlled by the [BE_VERSION environment](./docker-compose.yaml#L9) variable set at startup. This will control what DB is seeded, either the [dacat](./config/init.js#L1) mongodb database used by the [backend container](../backend/) or the [dacat-next](./config/init.js#L1) mongodb database used by the [backendnext container](../backendnext/).

For an explanation of how setting `BE_VERSION` changes the environment creation see [here](./README.md#dependency-on-be_version).
2 changes: 1 addition & 1 deletion services/mongodb/config/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db = connect('mongodb://localhost/dacat');
db = connect(`mongodb://localhost/${process.env.BE_VERSION === 'backendnext'? 'dacat-next': 'dacat'}`);
seedFiles = fs.readdirSync('/seed');
seedFiles.forEach((filename) => {
collectionName = filename.replace(/\.json$/, '');
Expand Down
8 changes: 6 additions & 2 deletions services/mongodb/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ services:
mongodb:
image: mongo:7.0
volumes:
- mongodb_data:/data/db
- ${BE_VERSION:-backendnext}_mongodb_data:/data/db
- ./config/init.js:/docker-entrypoint-initdb.d/init.js
- ./config/seed:/seed
environment:
BE_VERSION: ${BE_VERSION:-backendnext}

volumes:
mongodb_data:
backendnext_mongodb_data:
driver: local
backend_mongodb_data:
driver: local

0 comments on commit e5bf9ab

Please sign in to comment.