Skip to content

Commit

Permalink
Use dev_cli script from api to setup the database for e2e api tests #499
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Apr 16, 2024
1 parent 914c35f commit dbb7fea
Showing 1 changed file with 56 additions and 36 deletions.
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: add-common-dev-task-script-#235

- 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 mongodb_container
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 -p 8000:8000 --network=inventory-management-system-api_default \
--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="mongodb_container" \
--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@b4ffde65f46336ab88eb53be808477a3936bae11 # 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@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
Expand Down

0 comments on commit dbb7fea

Please sign in to comment.