Skip to content

Commit

Permalink
Merge branch 'next' into renderer2024
Browse files Browse the repository at this point in the history
* next:
  chore: fix the dockerfile to set entrypoint
  chore: update vckit Dockerfile (#184)
  chore: update DockerFile and agent template (#183)
  fix: bug fix for dockerize (#174)
  chore: add cicd for running unit test when creating PR (#180)
  chore: update agent config file (#181)

# Conflicts:
#	pnpm-lock.yaml
  • Loading branch information
ducpm511 committed Jun 4, 2024
2 parents 78445c2 + 3d40a6b commit e035b72
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 54 deletions.
15 changes: 9 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
*Dockerfile*
*docker-compose*
node_modules
*/__test__/*
coverage
build
docker-compose.yaml
.dockerignore
**/Dockerfile
**/node_modules
**/__test__
**/coverage
**/build
**/tsconfig.tsbuildinfo
.git
.github
.gitignore
jest.*
*.md
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Test

on:
pull_request:
branches:
- next

jobs:
test_and_build:
runs-on: ubuntu-latest
env:
EXCLUDED_PACKAGE_OA_RENDERERS: '!./packages/vckit-oa-renderers/'
EXCLUDED_PACKAGE_CREDENTIAL_OA: '!./packages/credential-oa/'
EXCLUDED_PACKAGE_EXPLORER: '!./packages/demo-explorer/'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Install pnpm
run: npm i pnpm --global

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '21'

- name: Install dependencies
run: pnpm i --filter ${{ env.EXCLUDED_PACKAGE_OA_RENDERERS }} --filter ${{ env.EXCLUDED_PACKAGE_CREDENTIAL_OA }} --filter ${{ env.EXCLUDED_PACKAGE_EXPLORER }} --no-frozen-lockfile

- name: Build
run: pnpm build:agent

- name: Run tests
run: |
pnpm test:packages --changedSince=origin/next --ci --json --coverage --testLocationInResults --outputFile=report.json
- name: Coverage
uses: artiomtr/jest-coverage-report-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
coverage-file: report.json
base-coverage-file: report.json
threshold: 80
44 changes: 31 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build
FROM node:18 as build
FROM node:20 as build

WORKDIR /app

Expand Down Expand Up @@ -32,20 +32,14 @@ COPY package.json .
COPY pnpm-lock.yaml .
COPY pnpm-workspace.yaml .
COPY lerna.json .
COPY packages/cli/default/agent.template.yml ./agent.template.yml
COPY agent.template.yml .
COPY entrypoint.sh .

COPY packages/tsconfig.json packages/
COPY packages/tsconfig.settings.json packages/

# Install gettext for envsubst command
RUN apt-get update && apt-get install gettext -y

# Substitute environment variables in agent template file
RUN envsubst '${DATABASE_TYPE},${DATABASE_NAME},${DATABASE_HOST},${DATABASE_PORT},${DATABASE_USERNAME},${DATABASE_PASSWORD},${DATABASE_ENCRYPTION_KEY},${PORT},${PROTOCOL},${API_DOMAIN}' \
< ./agent.template.yml \
> ./agent.yml

# Copy package.json for each package
COPY packages/bitstringStatusList/package.json packages/bitstringStatusList/
COPY packages/cli/package.json packages/cli/
COPY packages/core-types/package.json packages/core-types/
COPY packages/credential-merkle-disclosure-proof/package.json packages/credential-merkle-disclosure-proof/
Expand All @@ -57,6 +51,7 @@ COPY packages/oauth-middleware/package.json packages/oauth-middleware/
COPY packages/remote-server/package.json packages/remote-server/
COPY packages/renderer/package.json packages/renderer/
COPY packages/revocation-list-2020/package.json packages/revocation-list-2020/
COPY packages/tools/package.json packages/tools/
COPY packages/utils/package.json packages/utils/
COPY packages/vc-api/package.json packages/vc-api/

Expand All @@ -65,6 +60,7 @@ RUN npm install -g [email protected]
RUN pnpm install

# Copy the source code of each package
COPY packages/bitstringStatusList/ packages/bitstringStatusList/
COPY packages/cli/ packages/cli/
COPY packages/core-types/ packages/core-types/
COPY packages/credential-merkle-disclosure-proof/ packages/credential-merkle-disclosure-proof/
Expand All @@ -76,23 +72,34 @@ COPY packages/oauth-middleware/ packages/oauth-middleware/
COPY packages/remote-server/ packages/remote-server/
COPY packages/renderer/ packages/renderer/
COPY packages/revocation-list-2020/ packages/revocation-list-2020/
COPY packages/tools/ packages/tools/
COPY packages/utils/ packages/utils/
COPY packages/vc-api/ packages/vc-api/

# Build the project
RUN pnpm build

# Stage 2: Run
FROM node:18-alpine as vckit-api
FROM node:20-alpine as vckit-api

WORKDIR /app

# Copy the agent config file
COPY --from=build /app/agent.yml ./agent.yml
RUN apk update && apk add
# Update package lists and install gettext and git
RUN apk update && \
apk add gettext git

COPY --from=build /app/agent.template.yml ./agent.template.yml

# Copy built artifacts and node_modules from the build stage
COPY --from=build /app/node_modules ./node_modules

COPY --from=build /app/.tmp_npm ./.tmp_npm

COPY --from=build /app/packages/bitstringStatusList/build/ packages/bitstringStatusList/build/
COPY --from=build /app/packages/bitstringStatusList/node_modules/ packages/bitstringStatusList/node_modules/
COPY --from=build /app/packages/bitstringStatusList/package.json packages/bitstringStatusList/package.json

COPY --from=build /app/packages/cli/build/ packages/cli/build/
COPY --from=build /app/packages/cli/node_modules/ packages/cli/node_modules/
COPY --from=build /app/packages/cli/package.json packages/cli/package.json
Expand Down Expand Up @@ -123,6 +130,10 @@ COPY --from=build /app/packages/revocation-list-2020/build/ packages/revocation-
COPY --from=build /app/packages/revocation-list-2020/node_modules/ packages/revocation-list-2020/node_modules/
COPY --from=build /app/packages/revocation-list-2020/package.json packages/revocation-list-2020/package.json

COPY --from=build /app/packages/tools/build/ packages/tools/build/
COPY --from=build /app/packages/tools/node_modules/ packages/tools/node_modules/
COPY --from=build /app/packages/tools/package.json packages/tools/package.json

COPY --from=build /app/packages/utils/build/ packages/utils/build/
COPY --from=build /app/packages/utils/node_modules/ packages/utils/node_modules/
COPY --from=build /app/packages/utils/package.json packages/utils/package.json
Expand All @@ -132,6 +143,13 @@ COPY --from=build /app/packages/vc-api/node_modules/ packages/vc-api/node_module
COPY --from=build /app/packages/vc-api/package.json packages/vc-api/package.json
COPY --from=build /app/packages/vc-api/src/vc-api-schemas/vc-api.yaml packages/vc-api/src/vc-api-schemas/vc-api.yaml

# Add an entrypoint script to the image
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Specify the script to run on container start
ENTRYPOINT ["/entrypoint.sh"]

# Expose the port
EXPOSE ${PORT}

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ version: '3.8'

services:
demo-explorer:
image: demo-explore
build:
context: .
dockerfile: packages/demo-explorer/Dockerfile
ports:
- 3000:80
restart: unless-stopped
Expand Down
11 changes: 11 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

echo "Updating agent.yml with environment variables..."

# Replace variables in the agent.yml file with the exported environment variables
envsubst '${DATABASE_TYPE},${DATABASE_NAME},${DATABASE_HOST},${DATABASE_PORT},${DATABASE_USERNAME},${DATABASE_PASSWORD},${DATABASE_ENCRYPTION_KEY},${PORT},${PROTOCOL},${API_DOMAIN}' < /app/agent.template.yml > /app/agent.yml

echo "Agent.yml updated."

# Execute the Docker CMD
exec "$@"
15 changes: 15 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default {
'!**/types/**',
'!**/build/**',
'!**/node_modules/**',
'!packages/vckit-oa-renderers',
'!packages/demo-explorer',
'!packages/credential-oa',
],
coverageReporters: ['text', 'lcov', 'json'],
coverageProvider: 'v8',
Expand All @@ -21,6 +24,9 @@ export default {
'<rootDir>/node_modules/',
'<rootDir>/packages/credential-ld/',
'<rootDir>/packages/vckit-oa-renderers/',
'<rootDir>/packages/demo-explorer/',
'<rootDir>/packages/credential-oa/',
'<rootDir>/.tmp_npm/',
],
testEnvironment: 'node',
automock: false,
Expand All @@ -36,4 +42,13 @@ export default {
},
],
},
// jest will fail if there is less than 80% branch, line, and function coverage, or if there are more than 10 uncovered statements
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10,
},
},
};
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"version": "1.0.0-beta.5",
"scripts": {
"postinstall": "mkdir .tmp_npm; cd .tmp_npm; mkdir veramo; cd veramo; git init; git remote add -f origin https://github.com/gs-gs/veramo.git; git pull --depth=1 origin vc-v2; pnpm install; pnpm build;",
"build": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-json-modules\" pnpm build:js && pnpm build:api && pnpm build:schema",
"build:js": "pnpm -r --stream build",
"build:api": "pnpm --package=@vckit/cli -c dlx \"pnpm -r --stream extract-api\"",
"build": "pnpm build:agent && pnpm build:explorer",
"build:agent": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-json-modules\" pnpm build:js && pnpm build:api && pnpm build:schema",
"build:js": "pnpm -r --stream --filter !./packages/vckit-oa-renderers/ --filter !./packages/credential-oa/ --filter !./packages/demo-explorer/ build",
"build:api": "pnpm --package=@vckit/cli -c dlx \"pnpm -r --stream --filter !./packages/vckit-oa-renderers/ --filter !./packages/credential-oa/ --filter !./packages/demo-explorer/ extract-api\"",
"build:schema": "pnpm --package=@vckit/cli -c dlx \"pnpm -r --stream generate-plugin-schema\"",
"test": "pnpm test:packages && pnpm test:oa-renderer",
"build:explorer": "pnpm -r --stream --filter=@vckit/demo-explorer build",
"test": "pnpm test:packages",
"test:packages-ci": "pnpm test:packages --coverage=true",
"test:packages": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-import-meta-resolve\" jest",
"test:packages-watch": "pnpm test:packages --watch --verbose",
Expand Down Expand Up @@ -84,6 +86,6 @@
"jsonld": "npm:@digitalcredentials/[email protected]"
},
"engines": {
"node": ">= 18.0.0"
"node": ">= 21.0.0"
}
}
}
43 changes: 33 additions & 10 deletions packages/cli/default/agent.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ dbConnection:
port: ${DATABASE_PORT}
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}
synchronize: false
synchronize: true
migrationsRun: true
migrations:
$require: '@veramo/data-store?t=object#migrations'
Expand All @@ -104,7 +104,7 @@ dbConnectionEncrypted:
port: ${DATABASE_PORT}
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}
synchronize: false
synchronize: true
migrationsRun: true
migrations:
$require: '@vckit/encrypted-storage?t=object#migrations'
Expand All @@ -121,14 +121,31 @@ dbConnectionRevocationList:
port: ${DATABASE_PORT}
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}
synchronize: false
synchronize: true
migrationsRun: true
migrations:
$require: '@vckit/revocationlist?t=object#migrations'
logging: false
entities:
$require: '@vckit/revocationlist?t=object#Entities'

dbConnectionBitstringStatusList:
$require: typeorm#DataSource
$args:
- type: ${DATABASE_TYPE}
database: ${DATABASE_NAME}
host: ${DATABASE_HOST}
port: ${DATABASE_PORT}
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}
synchronize: true
migrationsRun: true
migrations:
$require: '@vckit/bitstringStatusList?t=object#migrations'
logging: false
entities:
$require: '@vckit/bitstringStatusList?t=object#Entities'

revocationList:
$require: '@vckit/revocationlist#RevocationStatus2020'
$args:
Expand Down Expand Up @@ -174,9 +191,6 @@ server:
$args:
- basePath: :${PORT}

- - /vc-api-docs
- $require: '@vckit/vc-api?t=function#VCApiDocsRouter'

# API base path
- - /messaging
- $require: '@vckit/remote-server?t=function#MessagingRouter'
Expand All @@ -193,11 +207,14 @@ server:
- - /credentials/status/revocation-list-2020
- $require: '@vckit/revocationlist?t=function#revocationList2020Router'

- - /credentials/status/bitstring-status-list
- $require: '@vckit/bitstringStatusList?t=function#bitstringStatusListRouter'

# API base path
- - /agent
- $require: '@vckit/remote-server?t=function#apiKeyAuth'
$args:
- apiKey: kh14g04piduv
- apiKey: test123

- $require: '@vckit/revocationlist?t=function#revocationList2020Middleware'
$args:
Expand All @@ -221,7 +238,7 @@ server:
- - /open-api.json
- $require: '@vckit/remote-server?t=function#ApiSchemaRouter'
$args:
- basePath: /agent
- basePath: :3332/agent
securityScheme: bearer
apiName: Agent
apiVersion: '1.0.0'
Expand Down Expand Up @@ -402,6 +419,13 @@ renderer:
SvgRenderingHint2022:
$require: '@vckit/renderer#WebRenderingTemplate2022'

bitstringStatusList:
$require: '@vckit/bitstringStatusList#BitstringStatusList'
$args:
- bitstringDomainURL: http://localhost:3332
dbConnection:
$ref: /dbConnectionBitstringStatusList

# Agent
agent:
$require: '@veramo/core#Agent'
Expand All @@ -416,6 +440,7 @@ agent:
- $require: '@veramo/did-comm#DIDComm'
- $require: '@vckit/credential-router#CredentialRouter'
- $require: '@veramo/credential-w3c#CredentialPlugin'
# - $require: '@vckit/credential-oa#CredentialOA' #TODO: Implement
- $ref: /credentialIssuerLD
- $require: '@veramo/credential-eip712#CredentialIssuerEIP712'
- $require: '@veramo/selective-disclosure#SelectiveDisclosure'
Expand All @@ -433,6 +458,4 @@ agent:
$args:
- BitstringStatusListEntry:
$require: '@vckit/bitstringStatusList?t=object#checkStatus'
RevocationList2020Status:
$require: '@vckit/revocationlist?t=object#checkStatus'
- $require: '@vckit/tools#MultibaseEncodedSHA256'
Loading

0 comments on commit e035b72

Please sign in to comment.