Skip to content

Commit

Permalink
Merge branch 'main' into format-once
Browse files Browse the repository at this point in the history
  • Loading branch information
freddieptf authored Nov 26, 2024
2 parents c591f6b + 786acef commit 926a7bf
Show file tree
Hide file tree
Showing 57 changed files with 12,812 additions and 2,855 deletions.
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/new-instance-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: New instance request
about: Details for new instance
title: New User Managament Tool instance for $PARTNERS_NAME


---

**Partner Name**: _$PARTNERS_NAME_
**Proposed URL**: users-chis-_$COUNTRY_-cht-user-management
**Config Name**: users-chis-$COUNTRY



**Action Items**
- [ ] verify URL: https://users-chis-$COUNTRY.app.medicmobile.org
- [ ] ensure repo has [config](https://github.com/medic/cht-user-management/tree/main/src/config) for $COUNTRY. Directory and config name needs to match URL
- [ ] create DNS entry: `CNAME` of `users-chis-$COUNTRY.app.medicmobile.org` -> `k8s-prodchtalb-dcc00345ac-1792311525.eu-west-2.elb.amazonaws.com`
- [ ] create helm values file in [correct location](https://github.com/medic/cht-user-management/tree/main/scripts/deploy/values)
- [ ] `helm install` chart so the instance is live at above URL [per docs](https://github.com/medic/cht-user-management/blob/main/scripts/deploy/medic-deploy.md)
- [ ] update docs to have new instance in the `Known cofigurations` section
11 changes: 8 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ jobs:
registry-type: public

- name: Get branch name
uses: nelonoel/branch-name@1ea5c86cb559a8c4e623da7f188496208232e49f
uses: nelonoel/branch-name@v1.0.1
- name: Set ENV
run: |
echo "BUILD_NUMBER=$GITHUB_RUN_ID" >> $GITHUB_ENV
echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Use Node.js 20.x
uses: actions/setup-node@v1
with:
node-version: 20.x
- run: npm run publish

- name: Build and push cht-user-management image
run: npm run publish:cht-user-management

- name: Build and push cht-user-management-worker image
run: npm run publish:cht-user-management-worker
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
dist
.env*
src/package.json
.eslintcache
.eslintcache
.DS_Store
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
FROM node:20-alpine

ENV EXTERNAL_PORT 3000
ENV PORT 3000
ENV EXTERNAL_PORT 3500
ENV PORT 3500
ENV NODE_ENV production

WORKDIR /app

HEALTHCHECK --interval=30s --timeout=3s \
CMD wget --spider http://localhost:${PORT}/_healthz || exit 1
CMD wget --spider http://127.0.0.1:${PORT}/_healthz || exit 1

COPY package*.json .
COPY package*.json ./
RUN apk add git
RUN npm ci --omit=dev

COPY src ./src
COPY tsconfig.json .
COPY tsconfig.json ./
RUN npm run build

CMD npm start
13 changes: 13 additions & 0 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine

WORKDIR /app

COPY package*.json ./
RUN apk add git
RUN npm ci --omit=dev

COPY src ./src
COPY tsconfig.json ./
RUN npm run build

CMD npm run start:worker
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A simple user-facing web application using [CHT's API](https://docs.communityhea
* [Moving an Existing Place with the User Management Tool](https://www.loom.com/share/cd9e98aefedb490fae61775c86b9b6fe)
* [CHIS Kenya - CHA Changing a Phone Number for a CHP](https://www.loom.com/share/8a0f629161944567b6ca504ab27ec6cf)
* [How to Bulk Replace CHPs with CHIS User Management Tool](https://www.loom.com/share/33d9395a515741fa9620f7004578de24)
* [How to Resolve eCHIS-KE Logic Error](https://www.loom.com/share/80e130733d094e4a829bdfe063d8b1e6)

For Developers:
* [Running CHT User Management Tool with a Local CHT Instance](https://www.loom.com/share/645cf995a9c44a5ab843628538a019ff)
Expand All @@ -27,7 +28,7 @@ To use the User Management Tool with your CHT project, you'll need to create a n
2. Create a `config.json` file and specify the values as defined below.
3. Add reference to your configuration folder in `src/config/config-factory.ts`.

Property | Type | Description
Property | Type | Description
-- | -- | --
`domains` | Array | Controls the list of instances which the user can login to
`domains.friendly` | string | Friendly name for the instance (eg. "Migori")
Expand All @@ -46,6 +47,7 @@ Property | Type | Description
`contact_types.place_properties` | Array<ConfigProperty> | Defines the attributes which are collected and set on the user's created place. See [ConfigProperty](#ConfigProperty).
`contact_types.contact_properties` | Array<ConfigProperty> | Defines the attributes which are collected and set on the user's primary contact doc. See [ConfigProperty](#ConfigProperty).
`contact_types.deactivate_users_on_replace` | boolean | Controls what should happen to the defunct contact and user documents when a user is replaced. When `false`, the contact and user account will be deleted. When `true`, the contact will be unaltered and the user account will be assigned the role `deactivated`. This allows for account restoration.
`contact_types.hint` | string | Provide a brief hint or description to clarify the expected input for the property.
`logoBase64` | Image in base64 | Logo image for your project

#### ConfigProperty
Expand Down Expand Up @@ -112,8 +114,17 @@ lineage | Has the attributes from `hierarchy.property_name`
This tool is available via Docker by running `docker compose up`. Set the [Environment Variables](#environment-variables).

## Development

### NodeJs with reloading code

Create an environment file by `cp env.example .env`. Change `INTERFACE` to `127.0.0.1` and otherwise see [Environment Variables](#environment-variables) for more info.

If you don't have redis running locally, you can start it with:

```shell
docker compose -f docker-compose.redis.yml up -d
```

Then run:

```
Expand All @@ -127,19 +138,38 @@ npm run build
npm start
```

### Docker with static code

To build the Docker images and run Docker Compose locally, run:

```bash
./docker-local-setup.sh build
```

If you just need to run the development environment without rebuilding the images run:

```bash
./docker-local-setup.sh
```

## Environment Variables

The `env.example` file has example values. Here's what they mean:

Variable | Description | Sample
-- | -- | --
`CONFIG_NAME` | Name of the configuration to use | `chis-ke`
`EXTERNAL_PORT` | Port to use in docker compose when starting the web server | `3000`
`PORT` | For localhost development environment | `3000`
`COOKIE_PRIVATE_KEY` | A string used to two-way encryption of cookies. Production values need to be a secret. Suggest `uuidgen` to generate | `589a7f23-5bb2-4b77-ac78-f202b9b6d5e3`
`EXTERNAL_PORT` | Port to use in docker compose when starting the web server | `3500`
`PORT` | For localhost development environment | `3500`
`COOKIE_PRIVATE_KEY` | A string used to two-way encryption of main app cookies. Production values need to be a secret. Suggest `uuidgen` to generate | `589a7f23-5bb2-4b77-ac78-f202b9b6d5e3`
`WORKER_PRIVATE_KEY` | A string used to two-way encryption sensitive data passed to workers. Recommend to be different from `COOKIE_PRIVATE_KEY`. Production values need to be a secret. Suggest `uuidgen` to generate | `2b57pd5e-f272-og90-8u97-89a7589a7f23`
`INTERFACE` | Interface to bind to. Leave as '0.0.0.0' for prod, suggest '127.0.0.1' for development | `127.0.0.1`
`CHT_DEV_URL_PORT` | CHT instance when in `NODE_ENV===dev`. Needs URL and port | `192-168-1-26.local-ip.medicmobile.org:10463`
`CHT_DEV_HTTP` | 'false' for http 'true' for https | `false`
`REDIS_HOST` | Redis server hostname use 'redis' for docker | `redis`
`REDIS_PORT` | Redis server port | `6379`
`CHT_USER_MANAGEMENT_IMAGE` | docker image for cht-user-management service (local development), leave empty to use published one | `cht-user-management:local `
`CHT_USER_MANAGEMENT_WORKER_IMAGE` | docker image for cht-user-management service (local development), leave empty to use published one | `cht-user-management-worker:local`

## Publishing new docker images

Expand Down
12 changes: 12 additions & 0 deletions docker-compose.redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
redis:
image: redis:6.2-alpine
restart: always
volumes:
- redis-data:/data
ports:
- 6379:6379


volumes:
redis-data:
37 changes: 32 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
version: '3.7'

services:
redis:
image: redis:6.2-alpine
restart: always
volumes:
- redis-data:/data

cht-user-management:
image: public.ecr.aws/medic/cht-user-management:latest
image: ${CHT_USER_MANAGEMENT_IMAGE:-public.ecr.aws/medic/cht-user-management:latest}
environment:
- EXTERNAL_PORT=${EXTERNAL_PORT:-3000}
- NODE_ENV=${NODE_ENV:-production}
- EXTERNAL_PORT=${EXTERNAL_PORT:-3500}
- COOKIE_PRIVATE_KEY=${COOKIE_PRIVATE_KEY}
- WORKER_PRIVATE_KEY=${WORKER_PRIVATE_KEY}
- CONFIG_NAME=${CONFIG_NAME}
- CHT_DEV_HTTP=${CHT_DEV_HTTP}
- CHT_DEV_URL_PORT=${CHT_DEV_URL_PORT}
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PORT=${REDIS_PORT:-6379}
ports:
- '${EXTERNAL_PORT-3000}:${PORT:-3000}'
- '${EXTERNAL_PORT-3500}:${PORT:-3500}'
restart: always
command: npm start
depends_on:
- redis

cht-user-management-worker:
image: ${CHT_USER_MANAGEMENT_WORKER_IMAGE:-public.ecr.aws/medic/cht-user-management-worker:latest}
restart: always
command: npm run start:worker
environment:
- NODE_ENV=${NODE_ENV:-production}
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PORT=${REDIS_PORT:-6379}
- WORKER_PRIVATE_KEY=${WORKER_PRIVATE_KEY}
depends_on:
- redis

volumes:
redis-data:
27 changes: 27 additions & 0 deletions docker-local-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

#!/bin/bash
set -e

if [ ! -f ".env" ]; then
echo "Please create a .env file first. Copy the env.example and edit the new file"
exit 1
fi
. .env

if [[ -n $1 ]] && [[ $1 == "build" ]]; then
docker build -f Dockerfile -t cht-user-management:local .
docker build -f Dockerfile.worker -t cht-user-management-worker:local .
elif [[ -z "$(docker images -q cht-user-management:local 2> /dev/null)" ]] || [[ -z "$(docker images -q cht-user-management-worker:local 2> /dev/null)" ]]; then
echo;echo "Docker images not found - please call
./docker-local-setup.sh build
to build missing images";echo;
exit 1
fi

echo;echo "Starting Docker Compose...";echo
CHT_USER_MANAGEMENT_IMAGE=cht-user-management:local CHT_USER_MANAGEMENT_WORKER_IMAGE=cht-user-management-worker:local docker compose up -d

echo;echo "Server is now running at http://127.0.0.1:$EXTERNAL_PORT/login";echo
24 changes: 17 additions & 7 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
COOKIE_PRIVATE_KEY=
CONFIG_NAME=chis-ke
PORT=3000 # for development environment
EXTERNAL_PORT=3000 # for docker
INTERFACE=0.0.0.0 # Leave as '0.0.0.0' for prod, suggest '127.0.0.1' for development
CHT_DEV_URL_PORT=localhost:5984 # where your dev CHT instance is, hostname:port
CHT_DEV_HTTP=true # 'false' for http 'true' for https
NODE_ENV= # set to "dev" to use CHT_DEV_URL_PORT below, leave empty for production
COOKIE_PRIVATE_KEY= # unique random key, use uuidgen to populate
WORKER_PRIVATE_KEY= # unique random key, use uuidgen to populate. different from COOKIE_PRIVATE_KEY
CONFIG_NAME=chis-ke # Name of the configuration
INTERFACE=0.0.0.0 # Leave as '0.0.0.0' for prod, suggest '127.0.0.1' for development
CHT_DEV_HTTP=true # 'true' for http 'false' for https
CHT_DEV_URL_PORT=localhost:5984 # where your dev CHT instance is, hostname:port

# uncomment for local development ( `npm run dev`)
#REDIS_HOST=localhost # Redis server hostname
#REDIS_PORT=6379 # Redis server port

# normally leave these commented out unless you know what you're doing:
#PORT=3500 # for development environment container
#EXTERNAL_PORT=3500 # for docker
#CHT_USER_MANAGEMENT_IMAGE=cht-user-management:local # docker image for cht-user-management service - uncomment to use with local development
#CHT_USER_MANAGEMENT_WORKER_IMAGE=cht-user-management-worker:local # docker image for worker service - uncomment to use with local development
Loading

0 comments on commit 926a7bf

Please sign in to comment.