Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(docker): Create Docker Compose file for local setup WITHOUT using Postgres/LogTo [DEV-2681] #250

Merged
merged 90 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
5a02f72
Add RUN command for migrating.
abdulla-ashurov Jun 6, 2023
67b457c
Update package-lock.json
abdulla-ashurov Jun 6, 2023
c29675a
Create docker-compose.yml file for running locally
abdulla-ashurov Jun 6, 2023
133f198
Merge remote-tracking branch 'origin/develop' into DEV-2681
abdulla-ashurov Jun 7, 2023
9b78722
Add a new command using for docker-compose.
abdulla-ashurov Jun 7, 2023
c6cb534
Update Dockerfile and docker-compose.yml.
abdulla-ashurov Jun 7, 2023
8da6da4
Add start and stop docker compose scripts.
abdulla-ashurov Jun 7, 2023
c0708ac
Update start-compose.sh.
abdulla-ashurov Jun 8, 2023
65b2375
Move Dockerfile and docker-compose.yml to "docker"
abdulla-ashurov Jun 8, 2023
5953042
Remove unused environment variables.
abdulla-ashurov Jun 8, 2023
53c1393
Update docker-compose.yml.
abdulla-ashurov Jun 8, 2023
6a2aed4
Remove start-compose and stop-compose scripts.
abdulla-ashurov Jun 8, 2023
cd168a3
Update .env.example.
abdulla-ashurov Jun 8, 2023
4b9ed3e
Update README.md.
abdulla-ashurov Jun 8, 2023
ba5eff8
Update build.yml.
abdulla-ashurov Jun 8, 2023
91ed125
Update README.md.
abdulla-ashurov Jun 8, 2023
973f982
Fix typo in README.md.
abdulla-ashurov Jun 8, 2023
68097b7
Update .env.example and docker-compose.yml files.
abdulla-ashurov Jun 8, 2023
4a120b3
Update README.md.
abdulla-ashurov Jun 8, 2023
7ad5377
Merge branch 'develop' into DEV-2681
abdulla-ashurov Jun 8, 2023
f746445
Merge branch 'develop' into DEV-2681
abdulla-ashurov Jun 8, 2023
326f8d7
Update docker-compose.yml.
abdulla-ashurov Jun 9, 2023
78a70ee
Merge branch 'develop' into DEV-2681
DaevMithran Jun 13, 2023
614fa0b
Update Dockerfile and docker-compose.yml.
abdulla-ashurov Jun 13, 2023
bda3529
Merge branch 'develop' into DEV-2681
abdulla-ashurov Jun 13, 2023
79a4473
Update Dockerfile.
abdulla-ashurov Jun 13, 2023
ab0fd38
Remove unused ENV variables from Dockerfile.
abdulla-ashurov Jun 13, 2023
95163b8
Update README.md.
abdulla-ashurov Jun 15, 2023
8e8b617
Add 2 profiles option(credential-service and credential-service-with-…
abdulla-ashurov Jun 15, 2023
2794326
Update README.md.
abdulla-ashurov Jun 15, 2023
47dab49
Change docker image in docker-compose.yml.
abdulla-ashurov Jun 15, 2023
f3353f9
Change Docker service port from "8787" to "3000".
abdulla-ashurov Jun 15, 2023
2429859
Merge branch 'develop' into DEV-2681
ankurdotb Jun 20, 2023
2f62580
bump deps
ankurdotb Jun 20, 2023
5d8af95
Delete custom_button.js
ankurdotb Jun 20, 2023
a767aab
Move Swagger file
ankurdotb Jun 20, 2023
7514f96
Update package-lock.json
ankurdotb Jun 20, 2023
5460467
Update Dockerfile
ankurdotb Jun 20, 2023
898c21f
No DB
ankurdotb Jun 20, 2023
2896cd6
checkin compose
ankurdotb Jun 20, 2023
4bd4f9c
Update docker-compose-no-db.yml
ankurdotb Jun 20, 2023
0fd963b
more compose
ankurdotb Jun 20, 2023
3bb7da7
Fix problem with an invalid path to swagger.json.
abdulla-ashurov Jun 21, 2023
a276fae
Fix bug with an incorrect logic of
abdulla-ashurov Jun 22, 2023
a005303
Update .env.no-db file.
abdulla-ashurov Jun 22, 2023
f43814e
Change the app image to an existing image.
abdulla-ashurov Jun 22, 2023
86813ce
Update package.json.
abdulla-ashurov Jun 22, 2023
77a8004
Update comment in docker-compose-no-db.yml.
abdulla-ashurov Jun 22, 2023
f700e28
Rename environment variables
ankurdotb Jun 22, 2023
9412cb4
Move Swagger back to top level
ankurdotb Jun 22, 2023
92ca0f3
Remove unnecessary NPM commands
ankurdotb Jun 22, 2023
fda223c
Update app.ts
ankurdotb Jun 22, 2023
940f404
Set image to latest
ankurdotb Jun 22, 2023
77165d3
Rename with DB file
ankurdotb Jun 22, 2023
32c15c2
Update .env.no-db
ankurdotb Jun 22, 2023
722ffb9
Change guards
ankurdotb Jun 22, 2023
9b25ca0
Bump package
ankurdotb Jun 22, 2023
de29c70
Change env file name
ankurdotb Jun 22, 2023
29337cd
Rename example ENV
ankurdotb Jun 22, 2023
822072a
Update .gitignore
ankurdotb Jun 22, 2023
f759e1d
Fix problem with an invalid path to swagger.json.
abdulla-ashurov Jun 22, 2023
e183b0f
Update .dockerignore
ankurdotb Jun 22, 2023
b86f1d0
Update build.yml
ankurdotb Jun 22, 2023
d1884a5
Merge branch 'DEV-2681' of https://github.com/cheqd/credential-servic…
ankurdotb Jun 22, 2023
5b34335
Downgrade did-provider-cheqd package
ankurdotb Jun 22, 2023
4d2e825
Update package-lock.json
ankurdotb Jun 22, 2023
513082f
downgrade did-provider-cheqd again
ankurdotb Jun 22, 2023
a6fa9cf
Set default for ENABLE variables
ankurdotb Jun 22, 2023
6cafcb5
Update package.json
ankurdotb Jun 22, 2023
aee39b8
Update package-lock.json
ankurdotb Jun 22, 2023
866d33e
Move files
ankurdotb Jun 22, 2023
c841afb
Update package-lock.json
ankurdotb Jun 22, 2023
2407dba
Checkin new folder structure
ankurdotb Jun 22, 2023
57fc9d0
Update package.json and package-lock.json files.
abdulla-ashurov Jun 22, 2023
49e69e5
Merge branch 'develop' into DEV-2681
ankurdotb Jun 22, 2023
acad474
Merge branch 'develop' into DEV-2681
abdulla-ashurov Jun 22, 2023
ac42202
Merge branch 'DEV-2681' of https://github.com/cheqd/credential-servic…
ankurdotb Jun 22, 2023
eef1ff5
Bump package
ankurdotb Jun 22, 2023
51b7075
Fix paths
ankurdotb Jun 22, 2023
67fff29
Move files around
ankurdotb Jun 22, 2023
b39d904
Fix folder includes in tsconfig
ankurdotb Jun 22, 2023
4620997
Move files around
ankurdotb Jun 22, 2023
f7acd20
convert to typescript
ankurdotb Jun 22, 2023
28bd5b2
Fix TypeScript paths
ankurdotb Jun 22, 2023
808a975
Update package.json
ankurdotb Jun 22, 2023
bc84aaf
Remove includes
ankurdotb Jun 22, 2023
481149c
Update Dockerfile
ankurdotb Jun 22, 2023
963bacc
Revert "Update Dockerfile"
ankurdotb Jun 22, 2023
6c964c2
Fix missing env
ankurdotb Jun 22, 2023
e56738d
Update README.md
ankurdotb Jun 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
MAINNET_RPC_URL=https://rpc.cheqd.net:443
TESTNET_RPC_URL=https://rpc.cheqd.network:443
MAINNET_RPC_URL="https://rpc.cheqd.net:443"
TESTNET_RPC_URL="https://rpc.cheqd.network:443"
RESOLVER_URL="https://resolver.cheqd.net/1.0/identifiers/"
ALLOWED_ORIGINS="http://localhost:8787"
APPLICATION_BASE_URL="http://localhost:8787"
ALLOWED_ORIGINS="http://localhost:8787"

# Database
ENABLE_EXTERNAL_DB="false"
EXTERNAL_DB_CONNECTION_URL=postgres://logto:password@localhost:5432/logto
ENABLE_EXTERNAL_DB="string,default:false"
EXTERNAL_DB_CONNECTION_URL="postgres://<user>:<password>@<host>:<port>/<database>"
EXTERNAL_DB_ENCRYPTION_KEY="<db-encryption-key>"
# EXTERNAL_DB_CERT="certs/issuer.crt"
EXTERNAL_DB_CERT="<path/to/extenal-db-cert>"

# OpenId
LOGTO_RESOURCE_URL='http://localhost:8787'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
file: docker/Dockerfile
platforms: linux/amd64
load: true
target: runner
Expand Down
79 changes: 52 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,39 @@ The application allows configuring the following parameters using environment va

#### Network API endpoints

1. `MAINNET_RPC_URL`: RPC endpoint for cheqd mainnet. (Default: `https://rpc.cheqd.net:443`)
2. `TESTNET_RPC_URL`: RPC endpoint for cheqd testnet. (`https://rpc.cheqd.network:443`)
1. `MAINNET_RPC_URL`: RPC endpoint for cheqd mainnet (Default: `https://rpc.cheqd.net:443`).
2. `TESTNET_RPC_URL`: RPC endpoint for cheqd testnet (`https://rpc.cheqd.network:443`).
3. `RESOLVER_URL`: API endpoint for a [DID Resolver](https://github.com/cheqd/did-resolver) endpoint that supports `did:cheqd`.
4. `APPLICATION_BASE_URL`: URL of the application (external domain name)
4. `APPLICATION_BASE_URL`: URL of the application (external domain name).
5. `ALLOWED_ORIGINS`: CORS allowed origins used in the app.

#### Veramo KMS Database

The application supports two modes in which keys are managed: either just storing them in-memory while a container is running, or persisting them in a PostgresSQL database with Veramo SDK. Using an external Postgres database allows for "custodian" mode where identity and cheqd/Cosmos keys can be offloaded by client applications to be stored in the database.

1. `DB_CONNECTION_URL`: Postgres database connection URL, e.g. `postgres://<user>:<password>@<host>:<port>/<database>`
2. `DB_ENCRYPTION_KEY`: Secret key used to encrypt the Veramo key-specific database tables. This adds a layer of protection by not storing the database in plaintext.
3. `DB_CERTIFICATE`: Custom CA certificate required to connect to the database (optional).
1. `ENABLE_EXTERNAL_DB`: Turns external database on/off (Default: `false`). If `ENABLE_EXTERNAL_DB=true`, then define below environment variables in `.env` file:
- `DB_CONNECTION_URL`: Postgres database connection URL, e.g. `postgres://<user>:<password>@<host>:<port>/<database>`.
- `DB_ENCRYPTION_KEY`: Secret key used to encrypt the Veramo key-specific database tables. This adds a layer of protection by not storing the database in plaintext.
- `DB_CERTIFICATE`: Custom CA certificate required to connect to the database (optional).
- `POSTGRES_USER`: Postgres database username using in database connection URL.
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
- `POSTGRES_PASSWORD`: Postgres database password using in database connection URL.
- `POSTGRES_DB`: Postgres database name using in database connection URL.
> **Note:** `POSTGRES_USER`, `POSTGRES_PASSWORD`, and `POSTGRES_DB` environment variables need only for [running your own credential-service using Docker](#running-your-own-credential-service-using-docker).

#### API Authentication using LogTo

By default, the application has API authentication disabled (which can be changed in configuration). If, however, you'd like to run the app with API authentication features, the following variables need to be configured.

We use a self-hosted version of [LogTo](https://logto.io/), which supports OpenID Connect. Theoretically, these values could also be replaced with [LogTo Cloud](http://cloud.logto.io/) or any other OpenID Connect identity provider.

1. `ENABLE_AUTHENTICATION`: Turns API authentication guards on/off. (Default: `false`)
1. `ENABLE_AUTHENTICATION`: Turns API authentication guards on/off (Default: `false`). If `ENABLE_AUTHENTICATION=false`, then define below environment variable in `.env` file:
- `DEFAULT_CUSTOMER_ID`: Customer/user in LogTo to use for unauthenticated users.
2. `LOGTO_ENDPOINT`: API endpoint for LogTo server
3. `LOGTO_RESOURCE_URL`: API resource associated with application
4. `LOGTO_APP_ID`: Application ID from LogTo. For now, Application is supposed to be a TraditionalWeb
5. `LOGTO_APP_SECRET`: Application secret. Also should encrypted in deployment
6. `ALLOWED_ORIGINS`: CORS allowed origins used in the app
7. `DEFAULT_CUSTOMER_ID`: Customer/user in LogTo to use for unauthenticated users
8. `ALL_SCOPES`: List of all scopes. Should be a string with scopes divided by whitespace, like `account:create account:read did:create`
9. `COOKIE_SECRET`: Secret for cookie encryption.
6. `ALL_SCOPES`: List of all scopes. Should be a string with scopes divided by whitespace, like `account:create account:read did:create`
7. `COOKIE_SECRET`: Secret for cookie encryption.

### 3rd Party Connectors

Expand All @@ -87,11 +92,10 @@ The app supports 3rd party connectors for credential storage and delivery.

The app's [Verida Network](https://www.verida.network/) connector can be enabled to deliver generated credentials to Verida Wallet.

1. `ENABLE_VERIDA_CONNECTOR`: Turns Verida connector on/off. (Default: `false`)
2. `VERIDA_NETWORK`: Verida Network type to connect to. (Default: `testnet`)
3. `VERIDA_PRIVATE_KEY`: Secret key for Verida Network API.
4. `POLYGON_RPC_URL`: Polygon Network RPC URL for connections.
5. `POLYGON_PRIVATE_KEY`: Secret key for Polygon Network.
1. `ENABLE_VERIDA_CONNECTOR`: Turns Verida connector on/off (Default: `false`). If `ENABLE_VERIDA_CONNECTOR=true`, then define below environment variables in `.env` file:
- `VERIDA_NETWORK`: Verida Network type to connect to. (Default: `testnet`)
- `VERIDA_PRIVATE_KEY`: Secret key for Verida Network API.
- `POLYGON_PRIVATE_KEY`: Secret key for Polygon Network.

### Run the application

Expand All @@ -102,31 +106,53 @@ docker pull postgres
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
```

Construct the postgres url and configure the env variables mentioned above
Construct the postgres URL and configure the env variables mentioned above.

Once configured, the app can be run using NPM:
Once configured, install dependencies and the app can be build using NPM:

```bash
npm start
npm install
npm run build
```

## 🧑‍💻🛠 Developer Guide
Run migration using NPM:

### Build using NPM
```bash
npm run migration
```

Dependencies can be installed using NPM or any other node package manager.
The app can be run using NPM:

```bash
npm install
npm run build
npm start
```

## 🧑‍💻🛠 Developer Guide

### Running your own credential-service using Docker

Construct the postgres URL and configure the env variables mentioned above.

Spinning up a Docker container from the [pre-built credential-service Docker image on Github](https://github.com/cheqd/credential-service/pkgs/container/credential-service) is as simple as the command below:

- Running credential-service using Docker with external database:

```bash
docker compose -f docker/docker-compose.yml up --detach
```

- Running credential-service using Docker without external database (In memory database):

```bash
docker compose -f docker/docker-compose.yml up credential-service --detach
```

### Build using Docker

To build and run in Docker, use the [Dockerfile](Dockerfile) provided.
To build and run in Docker, use the [Dockerfile](docker/Dockerfile) provided.

```bash
docker build -t credential-service .
docker build --file docker/Dockerfile --tag credential-service .
```

## 🐞 Bug reports & 🤔 feature requests
Expand All @@ -142,4 +168,3 @@ Please reach out to us there for discussions, help, and feedback on the project.
## 🙋 Find us elsewhere

[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge\&logo=telegram\&logoColor=white)](https://t.me/cheqd) [![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge\&logo=discord\&logoColor=white)](http://cheqd.link/discord-github) [![Twitter](https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge\&logo=twitter\&logoColor=white)](https://twitter.com/intent/follow?screen\_name=cheqd\_io) [![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\&logo=linkedin\&logoColor=white)](http://cheqd.link/linkedin) [![Slack](https://img.shields.io/badge/Slack-4A154B?style=for-the-badge\&logo=slack\&logoColor=white)](http://cheqd.link/join-cheqd-slack) [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge\&logo=medium\&logoColor=white)](https://blog.cheqd.io) [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge\&logo=youtube\&logoColor=white)](https://www.youtube.com/channel/UCBUGvvH6t3BAYo5u41hJPzw/)

38 changes: 38 additions & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
MAINNET_RPC_URL="https://rpc.cheqd.net:443"
TESTNET_RPC_URL="https://rpc.cheqd.network:443"
RESOLVER_URL="https://resolver.cheqd.net/1.0/identifiers/"
APPLICATION_BASE_URL="http://localhost:8787"
ALLOWED_ORIGINS="http://localhost:8787"

# Database
ENABLE_EXTERNAL_DB="string,default:false"
EXTERNAL_DB_CONNECTION_URL="postgres://<user>:<password>@<host>:<port>/<database>"
EXTERNAL_DB_ENCRYPTION_KEY="<db-encryption-key>"
EXTERNAL_DB_CERT="<path/to/extenal-db-cert>"
POSTGRES_USER="<user>"
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
POSTGRES_PASSWORD="<password>"
POSTGRES_DB="<database>"

# OpenId
LOGTO_RESOURCE_URL='http://localhost:8787'

# LogTo
LOGTO_ENDPOINT='http://localhost:3001'
LOGTO_APP_ID='ldfsr...rq432'
LOGTO_APP_SECRET='sdf...sdf'

# Authentication
ENABLE_AUTHENTICATION="false"
DEFAULT_CUSTOMER_ID="default customer id"

# verida
ENABLE_VERIDA_CONNECTOR="false"
VERIDA_PRIVATE_KEY="akjvncanv....avoa"
POLYGON_PRIVATE_KEY="alnvca...dvncioa"
VERIDA_NETWORK="testnet"
POLYGON_RPC_URL=""

ISSUER_ID_PRIVATE_KEY_HEX="akjvncanv....avoa"
ISSUER_ID_PUBLIC_KEY_HEX="alnvca...dvncioa"
ISSUER_DID="did:cheqd:testnet:afcnoa...adv"
FEE_PAYER_MNEMONIC="sketch mountain ....."
11 changes: 7 additions & 4 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ RUN npm ci

# Base arguments: build-time
ARG NPM_CONFIG_LOGLEVEL=warn
ARG PORT=3000
ARG PORT=8787
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved

# Network API endpoints: build-time
ARG MAINNET_RPC_URL=https://rpc.cheqd.net:443
ARG TESTNET_RPC_URL=https://rpc.cheqd.network:443
ARG RESOLVER_URL=https://resolver.cheqd.net/1.0/identifiers/

# Veramo Database configuration: build-time
ARG POSTGRES_USER
ARG POSTGRES_PASSWORD
ARG POSTGRES_DB
ARG DB_CONNECTION_URL
ARG DB_ENCRYPTION_KEY
ARG DB_CERTIFICATE
Expand Down Expand Up @@ -83,6 +86,9 @@ ENV RESOLVER_URL ${RESOLVER_URL}
ENV APPLICATION_BASE_URL ${APPLICATION_BASE_URL}

# Environment variables: Veramo Database configuration
ENV POSTGRES_USER ${POSTGRES_USER}
ENV POSTGRES_PASSWORD ${POSTGRES_PASSWORD}
ENV POSTGRES_DB ${POSTGRES_DB}
ENV DB_CONNECTION_URL ${DB_CONNECTION_URL}
ENV DB_ENCRYPTION_KEY ${DB_ENCRYPTION_KEY}
ENV DB_CERTIFICATE ${DB_CERTIFICATE}
Expand Down Expand Up @@ -114,6 +120,3 @@ EXPOSE ${PORT}
# Set user and shell
USER node
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]

# Run the application
CMD ["npm", "start"]
29 changes: 29 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'

# CAUTION: Please ensure you edit necessary values in .env before using this Docker Compose file.

# SYNTAX: docker compose -f docker/docker-compose.yml up --detach

services:
credential-service:
# OPTIONAL: Rebuild cheqd credential-service Docker image, if you want build your own
# Default is to pull in the pre-published image on GitHub Container Registry
# SYNTAX: docker compose -f docker/docker-compose.yml build
# build:
# context: ../
# dockerfile: docker/Dockerfile
# CAUTION: Change image section's value if building your own image in section below
image: ghcr.io/cheqd/credential-service:latest
ports:
- 8787:8787
env_file:
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
- .env
entrypoint: "npm run compose-run"

database:
image: postgres
user: postgres
ports:
- 5432:5432
env_file:
- .env
48 changes: 43 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"lint": "eslint --max-warnings=0 src && prettier --check '*.{json,js}' 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
"test": "jest --config jestconfig.json --verbose",
"typeorm": "typeorm-ts-node-esm -d ./dist/src/database/ormconfig.js",
"migration": "npm run typeorm migration:generate . && npm run typeorm migration:run"
"migration": "npm run typeorm migration:generate . && npm run typeorm migration:run",
"compose-run": "npm run migration && npm run start"
},
"eslintConfig": {
"root": true,
Expand Down
1 change: 0 additions & 1 deletion src/types/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ declare global {
EXTERNAL_DB_CONNECTION_URL: string
EXTERNAL_DB_ENCRYPTION_KEY: string
EXTERNAL_DB_CERT: string | undefined
ISSUER_DATABASE_CERT: string | undefined
APPLICATION_BASE_URL: string

// LogTo
Expand Down