cht-conf
v4.4.0
Published
Configure CHT deployments
Downloads
8,384
Maintainers
Keywords
Readme
CHT App Configurer
CHT Conf is a command-line interface tool to manage and configure your apps built using the Core Framework of the Community Health Toolkit.
Requirements
- nodejs 18 or later
- python 3
- or Docker
Installation
Operating System Specific
Ubuntu
npm install -g cht-conf
sudo python -m pip install git+https://github.com/medic/[email protected]#egg=pyxform-medic
OSX
npm install -g cht-conf
pip install git+https://github.com/medic/[email protected]#egg=pyxform-medic
Windows
As Administrator:
npm install -g cht-conf
python -m pip install git+https://github.com/medic/[email protected]#egg=pyxform-medic --upgrade
Docker
CHT Conf can also be run from within a Docker container. This is useful if you are already familiar with Docker and do not wish to configure the various dependencies required for developing CHT apps on your local machine. The necessary dependencies are pre-packaged in the Docker image.
Using the image
The Docker image can be used as a VS Code Development Container (easiest) or as a standalone Docker utility.
Install Docker. If you are using Windows, you also need to enable the Windows Subsystem for Linux (WSL2) to perform the following steps.
VS Code Development Container
If you want to develop CHT apps with VS Code, you can use the Docker image as a Development Container. This will allow you to use the cht
utility and its associated tech stack from within VS Code (without needing to install dependencies like NodeJS on your host system).
See the CHT Documentation for more information on building CHT apps with VS Code Development Containers.
Standalone Docker utility
If you are not using VS Code, you can use the Docker image as a standalone utility from the command line. Instead of using the cht ...
command, you can run docker run -it --rm -v "$PWD":/workdir medicmobile/cht-app-ide ...
. This will create an ephemeral container with access to your current directory that will run the given cht command. (Do not include the cht
part of the command, just your desired actions/parameters.)
Run the following command inside the project directory to bootstrap your new CHT project:
docker run -it --rm -v "$PWD":/workdir medicmobile/cht-app-ide initialise-project-layout
Note on connecting to a local CHT instance
When using cht
within a Docker container to connect to a CHT instance that is running on your local machine (e.g. a development instance), you cannot use the --local
flag or localhost
in your --url
parameter (since these will be interpreted as "local to the container").
It is recommended to run a local CHT instance using the CHT Docker Helper script. You can connect to the resulting ...my.local-ip.co
URL from the Docker container (or the VS Code terminal). (Just make sure the port your CHT instance is hosted on is not blocked by your firewall).
Bash completion
To enable tab completion in bash, add the following to your .bashrc
/.bash_profile
:
eval "$(cht --shell-completion=bash)"
Upgrading
To upgrade to the latest version
npm install -g cht-conf
Usage
cht
will upload the configuration from your current directory.
Specifying the server to configure
If you are using the default actionset, or performing any actions that require a CHT instance to function (e.g. upload-xyz
or backup-xyz
actions) you must specify the server you'd like to function against.
localhost
For developers, this is the instance defined in your COUCH_URL
environment variable.
cht --local
A specific Medic-hosted instance
For configuring Medic-hosted instances.
cht --instance=instance-name.dev
Username admin
is used. A prompt is shown for entering password.
If a different username is required, add the --user
switch:
--user user-name --instance=instance-name.dev
An arbitrary URL
cht --url=https://username:[email protected]:12345
NB - When specifying the URL with --url
, be sure not to specify the CouchDB database name in the URL. The CHT API will find the correct database.
Using a session token for authentication
CHT Conf supports authentication using a session token by adding --session-token
parameter:
cht --url=https://example.com:12345 --session-token=*my_token*
Into an archive to be uploaded later
cht --archive
The resulting archive is consumable by CHT API >v3.7 to create default configurations.
Perform specific action(s)
cht <--archive|--local|--instance=instance-name|--url=url> <...action>
The list of available actions can be seen via cht --help
.
Perform actions for specific forms
cht <--local|--instance=instance-name|--url=url> <...action> -- <...form>
Protecting against configuration overwriting
Added in v3.2.0
In order to avoid overwriting someone else's configuration cht-conf records the last uploaded configuration snapshot in the .snapshots
directory. The remote.json
file should be committed to your repository along with the associated configuration change. When uploading future configuration if cht-conf detects the snapshot doesn't match the configuration on the server you will be prompted to overwrite or cancel.
Currently supported
Settings
- compile app settings from:
- tasks
- rules
- schedules
- contact-summary
- purge
- app settings can also be defined in a more modular way by having the following files in app_settings folder:
- base_settings.json
- forms.json
- schedules.json
- backup app settings from server
- upload app settings to server
- upload resources to server
- upload custom translations to the server
- upload privacy policies to server
- upload branding to server
- upload partners to server
Forms
- fetch from Google Drive and save locally as
.xlsx
- backup from server
- delete all forms from server
- delete specific form from server
- upload all app or contact forms to server
- upload specified app or contact forms to server
Managing data and images
- convert CSV files with contacts and reports to JSON docs
- move contacts by downloading and making the changes locally first
- upload JSON files as docs on instance
- compress PNGs and SVGs in the current directory and its subdirectories
Editing contacts across the hierarchy.
To edit existing couchdb documents, create a CSV file that contains the id's of the document you wish to update, and the columns of the document attribute(s) you wish to add/edit. By default, values are parsed as strings. To parse a CSV column as a JSON type, refer to the Property Types section to see how you can parse the values to different types. Also refer to the Excluded Columns section to see how to exclude column(s) from being added to the docs.
Parameter | Description | Required
-- | -- | --
column(s) | Comma delimited list of columns you wish to add/edit. If this is not specified all columns will be added. | No
docDirectoryPath | This action outputs files to local disk at this destination | No. Default json-docs
file(s) | Comma delimited list of files you wish to process using edit-contacts. By default, contact.csv is searched for in the current directory and processed. | No.
updateOfflineDocs | If passed, this updates the docs already in the docDirectoryPath instead of downloading from the server. | No.
Example
Create a contact.csv file with your columns in the csv folder in your current path. The documentID column is a requirement. (The documentID column contains the document IDs to be fetched from couchdb.)
| documentID | is_in_emnch:bool | | ----------------- | ---------------- | | documentID1 | false | | documentID2 | false | | documentID3 | true |
Use the following command to download and edit the documents:
cht --instance=*instance* edit-contacts -- --column=*is_in_emnch* --docDirectoryPath=*my_folder*
or this one to update already downloaded docs
cht --instance=*instance* edit-contacts -- --column=*is_in_emnch* --docDirectoryPath=*my_folder* --updateOfflineDocs
Then upload the edited documents using the upload-docs command.
Project layout
This tool expects a project to be structured as follows:
example-project/
.eslintrc
app_settings.json
contact-summary.js
privacy-policies.json
privacy-policies/
language1.html
…
purge.js
resources.json
resources/
icon-one.png
…
targets.js
tasks.js
task-schedules.json
forms/
app/
my_project_form.xlsx
my_project_form.xml
my_project_form.properties.json
my_project_form-media/
[extra files]
…
contact/
person-create.xlsx
person-create.xml
person-create-media/
[extra files]
…
…
…
translations/
messages-xx.properties
…
If you are starting from scratch you can initialise the file layout using the initialise-project-layout
action:
cht initialise-project-layout
Derived configs
Configuration can be inherited from another project, and then modified. This allows the app_settings.json
and contained files (task-schedules.json
, targets.json
etc.) to be imported, and then modified.
To achieve this, create a file called settings.inherit.json
in your project's root directory with the following format:
{
"inherit": "../path/to/other/project",
"replace": {
"keys.to.replace": "value-to-replace-it-with"
},
"merge": {
"complex.objects": {
"will_be_merged": true
}
},
"delete": [
"all.keys.listed.here",
"will.be.deleted"
],
"filter": {
"object.at.this.key": [
"will",
"keep",
"only",
"these",
"properties"
]
}
}
Fetching logs
Fetch logs from a CHT v2.x production server.
This is a standalone command installed alongside cht-conf
. For usage information, run cht-logs --help
.
Usage
cht-logs <instance-name> <log-types...>
Accepted log types:
api
couchdb
gardener
nginx
sentinel
Development
To develop a new action or improve an existing one, check the "Actions" doc.
Testing
Unit tests
Execute npm test
to run static analysis checks and the test suite. Requires Docker to run integration tests against a CouchDB instance.
End-to-end tests
Run npm run test-e2e
to run the end-to-end test suite against an actual CHT instance locally. These tests rely on CHT Docker Helper to spin up and tear down an instance locally.
The code interfacing with CHT Docker Helper lives in test/e2e/cht-docker-utils.js
. You should rely on the API exposed by this file to orchestrate CHT instances for testing purposes. It is preferable to keep the number of CHT instances orchestrated in E2E tests low as it takes a non-negligible amount of time to spin up an instance and can quickly lead to timeouts.
Executing your local branch
- Clone the project locally
- Make changes to cht-conf or checkout a branch for testing
- Test changes
- To test CLI changes locally you can run
node <project_dir>/src/bin/index.js
. This will run as if you installed via npm. - To test changes that are imported in code run
npm install <project_dir>
to use the local version of cht-conf.
- To test CLI changes locally you can run
Releasing
- Create a pull request with prep for the new release.
- Get the pull request reviewed and approved.
- When doing the squash and merge, make sure that your commit message is clear and readable and follows the strict format described in the commit format section below. If the commit message does not comply, automatic release will fail.
- In case you are planning to merge the pull request with a merge commit, make sure that every commit in your branch respects the format.
Commit format
The commit format should follow this conventional-changelog angular preset. Examples are provided below.
Type | Example commit message | Release type -- | -- | -- Bug fixes | fix(#123): infinite spinner when clicking contacts tab twice | patch Performance | perf(#789): lazily loaded angular modules | patch Features | feat(#456): add home tab | minor Non-code | chore(#123): update README | none Breaking| perf(#2): remove reporting rates feature BREAKING CHANGE: reporting rates no longer supported | major
Releasing betas
- Checkout the default branch, for example
main
- Run
npm version --no-git-tag-version <major>.<minor>.<patch>-beta.1
. This will only update the versions inpackage.json
andpackage-lock.json
. It will not create a git tag and not create an associated commit. - Run
npm publish --tag beta
. This will publish your beta tag to npm's beta channel.
To install from the beta channel, run npm install cht-conf@beta
.
Build status
Builds brought to you courtesy of GitHub actions.
Copyright
Copyright 2013-2024 Medic Mobile, Inc. [email protected]
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.