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

Use replica set for MongoDB in e2e api tests on CI #499 #500

Merged
merged 4 commits into from
Apr 25, 2024
Merged
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
92 changes: 56 additions & 36 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,55 @@ jobs:
name: End-to-End (with api) Tests
runs-on: ubuntu-latest

services:
mongodb:
image: mongo:7.0-jammy
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example

ims-api:
image: harbor.stfc.ac.uk/inventory-management-system/ims-api:develop
ports:
- 8000:8000
env:
AUTHENTICATION__ENABLED: false
API__TITLE: Inventory Management System API
API__DESCRIPTION: This is the API for the Inventory Management System
API__ROOT_PATH: /inventory-management-system-api
DATABASE__PROTOCOL: mongodb
DATABASE__USERNAME: root
DATABASE__PASSWORD: example
DATABASE__HOSTNAME: mongodb
DATABASE__PORT: 27017
DATABASE__NAME: ims
API__ALLOWED_CORS_HEADERS: '["*"]'
API__ALLOWED_CORS_ORIGINS: '["*"]'
API__ALLOWED_CORS_METHODS: '["*"]'

options: --name inventory-management-system-api

steps:
- name: Clone api repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
repository: ral-facilities/inventory-management-system-api
ref: develop

- name: Set up Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.12'

# This is required as need to setup api in a different directory as checkout will attempt delete
# all existing files which in this case will include a data directory created by docker causing
# a permission error (checkout action also can't specify a different directory to clone into)
- name: Move api repo
run: |
cd ..
mkdir inventory-management-system-api
mv -v inventory-management-system/* inventory-management-system-api/
cd inventory-management-system-api/

- name: Setup MongoDB
working-directory: ../inventory-management-system-api
run: |
python ./scripts/dev_cli.py --ci db-init --replicaSetMemberHost localhost
python ./scripts/dev_cli.py --ci db-import

# Use docker run here to test the actual built image
# Use same network as the MongoDB instance (which is generated by docker compose based on the folder
# name)
- name: Start inventory-management-system-api
run: |
docker run -d --network=host \
--name inventory_management_system_api_container \
--env AUTHENTICATION__ENABLED=false \
--env API__TITLE="Inventory Management System API" \
--env API__DESCRIPTION="This is the API for the Inventory Management System" \
--env DATABASE__PROTOCOL="mongodb" \
--env DATABASE__USERNAME="root" \
--env DATABASE__PASSWORD="example" \
--env DATABASE__HOSTNAME="localhost" \
--env DATABASE__PORT=27017 \
--env DATABASE__NAME="ims" \
--env API__ALLOWED_CORS_HEADERS='["*"]' \
--env API__ALLOWED_CORS_ORIGINS='["*"]' \
--env API__ALLOWED_CORS_METHODS='["*"]' \
harbor.stfc.ac.uk/inventory-management-system/ims-api:develop

- name: Checkout repo
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4

Expand All @@ -117,15 +135,17 @@ jobs:
sudo apt-get install libgconf-2-4
yarn --immutable

- name: Download unit data
run: wget https://raw.githubusercontent.com/ral-facilities/inventory-management-system-api/develop/data/units.json

- name: Import unit data to ims api
run: docker exec -i $(docker ps | grep mongo | awk '{ print $1 }') mongoimport --username 'root' --password 'example' --authenticationDatabase=admin --db ims --collection units --type=json --jsonArray --drop < units.json

- name: Run e2e tests
run: yarn e2e:api

- name: Output docker logs (mongodb)
if: failure()
run: docker logs mongodb_container

- name: Output docker logs (api)
if: failure()
run: docker logs inventory_management_system_api

- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
Expand Down
Loading