Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for postgresql database (for FDP develop) #12

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ output
cypress.env.json

fdp/graphdb
fdp/compose.yml
fdp/docker-compose.yml
fdp/openrefine-cfg/*.yaml
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ init:

.PHONY: start
start:
@cd fdp && docker-compose pull && docker-compose up -d
@cd fdp && docker compose up -d

.PHONY: stop
stop:
@cd fdp && docker-compose down
@cd fdp && docker compose down

.PHONY: run
run:
Expand Down Expand Up @@ -45,9 +45,9 @@ ci:

.PHONY: clean
clean:
@rm -rf output && rm -rf fdp/graphdb && rm -f fdp/docker-compose.yml && rm -rf fdp/openrefine-cfg/*.yaml
@rm -rf output && rm -rf fdp/graphdb && rm -f fdp/compose.yml && rm -rf fdp/openrefine-cfg/*.yaml


.PHONY: logs
logs:
@cd fdp && docker-compose logs -f
@cd fdp && docker compose logs -f
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FAIR Data Point E2E Tests

> E2E test suite for the [FAIR Data Point](https://github.com/FAIRDataTeam/FAIRDataPoint), [FAIR Data Point Client](https://github.com/FAIRDataTeam/FAIRDataPoint-client) and [Open Refine Metadata Extension](https://github.com/FAIRDataTeam/OpenRefine-metadata-extension) based on [Cypress](https://www.cypress.io).
> E2E test suite for the [FAIR Data Point][1], [FAIR Data Point Client][2], and [Open Refine Metadata Extension][3], based on [Cypress][4].


## Project Structure
Expand All @@ -9,7 +9,7 @@
- Contains all test files following the standard [Cypress structure](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Support-file).
- `/fdp`
- Contains the configuration to run FDP and other associated services in Docker.
- The actual docker-compose.yml file is generated during initialization.
- The actual docker compose.yml file is generated during initialization.
- `/scripts`
- Additional utility scripts.
- `/cypress.json`
Expand All @@ -19,27 +19,36 @@

## Environment Variables

When initializing the `docker-compose.yml` file, the following ENV variables can be used to choose different images to test.
When initializing the `compose.yml` file, the following ENV variables can be used to choose different images to test.

| ENV | Default |
| --- | --- |
| SERVER_IMAGE | `fairdata/fairdatapoint:develop` |
| CLIENT_IMAGE | `fairdata/fairdatapoint-client:develop` |
| OPEN_REFINE_IMAGE | `fairdata/openrefine-metadata-extension:develop` |
| Name | Example | Default |
| --- | --- | --- |
| SERVER_VERSION | `1.16` | `develop` |
| CLIENT_VERSION | `1.16` | `develop` |

## Running the tests

Makefile contains several commands to work with the project.

- `make install` - install all the dependencies to run the tests
- `make init` - initialize docker-compose so that the project can run
- `make init` - initialize docker compose file so that the project can run
- `make start` - start all containers
- `make stop` - stop all containers
- `make run` - run tests in headless mode
- `make open` - open Cypress app, good for local development
- `make ci` - shortcut for the whole workflow in CI
- `make clean` - clean all generated files

For convenience, it is also possible to run the tests through `npm run test`.
To add [cypress cli options][5], use `--`, e.g. `npm run test -- <cypress options>`.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for more details.


[1]: https://github.com/FAIRDataTeam/FAIRDataPoint
[2]: https://github.com/FAIRDataTeam/FAIRDataPoint-client
[3]: https://github.com/FAIRDataTeam/OpenRefine-metadata-extension
[4]: https://www.cypress.io
[5]: https://docs.cypress.io/app/references/command-line#Commands
39 changes: 39 additions & 0 deletions fdp/compose.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
services:
fdp:
# entire string `{SERVER_IMAGE}` is replaced in scripts/init.sh
image: {SERVER_IMAGE}
restart: always
ports:
# <host port>:<container port>
- 127.0.0.1:3000:80
environment:
# postgres variables are ignored if mongodb is used
# values must match those specified for db in scripts/init.sh
# see config in FDP application.yml
FDP_POSTGRES_HOST: db
FDP_POSTGRES_DB: fdp
FDP_POSTGRES_USERNAME: fdp
FDP_POSTGRES_PASSWORD: fdp
volumes:
# bind mount
- ./application.yml:/fdp/application.yml:ro
healthcheck:
test: curl --no-progress-meter --fail http://fdp:80 || exit 1
depends_on:
db:
condition: service_healthy

fdp-client:
image: {CLIENT_IMAGE}
ports:
- 127.0.0.1:80:80
- 127.0.0.1:3333:3333
environment:
# fdp service is defined above
- FDP_HOST=fdp
depends_on:
fdp:
condition: service_healthy

db:
# content added by init.sh script (database type depends on fdp version)
24 changes: 0 additions & 24 deletions fdp/docker-compose.template.yml

This file was deleted.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "dsw-e2e-tests",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"test": "cypress run"
},
"dependencies": {
"mongodb": "^3.7.3",
"rdflib": "^1.3.4"
Expand Down
58 changes: 50 additions & 8 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
#!/bin/sh

# Init docker-compose file
SERVER_IMAGE="${SERVER_IMAGE:-fairdata/fairdatapoint:develop}"
CLIENT_IMAGE="${CLIENT_IMAGE:-fairdata/fairdatapoint-client:develop}"
# Create a docker compose file based on template

DOCKER_COMPOSE_FILE=fdp/docker-compose.yml
# Get Docker image versions from environment, with fallback to develop
SERVER_IMAGE="fairdata/fairdatapoint:${SERVER_VERSION:-develop}"
CLIENT_IMAGE="fairdata/fairdatapoint-client:${CLIENT_VERSION:-develop}"

cp -r fdp/docker-compose.template.yml $DOCKER_COMPOSE_FILE
sed -i.bak "s#{SERVER_IMAGE}#$SERVER_IMAGE#" $DOCKER_COMPOSE_FILE && rm $DOCKER_COMPOSE_FILE".bak"
sed -i.bak "s#{CLIENT_IMAGE}#$CLIENT_IMAGE#" $DOCKER_COMPOSE_FILE && rm $DOCKER_COMPOSE_FILE".bak"
# Path to Docker Compose file (to be created)
DOCKER_COMPOSE_FILE=fdp/compose.yml

echo "Initialized docker-compose.yml:"
# Copy template into new Docker Compose file
cp fdp/compose.template.yml $DOCKER_COMPOSE_FILE

# Replace Docker image names in newly created Docker Compose file
# (uses `#` as `sed` delimiter, instead of default `/`, because the search and replace strings contain `/`)
sed --in-place "s#{SERVER_IMAGE}#$SERVER_IMAGE#" $DOCKER_COMPOSE_FILE
sed --in-place "s#{CLIENT_IMAGE}#$CLIENT_IMAGE#" $DOCKER_COMPOSE_FILE

# Configure database based on FDP version
# (mongodb for <=1.17.x, postgresql for later versions)
case $SERVER_IMAGE in
*1.16*|*1.17*)
# use mongodb
# todo: change `mongo` to `mongosh` (after upgrade to mongo >6.0)
cat <<'HEREDOC' >> $DOCKER_COMPOSE_FILE
image: mongo:4.0.12
hostname: mongo
ports:
- 127.0.0.1:27017:27017
healthcheck:
test: |
[ $(mongo --quiet --host mongo:27017 --eval "db.runCommand('ping').ok") = 1 ] || exit 1
restart: always
HEREDOC
;;
*)
# use postgresql
cat <<'HEREDOC' >> $DOCKER_COMPOSE_FILE
image: postgres
ports:
- 127.0.0.1:54321:5432
healthcheck:
test: pg_isready || exit 1
environment:
POSTGRES_DB: fdp
POSTGRES_USER: fdp
POSTGRES_PASSWORD: fdp
restart: always
HEREDOC
;;
esac

# Show result
echo "Initialized docker compose file:"
cat $DOCKER_COMPOSE_FILE