Skip to content

Commit

Permalink
fixes entry point and env vars in dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
latin-panda committed Jun 19, 2024
1 parent ca93860 commit 99cac8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ RUN npm ci
# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
USER node

ARG INSTANCE_COUCH_URL
ENV COUCH_URL=INSTANCE_COUCH_URL
ENV FILE=""
ENV COUCH_URL=""

VOLUME /app/test-data
ARG FILE
ENTRYPOINT ["npm", "run", "generate", "test-data/$FILE"]

ENTRYPOINT npm run generate test-data/$FILE
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,38 @@ Design the test data that fit your project hierarchy and reports. The tool will

## Minimum System Requirements

- npm >= 8.0.0
- node >= 16.0.0
- npm >= 10.2.4
- node >= 20.11.0

## Setup and Getting Started

Instructions on setting up the project and getting it running on a local machine.

- Set the `COUCH_URL` environment variable to point your test instance, for example it is something similar to this: `http://[user]:[pass]@[host]:[port]/medic`
- Double-check your CHT test instance is running
- Clone or fork the repository
- Install the project globally by running `npm install -g`.
- Clone or fork the test data generator repository
- Install and build the project by running `npm ci` in the project root folder
- Design the test data in a custom JavaScript file. See section [Designing Test Data](#designing-test-data).
- Build, generate data and upload by running `test-data-generator *path_to_your_custom_design_file*`
- Build, generate data and upload by running `npm run generate *path_to_your_custom_design_file*`

### Install it globally
Another option is to install the tool globally:
- Build the project `npm run build`
- Run `npm install -g` in the project root folder
- Build, generate and upload data by running `test-data-generator <path_to_your_custom_design_file>`.

### Use it with Docker
The tool is also available in Docker:
- Create the image `docker build -t test-data-generator .`
- Run the container `docker run --rm -it -v <folder_path_of_your_design_file>:/app/test-data -e COUCH_URL=<test_instance_CouchDB_URL> -e FILE=<your_design_file> test-data-generator`

## Designing Test Data

Steps to design the test data:

1. Create a custom JavaScript file that exports a `default` function. This function should match the [`DocDesign` type](./src/doc-design.ts).
2. Your custom function should return an array of [`DesignSpec`](./src/doc-design.ts) objects that define the structure of your data to create.
3. Generate and upload data `test-data-generator *path_to_your_custom_design_file*`. That's all! You can check the data in the CHT's CouchDB.
3. Generate and upload data `npm run generate *path_to_your_custom_design_file*`. That's all! You can check the data in the CHT's CouchDB.

Note that `getDoc` function should return an object with at least a `type: string`. Remember that `type` is a `data_record` for reports, but when it comes to contacts, use the `contact_types` defined in your CHT project's `app-settings.json`.

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"npm": ">=10.2.4"
},
"scripts": {
"postinstall": "npm run build",
"test": "mocha",
"lint": "eslint .",
"build": "npm run lint && tsc",
"generate": "npm run build && echo 'Processing, please wait.' && node built/."
"generate": "node built/."
},
"bin": {
"test-data-generator": "built/index.js"
Expand Down

0 comments on commit 99cac8a

Please sign in to comment.