Skip to content

Commit

Permalink
added docker-compose specific file for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Jul 10, 2023
1 parent a35a33f commit 751619f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ build:
docker compose build

init:
docker network create datalake-taxii && docker compose run --rm --entrypoint "python main.py --init" taxii_integration && docker compose restart medallion
docker network create datalake-taxii || echo "Using previously created network datalake-taxii..." && docker compose run --rm --entrypoint "python main.py --init" taxii_integration && docker compose restart medallion

run:
docker compose run --rm taxii_integration

test:
docker compose up -d -V nginx_proxy && docker compose run --entrypoint "python main.py --init" taxii_integration && docker compose restart medallion && docker compose run --entrypoint=sh taxii_integration -c "python -m flake8 . --count --max-complexity=10 --max-line-length=120 --show-source --statistics && python -m pytest -s "
docker network create datalake-taxii || echo "Using previously created network datalake-taxii..." && docker compose -f docker-compose.test.yml up -d -V nginx_proxy && docker compose -f docker-compose.test.yml run --entrypoint "python main.py --init" taxii_integration && docker compose -f docker-compose.test.yml restart medallion && docker compose -f docker-compose.test.yml run --entrypoint=sh taxii_integration -c "python -m flake8 . --count --max-complexity=10 --max-line-length=120 --show-source --statistics && python -m pytest -s "
44 changes: 4 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,48 +99,12 @@ Remember to adapt your `.env` after that.

:warning: by default medallion use credentials in plain text, therefore medallion_config.json must be secured.

## Testing

Before running tests you will need to change somes values in the `docker-compose.yml` file.

Replace the `taxii_integration` service with the following:

```yml
taxii_integration:
build: .
restart: unless-stopped
container_name: taxii_integration
volumes:
- ./tests/ci_files/queries.test.json:/code/queries.json
- data_volume:/code/output
env_file: ./tests/ci_files/.env.test
depends_on:
- nginx_proxy
networks:
- datalake_taxii_integration
```
Replace `medallion` service with the following:

```yml
medallion:
image: ocddev/cti-taxii-server
container_name: medallion-deployment-sample
restart: unless-stopped
command: "uwsgi --ini /deployment_sample/uwsgi.ini"
volumes:
- ./tests/ci_files/medallion_config.test.json:/opt/taxii/config.json
- ./deployment_sample/uwsgi.ini:/deployment_sample/uwsgi.ini
depends_on:
- mongo
networks:
- datalake_taxii_integration
```
## Running tests

This will change which files are used to build those services for our tests.
To run test, you will need to use the `docker-compose.test.yml` docker-compose file. If you made changes to the tests, make sure any required changes are made there.

You can now run the following command:
Run the tests with the following command

```shell
```bash
make test
```
79 changes: 79 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# used for local test
version: '3'
services:
nginx:
image: nginx
container_name: nginx
restart: unless-stopped
volumes:
- ./deployment_sample/nginx:/etc/nginx
depends_on:
- medallion
networks:
- datalake-taxii

nginx_proxy:
image: nginx
container_name: nginx_proxy
restart: unless-stopped
ports:
- 8080:8080
- 443:443
volumes:
- ./deployment_sample/nginx_proxy:/etc/nginx
- ./deployment_sample/certs:/etc/certs # Auto signed certs by default
depends_on:
- nginx
networks:
datalake-taxii:
aliases:
- my.taxii_server.com

taxii_integration:
build: .
restart: unless-stopped
container_name: taxii_integration
volumes:
- ./tests/ci_files/queries.test.json:/code/queries.json
- data_volume:/code/output
env_file: ./tests/ci_files/.env.test
depends_on:
- nginx_proxy
networks:
- datalake-taxii

medallion:
image: ocddev/cti-taxii-server
container_name: medallion-deployment-sample
restart: unless-stopped
command: "uwsgi --ini /deployment_sample/uwsgi.ini"
volumes:
- ./tests/ci_files/medallion_config.test.json:/opt/taxii/config.json
- ./deployment_sample/uwsgi.ini:/deployment_sample/uwsgi.ini
depends_on:
- mongo
networks:
- datalake-taxii

mongo:
image: mongo
restart: unless-stopped
container_name: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
volumes:
- ./data/mongo_data:/data/db
ports:
- 27017:27017
networks:
- datalake-taxii

volumes:
data_volume:


networks:
datalake-taxii:
external: true
name: datalake-taxii

0 comments on commit 751619f

Please sign in to comment.