Skip to content

Commit

Permalink
feat(#12): cloud-based execution of move contact (#177)
Browse files Browse the repository at this point in the history
* wip: move contact setup raw feature

* feat(#12): add centralized queue layer  & cleanup

* fix(#12): oups test

* fix(#12): get this test pass

* fix(#12): lint

* feat: address feedback part 1

* fix(#12): failing test

* feat(#12): fix review feedback part2

* feat(#12): fix review feedback part2

* fix(#12): job postponed

* fix(#12): update  postponed test

* feat(#12): make this toast display

* ref(#12): remove move_result.html as no more used

* fix(#12): address docker feedback

* Apply suggestions from code review

* fix(#12): address feedback part 5

* ref(#12): switch to an official version of cht-conf support session

* Apply suggestions from code review

* doc(#12): update readme

* fix(#12): add integration test + feedback

* 1.4.0
  • Loading branch information
paulpascal authored Jun 29, 2024
1 parent 4d93578 commit 975d57c
Show file tree
Hide file tree
Showing 31 changed files with 11,752 additions and 2,745 deletions.
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ dist
src/package.json
.eslintcache
.DS_Store
json_docs
upload-docs.*.json
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ FROM node:20-alpine

ENV EXTERNAL_PORT 3000
ENV PORT 3000
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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ 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.

Then run:
Expand All @@ -128,6 +131,20 @@ 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:
Expand All @@ -137,10 +154,15 @@ 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`
`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 | `6378`
`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
33 changes: 30 additions & 3 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:
- NODE_ENV=${NODE_ENV:-production}
- EXTERNAL_PORT=${EXTERNAL_PORT:-3000}
- 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}'
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
20 changes: 13 additions & 7 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
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
PORT=3000 # for development environmentcontainer)
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
#REDIS_HOST=redis # Redis server hostname - only uncomment if you know what you're doing
#REDIS_PORT=6378 # Redis server port - only uncomment if you know what you're doing
CHT_DEV_HTTP=false # 'true' for http 'false' for https
CHT_DEV_URL_PORT=localhost:5984 # where your dev CHT instance is, hostname:port
#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 975d57c

Please sign in to comment.