diff --git a/.env.example b/.env.example index 85faa03777dd1af16d608530a5c92c0ad8f3a9fc..3864d26b960d71a8a4b48c06b4d894ef27ababfc 100644 --- a/.env.example +++ b/.env.example @@ -14,4 +14,4 @@ AGENT_DB_PASS=postgres AGENT_PORT=8001 ALLOWED_ORIGINS=* -SWAGGER=false +SWAGGER=false \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6e611ba2382f78dc800c042ef9025ca46cac99d7..bc283cc085d683e2c4bcedabfbf984d06fd09df5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,119 +1,13 @@ +variables: + NODE_VERSION: "18.19.1" + include: - - project: 'gaiax/helpers/mono-helpers' + - project: ${HELPERS_PATH} file: - - ocm-engine.yml + - mono-template.yml stages: - lint - build - - release - - docker - - registries - - helm - - deploy-test - - deploy-prod - -# Bare microservice build - -build-all: - extends: .build-all - stage: build - -# Docker build microservices - -docker-agent: - extends: .docker-agent - stage: docker - -docker-hin-agent: - extends: .docker-hin-agent - stage: docker - -docker-dashboard: - extends: .docker-dashboard - stage: docker - -# Push to registries - -registry-agent: - extends: .registry-agent - stage: registries - -registry-hin-agent: - extends: .registry-hin-agent - stage: registries - -registry-dashboard: - extends: .registry-dashboard - stage: registries - -# Configure helm - -helm-agent: - extends: .helm-agent - stage: helm - -helm-hin-agent: - extends: .helm-hin-agent - stage: helm - -helm-dashboard: - extends: .helm-dashboard - stage: helm - - -deploy agent hin: - extends: .deploy-agent-hin-main - stage: deploy-test - -deploy agent hin tagged: - extends: .deploy-agent-hin-tag - stage: deploy-test - -deploy agent ocm: - extends: .deploy-agent-ocm-main - stage: deploy-test - -deploy agent ocm tagged: - extends: .deploy-agent-ocm-main-tag - stage: deploy-test - -deploy agent ocm test: - extends: .deploy-agent-ocm-test - stage: deploy-test - -deploy agent ocm test tagged: - extends: .deploy-agent-ocm-test-tag - stage: deploy-test - -deploy dashboard ocm: - extends: .deploy-dashboard-ocm-main - stage: deploy-test - -deploy dashboard ocm tagged: - extends: .deploy-dashboard-ocm-main-tag - stage: deploy-test - -deploy dashboard ocm test: - extends: .deploy-dashboard-ocm-test - stage: deploy-test - -deploy dashboard ocm test tagged: - extends: .deploy-dashboard-ocm-test-tag - stage: deploy-test - -deploy agent cloud auth: - extends: .deploy-agent-cloud-auth-main - stage: deploy-prod - -deploy agent cloud auth tagged: - extends: .deploy-agent-cloud-auth-tag - stage: deploy-prod - -commit lint: - extends: .commit-lint - stage: lint - -changelog: - extends: .changelog - stage: release + - changelog + - trigger-deploy diff --git a/apps/agent/deployment/ci-cd/Dockerfile b/apps/agent/deployment/ci-cd/Dockerfile index 50fd4edb5b18cfd12ab88d824e2b1d7de5c2fd22..9ef9d3580e77a24aa2a8f3d0e63c2d5e9f9bc42b 100644 --- a/apps/agent/deployment/ci-cd/Dockerfile +++ b/apps/agent/deployment/ci-cd/Dockerfile @@ -1,29 +1,56 @@ +FROM node:18.19.1 as base +RUN apt update -y && apt install yarn python3 make build-essential -y + +FROM base as deps +WORKDIR /app + +COPY package.json . +COPY yarn.lock . + +RUN yarn install --frozen-lockfile + +FROM base as linter +#TODO: pass MR title and validate it +RUN apt update -y && apt install yarn python3 make build-essential -y + +WORKDIR /app + +COPY . . + +COPY --from=deps /app/node_modules ./node_modules + +RUN npx nx run-many --target=lint --projects=agent --configuration=production +RUN npx nx run-many --target=test --projects=agent --configuration=production + +FROM base as builder + +RUN apt update -y && apt install yarn python3 make build-essential -y + +WORKDIR /app +COPY . . +COPY --from=deps /app/node_modules ./node_modules + +RUN yarn nx run-many --target=build --projects=agent --configuration=production + FROM node:18.19.1-buster-slim as production ENV NODE_ENV production -# Instal required software RUN apt update -y && apt install yarn python3 make build-essential -y WORKDIR /app -# Copy the build artifacts from the previous stage -COPY build /app/build +#copy from build +COPY --from=builder /app/dist . -# Install only required dependencies, see nx.json generatePackageJson -COPY build/apps/agent/package.json . -COPY build/apps/agent/yarn.lock . -RUN yarn install +COPY --from=builder /app/dist/apps/agent/package.json . +COPY --from=builder /app/dist/apps/agent/yarn.lock . -COPY build/apps/agent . -COPY build/libs . -RUN rm -rf /app/build/* +RUN yarn install --frozen-lockfile # Expose required ports EXPOSE 8080 EXPOSE 8001 EXPOSE 6001 -#####hashtag -# Command / Entrypoint -CMD ["node", "main.js"] +CMD ["node", "/app/apps/agent/main.js"] \ No newline at end of file diff --git a/apps/agent/src/main.ts b/apps/agent/src/main.ts index 932ec151e6531e2b4de5363a9e1ef9e6ba1bb714..60f11fe22521f76ce50d69b3d284b57a7879a77c 100644 --- a/apps/agent/src/main.ts +++ b/apps/agent/src/main.ts @@ -1,8 +1,3 @@ -/** - * This is not a production server yet! - * This is only a minimal backend to get started. - */ - import { Logger } from "@nestjs/common"; import { NestFactory } from "@nestjs/core"; @@ -14,12 +9,17 @@ import process from "process"; import { LogLevel } from "@credo-ts/core"; import { configureLogger } from "./configure.logger"; -configureLogger(parseInt(process.env["LOG_LEVEL"]!) ?? LogLevel.error); +configureLogger( + !isNaN(parseInt(process.env["LOG_LEVEL"])) + ? parseInt(process.env["LOG_LEVEL"]) + : LogLevel.error, +); async function bootstrap() { const app = await NestFactory.create(AppModule); const origins = (process.env.ALLOWED_ORIGINS || "").split(","); + app.enableCors({ origin: origins.length > 1 ? origins : origins[0] || "", methods: "GET,HEAD,PUT,PATCH,POST,DELETE", diff --git a/apps/dashboard/deployment/ci-cd/Dockerfile b/apps/dashboard/deployment/ci-cd/Dockerfile index 4c9259ef7211997d2c5efad4200482c8c48bdbe5..f6a7270ac660eb7ba262108f4bfca81b1a5cdccd 100644 --- a/apps/dashboard/deployment/ci-cd/Dockerfile +++ b/apps/dashboard/deployment/ci-cd/Dockerfile @@ -1,40 +1,48 @@ -FROM nginx:1-alpine as production +FROM node:18.19.1 AS base +RUN apt update -y && apt install yarn python3 make build-essential -y -ENV NODE_ENV production +FROM base AS deps +WORKDIR /app -# Install yarn -RUN apk add --no-cache yarn +COPY package.json . +COPY yarn.lock . + +RUN yarn install --frozen-lockfile + +FROM base AS linter +#TODO: pass MR title and validate it + +WORKDIR /app + +COPY . . + +COPY --from=deps /app/node_modules ./node_modules + +RUN npx nx run-many --target=lint --projects=dashboard --configuration=production +RUN npx nx run-many --target=test --projects=dashboard --configuration=production + +FROM base AS build WORKDIR /app -# Copy the build artifacts from the previous stage -COPY build /app/build +COPY . . -# Install only required dependencies, see nx.json generatePackageJson -COPY build/apps/dashboard/package.json . -COPY build/apps/dashboard/yarn.lock . -RUN yarn install +COPY --from=deps /app/node_modules ./node_modules +RUN yarn nx run dashboard:build:production -# Create required directories -RUN mkdir -p /usr/share/nginx/html/ocm-test/dashboard /usr/share/nginx/html/ocm/dashboard +FROM nginx:1-alpine AS production -# Move the projects -RUN mv build/apps/ocm-test-dashboard/* /usr/share/nginx/html/ocm-test/dashboard && \ - mv build/apps/dashboard/* /usr/share/nginx/html/ocm/dashboard +RUN apk add --no-cache yarn -# Copy shared resources -RUN cp -r build/libs/clients /usr/share/nginx/html/ocm-test/dashboard/clients && \ - cp -r build/libs/clients /usr/share/nginx/html/ocm/dashboard/clients +ENV NODE_ENV production -# Create symlink for node_modules -RUN ln -s /app/node_modules /usr/share/nginx/html/ocm-test/dashboard/node_modules && \ - ln -s /app/node_modules /usr/share/nginx/html/ocm/dashboard/node_modules +WORKDIR /app -RUN rm -rf /app/build/* +COPY --from=build /app/dist/apps/dashboard /usr/share/nginx/html/ +COPY --from=deps /app/node_modules /usr/share/nginx/html/node_modules +COPY ./apps/dashboard/deployment/ci-cd/nginx.conf /etc/nginx/conf.d/default.conf -# Expose the port that NGINX will run on -EXPOSE 8080 +EXPOSE 80 -# Command / Entrypoint CMD ["nginx", "-g", "daemon off;"] diff --git a/apps/dashboard/deployment/ci-cd/helm/Chart.yaml b/apps/dashboard/deployment/ci-cd/helm/Chart.yaml deleted file mode 100644 index 721efcadc1fa3ef823341df1c8189d5892ffb957..0000000000000000000000000000000000000000 --- a/apps/dashboard/deployment/ci-cd/helm/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v1 -appVersion: build-654 -description: dashboard deployment -name: dashboard -version: 0.0.2 -icon: "https://www.vereign.com/wp-content/themes/vereign2020/images/vereign-logo.svg" diff --git a/apps/dashboard/deployment/ci-cd/helm/templates/ConfigMap.yaml b/apps/dashboard/deployment/ci-cd/helm/templates/ConfigMap.yaml deleted file mode 100644 index 4eb90dd5f7a08b28e4b6d7b2f8eabad031b234c9..0000000000000000000000000000000000000000 --- a/apps/dashboard/deployment/ci-cd/helm/templates/ConfigMap.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ template "app.name" . }}-config - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} -data: - config.js: | - {{- if eq .Release.Namespace "ocm" }} - window.OCMENGINE_HTTP_URL="{{ .Values.ocm.dashboard.agent.http }}"; - window.OCMENGINE_WS_URL="{{ .Values.ocm.dashboard.agent.wss }}"; - window.TSA_URL="{{ .Values.ocm.dashboard.tsa }}"; - window.BASE_PATH="{{ .Values.ocm.dashboard.basepath }}"; - {{- else if eq .Release.Namespace "ocm-test" }} - window.OCMENGINE_HTTP_URL="{{ .Values.ocmtest.dashboard.agent.http }}"; - window.OCMENGINE_WS_URL="{{ .Values.ocmtest.dashboard.agent.wss }}"; - window.TSA_URL="{{ .Values.ocmtest.dashboard.tsa }}"; - window.BASE_PATH="{{ .Values.ocmtest.dashboard.basepath }}"; - {{- end }} diff --git a/apps/dashboard/deployment/ci-cd/helm/templates/_helpers.tpl b/apps/dashboard/deployment/ci-cd/helm/templates/_helpers.tpl deleted file mode 100644 index 6cba3ffc4fead9c4924f9788d1fb6c1daf8874e3..0000000000000000000000000000000000000000 --- a/apps/dashboard/deployment/ci-cd/helm/templates/_helpers.tpl +++ /dev/null @@ -1,94 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "app.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "app.fullname" -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- printf "%s-%s" $name .Release.Namespace | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create instance name based on app version and short image sha. -*/}} -{{- define "app.revision" -}} -{{- default .Release.Name .Values.appRel | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "app.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "app.labels" -}} -helm.sh/chart: {{ include "app.chart" . }} -{{ include "app.selectorLabels" . }} -app.kubernetes.io/version: {{ .Chart.AppVersion }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "app.selectorLabels" -}} -app.kubernetes.io/name: {{ include "app.name" . }} -app.kubernetes.io/component: {{ include "app.fullname" . }} -{{- end -}} - -{{/* -Metrics Annotations -*/}} -{{- define "app.metricsAnnotations" -}} -{{- if .Values.metrics.enabled -}} -prometheus.io/scrape: "true" -prometheus.io/port: "{{ .Values.metrics.port }}" -prometheus.io/path: {{ .Values.metrics.path | default "/metrics" | quote }} -{{- end -}} -{{- end -}} - -{{/* -Image string -*/}} -{{- define "app.image" -}} -{{- if .Values.image.sha -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}@{{ .Values.image.sha }} -{{- else -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }} -{{- end -}} -{{- end -}} - -{{/* -Security context -*/}} -{{- define "app.securitycontext" -}} -runAsNonRoot: {{ .Values.security.runAsNonRoot | default false }} -runAsGroup: {{ .Values.security.runAsGid | default 0 }} -runAsUser: {{ .Values.security.runAsUid | default 0 }} -fsGroup: {{ .Values.security.runAsGid | default 0 }} -{{- end -}} - -{{/* -PostgreSQL Connection string URI -*/}} -{{- define "app.postgresql.connectionstring" -}} -postgresql://{{ .Values.attestationManager.database.user }}:{{ .Values.attestationManager.database.password }}@{{ .Values.attestationManager.database.host }}:{{ .Values.attestationManager.database.port }}/{{ .Release.Namespace }}_{{ include "app.name" . | replace "-" "_" }}?schema={{ .Values.attestationManager.database.schema }} -{{- end -}} - -{{/* -Ingress custom path. -*/}} -{{- define "app.path" -}} -{{- default .Chart.Name .Values.ingress.pathOverride | replace "-manager" "" | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/apps/dashboard/deployment/ci-cd/helm/templates/deployment.yaml b/apps/dashboard/deployment/ci-cd/helm/templates/deployment.yaml deleted file mode 100644 index bb59b01d66122804eebf5bd3e40bfc59ef5cebc3..0000000000000000000000000000000000000000 --- a/apps/dashboard/deployment/ci-cd/helm/templates/deployment.yaml +++ /dev/null @@ -1,63 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: "{{ template "app.name" . }}" - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} - app.kubernetes.io/instance: {{ include "app.revision" . }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 1 - maxUnavailable: 0 - selector: - matchLabels: - {{- include "app.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "app.labels" . | nindent 8 }} - annotations: - {{- include "app.metricsAnnotations" . | nindent 8 }} -{{- if .Values.podAnnotations }} -{{ toYaml .Values.podAnnotations | indent 8 }} -{{- end }} - spec: - securityContext: -{{- include "app.securitycontext" . | nindent 8 }} - imagePullSecrets: - - name: {{ .Values.image.pullSecrets }} - containers: - - name: {{ template "app.name" . }} - image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy | quote }} -{{- if .Values.extraVars }} -{{ toYaml .Values.extraVars | indent 8 }} -{{- end }} - ports: - {{- if .Values.metrics.enabled }} - - name: monitoring - containerPort: {{ .Values.metrics.port }} - {{- end }} - - name: http - containerPort: {{ .Values.service.port }} - resources: -{{ toYaml .Values.resources | indent 10 }} - volumeMounts: - {{- if eq .Release.Namespace "ocm" }} - - name: {{ template "app.name" . }}-config - mountPath: /usr/share/nginx/html/ocm/dashboard/assets/config.js - subPath: config.js - {{- else if eq .Release.Namespace "ocm-test" }} - - name: {{ template "app.name" . }}-config - mountPath: /usr/share/nginx/html/ocm-test/dashboard/assets/config.js - subPath: config.js - {{- end }} - volumes: - - name: {{ template "app.name" . }}-config - configMap: - name: {{ template "app.name" . }}-config - diff --git a/apps/dashboard/deployment/ci-cd/helm/templates/ingress.yaml b/apps/dashboard/deployment/ci-cd/helm/templates/ingress.yaml deleted file mode 100644 index 95517eaa8d1fda54ca824473af2716fee4790e3d..0000000000000000000000000000000000000000 --- a/apps/dashboard/deployment/ci-cd/helm/templates/ingress.yaml +++ /dev/null @@ -1,47 +0,0 @@ -{{- if .Values.ingress.enabled }} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} - {{- if eq .Release.Namespace "ocm" }} - annotations: -{{ toYaml .Values.ingress.ocm.annotations | indent 4 }} - {{- else if eq .Release.Namespace "ocm-test" }} - annotations: -{{ toYaml .Values.ingress.ocmtest.annotations | indent 4 }} - {{- end }} - labels: - {{- include "app.labels" . | nindent 4 }} -spec: -{{- if .Values.ingress.tlsEnabled }} - tls: - - hosts: - - {{ .Values.ingress.frontendDomain }} - secretName: {{ .Values.ingress.frontendTlsSecretName }} -{{- end }} - rules: - {{- if eq .Release.Namespace "ocm" }} - - host: {{ .Values.ingress.frontendDomain }} - http: - paths: - - path: /ocm/dashboard(/|$)(.*) - pathType: Prefix - backend: - service: - name: {{ template "app.name" . }} - port: - number: {{ .Values.service.port }} - {{- else if eq .Release.Namespace "ocm-test" }} - - host: {{ .Values.ingress.frontendDomain }} - http: - paths: - - path: /ocm-test/dashboard(/|$)(.*) - pathType: Prefix - backend: - service: - name: {{ template "app.name" . }} - port: - number: {{ .Values.service.port }} - {{- end }} -{{- end }} diff --git a/apps/dashboard/deployment/ci-cd/helm/templates/service.yaml b/apps/dashboard/deployment/ci-cd/helm/templates/service.yaml deleted file mode 100644 index 375d171e72676405623eea98ed0e7bb8412ac8ea..0000000000000000000000000000000000000000 --- a/apps/dashboard/deployment/ci-cd/helm/templates/service.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} -spec: - clusterIP: None - ports: - - name: http - port: {{ .Values.service.port }} - targetPort: {{ .Values.service.port }} - selector: - {{- include "app.selectorLabels" . | nindent 4 }} diff --git a/apps/dashboard/deployment/ci-cd/helm/values.yaml b/apps/dashboard/deployment/ci-cd/helm/values.yaml deleted file mode 100644 index 71840be446884f4ed08ec153fc6fdb1a0ba5ede1..0000000000000000000000000000000000000000 --- a/apps/dashboard/deployment/ci-cd/helm/values.yaml +++ /dev/null @@ -1,101 +0,0 @@ -# -- Default number of instances to start ..... -replicaCount: 1 -# -- Application name ... -name: dashboard -# -- Ovverwrites application name ... -nameOverride: "" - -image: - repository: eu.gcr.io/vrgn-infra-prj - # -- Image name .. - name: gaiax/ocm/ocm-engine/dashboard - # -- Image tag .. - # Uses .Chart.AppVersion if empty . - tag: "" - # -- Image sha, usually generated by the CI . - # Uses image.tag if empty . - sha: "" - # -- Image pull policy . - pullPolicy: Always - # -- Image pull secret when internal image is used . - pullSecrets: deployment-key-light - -resources: - requests: - cpu: 250m - -autoscaling: - # -- Enable autoscaling . - enabled: false - # -- Minimum replicas . - minReplicas: 1 - # -- Maximum replicas . - maxReplicas: 3 - # -- CPU target for autoscaling trigger . - targetCPUUtilizationPercentage: 70 - # -- Memory target for autoscaling trigger . - targetMemoryUtilizationPercentage: 70 -## -## Prometheus Exporter / Metrics . -## - -metrics: - # -- Enable prometheus metrics . - enabled: true - # -- Port for prometheus metrics . - port: 2112 - -## -## Kubernetes [SecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) object. -## - -security: - # -- by default, apps run as non-root . - runAsNonRoot: false - # -- User used by the apps . - runAsUid: 0 - # -- Group used by the apps . - runAsGid: 0 - -ocm: - dashboard: - agent: - ws: "wss://ssi-dev.vereign.com/api-issuer" - http: "https://ssi-dev.vereign.com/api-issuer" - tsa: "https://ssi-dev.vereign.com/ocm/login" - basepath: "/ocm/dashboard" - -ocmtest: - dashboard: - agent: - ws: "wss://ssi-dev.vereign.com/api-holder" - http: "https://ssi-dev.vereign.com/api-holder" - tsa: "https://ssi-dev.vereign.com/ocm-test/login" - basepath: "/ocm-test/dashboard" - -service: - port: 8080 - -ingress: - enabled: true - tlsEnabled: true - frontendDomain: ssi-dev.vereign.com - frontendTlsSecretName: cert-manager-tls - - ocm: - annotations: { - kubernetes.io/ingress.class: "nginx", - cert-manager.io/cluster-issuer: letsencrypt-production-http, - kubernetes.io/ingress.global-static-ip-name: ssi-dev, - nginx.ingress.kubernetes.io/rewrite-target: /ocm/dashboard/$2 - } - - ocmtest: - annotations: { - kubernetes.io/ingress.class: "nginx", - cert-manager.io/cluster-issuer: letsencrypt-production-http, - kubernetes.io/ingress.global-static-ip-name: ssi-dev, - nginx.ingress.kubernetes.io/rewrite-target: /ocm-test/dashboard/$2 - } - - diff --git a/apps/dashboard/deployment/ci-cd/nginx.conf b/apps/dashboard/deployment/ci-cd/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..f50bfba942315ba310ba118889fc4b2a09ede66c --- /dev/null +++ b/apps/dashboard/deployment/ci-cd/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.html; + try_files $uri /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file diff --git a/apps/dashboard/src/assets/config.js.example b/apps/dashboard/src/assets/config.js.example index 7ce5785edddca5068434eece97cef040aaf5c34f..5f78a063191039def98f6d03645b31ec0a5e5253 100644 --- a/apps/dashboard/src/assets/config.js.example +++ b/apps/dashboard/src/assets/config.js.example @@ -1,4 +1,2 @@ window.OCMENGINE_HTTP_URL="https://ssi-dev.vereign.com/ocm-test-gateway"; -window.OCMENGINE_WS_URL="wss://ssi-dev.vereign.com/ocm-test-gateway"; -window.TSA_URL="https://tsa.vereign.com"; -window.BASE_PATH="/"; +window.TSA_URL="https://tsa.vereign.com"; \ No newline at end of file diff --git a/apps/dashboard/src/components/App/index.tsx b/apps/dashboard/src/components/App/index.tsx index edcaac2bfb4a7d33e727cd1a32e3c1fad305ca05..5ad7e2cb4526577007333a4b275887785932e703 100644 --- a/apps/dashboard/src/components/App/index.tsx +++ b/apps/dashboard/src/components/App/index.tsx @@ -18,7 +18,7 @@ const App = observer(() => { onUnauthorized: () => { auth.setToken(null); }, - wsUrl: config.OCMENGINE_WS_URL, + wsUrl: "", httpUrl: config.OCMENGINE_HTTP_URL, getAuthorization: async () => config.OCMENGINE_AUTHORIZATION || `Bearer ${auth.getToken()}` || "", diff --git a/apps/dashboard/src/main.tsx b/apps/dashboard/src/main.tsx index 9b91aa72dbb97fed10977a2c257ad854040c7cf9..88b6fe1fbe67ca3635ad487d161188ce54e568fa 100644 --- a/apps/dashboard/src/main.tsx +++ b/apps/dashboard/src/main.tsx @@ -17,7 +17,7 @@ import "@fontsource/roboto/700.css"; const config = getConfig(); setOcmEngineConfig({ - wsUrl: config.OCMENGINE_WS_URL, + wsUrl: "", httpUrl: config.OCMENGINE_HTTP_URL, getAuthorization: async () => "", }); @@ -33,7 +33,7 @@ const root = ReactDOM.createRoot( document.getElementById("root") as HTMLElement, ); root.render( - <BrowserRouter basename={window.BASE_PATH}> + <BrowserRouter> <ConfigProvider theme={{ token: { diff --git a/apps/dashboard/src/routes/pages/LoginPage/AuthForm/index.tsx b/apps/dashboard/src/routes/pages/LoginPage/AuthForm/index.tsx index 1c970046055a62fb477b4f174a47258a30d3e8f9..57d8b7ab4349285709edc55b2fab15b4a83c92b6 100644 --- a/apps/dashboard/src/routes/pages/LoginPage/AuthForm/index.tsx +++ b/apps/dashboard/src/routes/pages/LoginPage/AuthForm/index.tsx @@ -76,7 +76,7 @@ const LoginPage = observer(() => { } value={store.proofUrlShort || "loading"} size={400} - icon={getFullHttpPath("/assets/Vereign_Logo_ICON_BLACK.png")} + icon="/assets/Vereign_Logo_ICON_BLACK.png" /> </div> {store.acceptanceExpired && ( @@ -108,18 +108,4 @@ const LoginPage = observer(() => { ); }); -function getFullHttpPath(partialPath: string) { - const domain = window.location.origin; - const BASE_PATH = window.BASE_PATH; - - const formattedBasePath = BASE_PATH.endsWith("/") - ? BASE_PATH - : `${BASE_PATH}/`; - const formattedPartialPath = partialPath.startsWith("/") - ? partialPath.substring(1) - : partialPath; - - return `${domain}${formattedBasePath}${formattedPartialPath}`; -} - export default LoginPage; diff --git a/apps/dashboard/src/routes/pages/RegisterPage/index.tsx b/apps/dashboard/src/routes/pages/RegisterPage/index.tsx index b67752e455fc2293f3d91535a30dfbba7bd57765..e8ad8b56fe6ced4dfa4622c2ba04a2cf672adf60 100644 --- a/apps/dashboard/src/routes/pages/RegisterPage/index.tsx +++ b/apps/dashboard/src/routes/pages/RegisterPage/index.tsx @@ -102,7 +102,7 @@ const RegisterPage = observer(() => { } value={store.shortCredentialUrl || "loading"} size={400} - icon={`${window.BASE_PATH}/assets/Vereign_Logo_ICON_BLACK.png`} + icon={"/assets/Vereign_Logo_ICON_BLACK.png"} /> </div> ))} diff --git a/apps/dashboard/src/utils/getConfig.ts b/apps/dashboard/src/utils/getConfig.ts index 96b5af62e01edbd9d52d7a00f57a6a046bf21997..83cd21cf8d2d2b9178a6aad443cebc138d5b5608 100644 --- a/apps/dashboard/src/utils/getConfig.ts +++ b/apps/dashboard/src/utils/getConfig.ts @@ -1,21 +1,16 @@ export interface Config { OCMENGINE_HTTP_URL: string; - OCMENGINE_WS_URL: string; TSA_URL: string; - BASE_PATH: string; OCMENGINE_AUTHORIZATION: string | null | undefined; } const lsHttp = localStorage.getItem("OCMENGINE_HTTP_URL"); -const lsWs = localStorage.getItem("OCMENGINE_WS_URL"); const authorization = localStorage.getItem("OCMENGINE_AUTHORIZATION"); const tsaHttp = localStorage.getItem("TSA_URL"); export const getConfig = (): Config => { return { OCMENGINE_HTTP_URL: lsHttp || window.OCMENGINE_HTTP_URL, - OCMENGINE_WS_URL: lsWs || window.OCMENGINE_WS_URL, TSA_URL: tsaHttp || window.TSA_URL, - BASE_PATH: window.BASE_PATH, OCMENGINE_AUTHORIZATION: authorization, }; }; diff --git a/apps/dashboard/types.d.ts b/apps/dashboard/types.d.ts index fca3e2adc81158765743d8538ac4ec7efa47b17b..f0e1d783b03e7370c207b60498b4fa4280bc8b78 100644 --- a/apps/dashboard/types.d.ts +++ b/apps/dashboard/types.d.ts @@ -1,9 +1,7 @@ export {}; declare global { interface Window { - BASE_PATH: string; OCMENGINE_HTTP_URL: string; - OCMENGINE_WS_URL: string; TSA_URL: string; } } diff --git a/apps/hin-agent/.eslintrc.json b/apps/hin-agent/.eslintrc.json deleted file mode 100644 index 9d9c0db55bb1e91c5f2e7b64a02bc6bf69fc7cb5..0000000000000000000000000000000000000000 --- a/apps/hin-agent/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.ts", "*.tsx"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "rules": {} - } - ] -} diff --git a/apps/hin-agent/README.md b/apps/hin-agent/README.md deleted file mode 100644 index 63a0c6113ee88579512ff090302b25584e202825..0000000000000000000000000000000000000000 --- a/apps/hin-agent/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# OCM ENGINE - AGENT - -Agent service is a wrapper around @ocm-engine/askar library. - -The agent can be started with two different mods - Rest and Consumer, default behaviour is a message consumer. - -Agent will consume messages from a broker (NATS) on a pre-configured stream and subjects. - -Then it will do execute the task and send result to the @ocm-engine/gateway. - -## Agent setup - -### From the root of the project run: - - -#### Install dependencies -``` -yarn install -``` -#### Copy .env.example to .env - -``` -cp .env.exampe .env -``` - -Do changes to the .env according to your needs. - -#### Start the agent locally: - -``` -yarn serve:agent -``` diff --git a/apps/hin-agent/deployment/ci-cd/Dockerfile b/apps/hin-agent/deployment/ci-cd/Dockerfile deleted file mode 100644 index 24523c9addff5dd78353efe95c96aab731cc373e..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/ci-cd/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -FROM node:18.19.1-buster-slim as production - -ENV NODE_ENV production - -# Instal required software -RUN apt update -y && apt install yarn python3 make build-essential -y - -WORKDIR /app - -# Copy the build artifacts from the previous stage -COPY build /app/build - -# Install only required dependencies, see nx.json generatePackageJson -COPY build/apps/hin-agent/package.json . -COPY build/apps/hin-agent/yarn.lock . -RUN yarn install - -COPY build/apps/hin-agent . -COPY build/libs . -RUN rm -rf /app/build/* - -# Expose required ports -EXPOSE 8080 -EXPOSE 8001 -EXPOSE 6001 - -#####hashtag -# Command / Entrypoint -CMD ["node", "main.js"] diff --git a/apps/hin-agent/deployment/ci-cd/helm/Chart.yaml b/apps/hin-agent/deployment/ci-cd/helm/Chart.yaml deleted file mode 100644 index e90911dc67a8c3b34901c687d348e887558b135d..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/ci-cd/helm/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v1 -appVersion: build-654 -description: hin-agent deployment -name: hin-agent -version: 0.0.2 -icon: "https://www.vereign.com/wp-content/themes/vereign2020/images/vereign-logo.svg" diff --git a/apps/hin-agent/deployment/ci-cd/helm/templates/_helpers.tpl b/apps/hin-agent/deployment/ci-cd/helm/templates/_helpers.tpl deleted file mode 100644 index 6cba3ffc4fead9c4924f9788d1fb6c1daf8874e3..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/ci-cd/helm/templates/_helpers.tpl +++ /dev/null @@ -1,94 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "app.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "app.fullname" -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- printf "%s-%s" $name .Release.Namespace | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create instance name based on app version and short image sha. -*/}} -{{- define "app.revision" -}} -{{- default .Release.Name .Values.appRel | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "app.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "app.labels" -}} -helm.sh/chart: {{ include "app.chart" . }} -{{ include "app.selectorLabels" . }} -app.kubernetes.io/version: {{ .Chart.AppVersion }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "app.selectorLabels" -}} -app.kubernetes.io/name: {{ include "app.name" . }} -app.kubernetes.io/component: {{ include "app.fullname" . }} -{{- end -}} - -{{/* -Metrics Annotations -*/}} -{{- define "app.metricsAnnotations" -}} -{{- if .Values.metrics.enabled -}} -prometheus.io/scrape: "true" -prometheus.io/port: "{{ .Values.metrics.port }}" -prometheus.io/path: {{ .Values.metrics.path | default "/metrics" | quote }} -{{- end -}} -{{- end -}} - -{{/* -Image string -*/}} -{{- define "app.image" -}} -{{- if .Values.image.sha -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}@{{ .Values.image.sha }} -{{- else -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }} -{{- end -}} -{{- end -}} - -{{/* -Security context -*/}} -{{- define "app.securitycontext" -}} -runAsNonRoot: {{ .Values.security.runAsNonRoot | default false }} -runAsGroup: {{ .Values.security.runAsGid | default 0 }} -runAsUser: {{ .Values.security.runAsUid | default 0 }} -fsGroup: {{ .Values.security.runAsGid | default 0 }} -{{- end -}} - -{{/* -PostgreSQL Connection string URI -*/}} -{{- define "app.postgresql.connectionstring" -}} -postgresql://{{ .Values.attestationManager.database.user }}:{{ .Values.attestationManager.database.password }}@{{ .Values.attestationManager.database.host }}:{{ .Values.attestationManager.database.port }}/{{ .Release.Namespace }}_{{ include "app.name" . | replace "-" "_" }}?schema={{ .Values.attestationManager.database.schema }} -{{- end -}} - -{{/* -Ingress custom path. -*/}} -{{- define "app.path" -}} -{{- default .Chart.Name .Values.ingress.pathOverride | replace "-manager" "" | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/apps/hin-agent/deployment/ci-cd/helm/templates/deployment.yaml b/apps/hin-agent/deployment/ci-cd/helm/templates/deployment.yaml deleted file mode 100644 index 75d9ea00de7056de38b41d5d7af8bf5f043df274..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/ci-cd/helm/templates/deployment.yaml +++ /dev/null @@ -1,92 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: "{{ template "app.name" . }}" - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} - app.kubernetes.io/instance: {{ include "app.revision" . }} - app.kubernetes.io/part-of: rse -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 1 - maxUnavailable: 0 - selector: - matchLabels: - {{- include "app.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "app.labels" . | nindent 8 }} - annotations: - {{- include "app.metricsAnnotations" . | nindent 8 }} -{{- if .Values.podAnnotations }} -{{ toYaml .Values.podAnnotations | indent 8 }} -{{- end }} - spec: - securityContext: -{{- include "app.securitycontext" . | nindent 8 }} - imagePullSecrets: - - name: {{ .Values.image.pullSecrets }} - containers: - - name: {{ template "app.name" . }} - image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy | quote }} - env: - {{- if eq .Release.Namespace "hin" }} - - name: LEDGERS - value: {{ .Values.hin.agent.ledgers | quote }} - - name : AGENT_PEER_URL - value: {{ .Values.hin.agent.peer.url | quote }} - - name: AGENT_NAME - value: {{ .Values.hin.agent.name | quote }} - - name: AGENT_KEY - value: {{ .Values.hin.agent.key | quote }} - - name: AGENT_DID_SEED - value: {{ .Values.hin.agent.did.seed | quote }} - - name: AGENT_DB_HOST - value: {{ .Values.hin.agent.db.host | quote }} - - name: AGENT_DB_USER - value: {{ .Values.hin.agent.db.user | quote }} - - name: AGENT_DB_PASS - value: {{ .Values.hin.agent.db.pass | quote }} - - name: AGENT_PORT - value: {{ .Values.hin.agent.port | quote }} - - name: ALLOWED_ORIGINS - value: {{ .Values.hin.agent.allowedOrigin | quote }} - - name: AUTH_BASIC_USER - value: {{ .Values.hin.agent.api.basic.user | quote }} - - name: AUTH_BASIC_PASS - value: {{ .Values.hin.agent.api.basic.pass | quote }} - - name: AUTH_JWT_PUBLIC_KEY - value: {{ .Values.hin.agent.api.jwt.publicKey | quote }} - - name: HIN_SVDX_WEBHOOK_URL - value: {{ .Values.hin.agent.svdx.webhook.url | quote }} - - name: HIN_SVDX_BASIC_USER - value: {{ .Values.hin.agent.svdx.basic.user | quote }} - - name: HIN_SVDX_BASIC_PASS - value: {{ .Values.hin.agent.svdx.basic.pass | quote }} - - name: HIN_OOB_GOALS - value: {{ .Values.hin.agent.invitationGoals | quote }} - - name: HIN_WEBHOOK_URL - value: {{ .Values.hin.agent.oob.url | quote }} - {{- end }} -{{- if .Values.extraVars }} -{{ toYaml .Values.extraVars | indent 8 }} -{{- end }} - ports: - {{- if .Values.metrics.enabled }} - - name: monitoring - containerPort: {{ .Values.metrics.port }} - {{- end }} - - name: http - containerPort: {{ .Values.service.port }} - - name: peer - containerPort: {{ .Values.service.port1 }} - - name: http2 - containerPort: {{ .Values.service.port2 }} - resources: -{{ toYaml .Values.resources | indent 10 }} diff --git a/apps/hin-agent/deployment/ci-cd/helm/templates/ingress.yaml b/apps/hin-agent/deployment/ci-cd/helm/templates/ingress.yaml deleted file mode 100644 index 01defc006a4d08905aad12cc0ffedd1303ba0fc5..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/ci-cd/helm/templates/ingress.yaml +++ /dev/null @@ -1,38 +0,0 @@ -{{- if .Values.ingress.enabled }} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} - annotations: -{{ toYaml .Values.ingress.annotations | indent 4 }} - labels: - {{- include "app.labels" . | nindent 4 }} -spec: -{{- if .Values.ingress.tlsEnabled }} - tls: - - hosts: - - {{ .Values.ingress.frontendDomain }} - secretName: {{ .Values.ingress.frontendTlsSecretName }} -{{- end }} - rules: - {{- if eq .Release.Namespace "hin" }} - - host: {{ .Values.ingress.frontendDomain }} - http: - paths: - - path: /hin-agent(/|$)(.*) - pathType: Prefix - backend: - service: - name: {{ template "app.name" . }} - port: - number: {{ .Values.service.port1 }} - - path: /api-hin-agent(/|$)(.*) - pathType: Prefix - backend: - service: - name: {{ template "app.name" . }} - port: - number: {{ .Values.hin.agent.port }} - {{- end }} -{{- end }} diff --git a/apps/hin-agent/deployment/ci-cd/helm/templates/service.yaml b/apps/hin-agent/deployment/ci-cd/helm/templates/service.yaml deleted file mode 100644 index 46c59e5c5e19057c6225b2886d504fdd53556fe7..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/ci-cd/helm/templates/service.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} -spec: - clusterIP: None - ports: - - name: http - port: {{ .Values.service.port }} - targetPort: {{ .Values.service.port }} - - name: http1 - port: {{ .Values.service.port1 }} - targetPort: {{ .Values.service.port1 }} - - name: http2 - port: {{ .Values.service.port2 }} - targetPort: {{ .Values.service.port2 }} - selector: - {{- include "app.selectorLabels" . | nindent 4 }} diff --git a/apps/hin-agent/deployment/ci-cd/helm/values.yaml b/apps/hin-agent/deployment/ci-cd/helm/values.yaml deleted file mode 100644 index 73c5f1ee80a7667cd74803f72daea2d731903f9f..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/ci-cd/helm/values.yaml +++ /dev/null @@ -1,100 +0,0 @@ -# -- Default number of instances to start ..... -replicaCount: 1 -# -- Application name ... -name: hin-agent -# -- Ovverwrites application name ... -nameOverride: "" - -image: - repository: eu.gcr.io/vrgn-infra-prj - # -- Image name .. - name: gaiax/ocm/ocm-engine/hin-agent - # -- Image tag .. - # Uses .Chart.AppVersion if empty . - tag: "" - # -- Image sha, usually generated by the CI . - # Uses image.tag if empty . - sha: "" - # -- Image pull policy . - pullPolicy: Always - # -- Image pull secret when internal image is used . - pullSecrets: deployment-key-light - -resources: - requests: - cpu: 250m - -autoscaling: - # -- Enable autoscaling . - enabled: false - # -- Minimum replicas . - minReplicas: 1 - # -- Maximum replicas . - maxReplicas: 3 - # -- CPU target for autoscaling trigger . - targetCPUUtilizationPercentage: 70 - # -- Memory target for autoscaling trigger . - targetMemoryUtilizationPercentage: 70 -## -## Prometheus Exporter / Metrics . -## - -metrics: - # -- Enable prometheus metrics . - enabled: true - # -- Port for prometheus metrics . - port: 2112 - -## -## Kubernetes [SecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) object. -## - -security: - # -- by default, apps run as non-root . - runAsNonRoot: false - # -- User used by the apps . - runAsUid: 0 - # -- Group used by the apps . - runAsGid: 0 - -hin: - agent: - ledgers: "BCOVRIN_TEST" - peer: - url: "https://ssi-dev.vereign.com/hin-agent" - name: "hin-agent-dev" - key: "Fpvsvz0seqevq7RRiPbRT6oopAcrMXcaY8d" - did: - seed: "8rQuMQ6YeVF1CVyKp4KZTjikpwM4irGl26Ds" - port: 8080 - svdx: - basic: - user: "" - pass: "" - webhook: - url: "https://did.svdx.pro/ocm/connection" - db: - host: "" - user: "" - pass: "" - allowedOrigin: "*" - invitationGoals: "connection.exchange" - api: - jwt: - publicKey: "" - basic: - user: "ocmhin-admin" - pass: "" - oob: - url: "https://hin-dev.vereign.com" - -service: - port: 8080 - port1: 8001 - port2: 8010 - -ingress: - enabled: true - tlsEnabled: true - frontendDomain: ssi-dev.vereign.com - frontendTlsSecretName: cert-manager-tls diff --git a/apps/hin-agent/deployment/local/Dockerfile b/apps/hin-agent/deployment/local/Dockerfile deleted file mode 100644 index 072b47c6eb670470472d30a395c0bff80378573e..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/local/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM node:18.19.1-buster-slim - -RUN apt update -y && apt install yarn python3 make build-essential -y - -WORKDIR app - -COPY ./dist/apps/hin-agent . -COPY package.json yarn.lock ./ - -RUN yarn install - -EXPOSE 8080 -EXPOSE 8001 -EXPOSE 6001 - -CMD ["node", "main.js"] diff --git a/apps/hin-agent/deployment/local/HinDockerfile b/apps/hin-agent/deployment/local/HinDockerfile deleted file mode 100644 index 50326cd453bbb4d4b50a0e4d30dfb9e1136ff4f6..0000000000000000000000000000000000000000 --- a/apps/hin-agent/deployment/local/HinDockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM node:18.16.0-buster-slim - -RUN apt update -y && apt install python3 git make cmake build-essential -y - -WORKDIR /app - -COPY . . - -RUN yarn install -RUN yarn build:hin-agent - -EXPOSE 8080 -EXPOSE 8001 - -CMD ["node", "./dist/apps/hin-agent/main.js"] diff --git a/apps/hin-agent/jest.config.ts b/apps/hin-agent/jest.config.ts deleted file mode 100644 index ffeddf42973a312615fcd6ade8d4a1d4781a0c44..0000000000000000000000000000000000000000 --- a/apps/hin-agent/jest.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint-disable */ -export default { - displayName: "agent", - preset: "../../jest.preset.js", - testEnvironment: "node", - transform: { - "^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }], - }, - moduleFileExtensions: ["ts", "js", "html"], - coverageDirectory: "../../coverage/apps/hin-agent", - collectCoverage: true, - verbose: true, -}; diff --git a/apps/hin-agent/project.json b/apps/hin-agent/project.json deleted file mode 100644 index 727ba92a585f26971e738f74f14cab55f112609c..0000000000000000000000000000000000000000 --- a/apps/hin-agent/project.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "name": "hin-agent", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "apps/hin-agent/src", - "projectType": "application", - "targets": { - "build": { - "executor": "@nx/webpack:webpack", - "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", - "options": { - "target": "node", - "compiler": "tsc", - "outputPath": "dist/apps/hin-agent", - "main": "apps/hin-agent/src/main.ts", - "tsConfig": "apps/hin-agent/tsconfig.app.json", - "isolatedConfig": true, - "webpackConfig": "apps/hin-agent/webpack.config.js", - "transformers": [ - { - "name": "@nestjs/swagger/plugin", - "options": { - "introspectComments": true - } - } - ] - }, - - "configurations": { - "development": {}, - "production": {} - } - }, - "serve": { - "executor": "@nx/js:node", - "defaultConfiguration": "development", - "options": { - "buildTarget": "agent:build" - }, - "configurations": { - "development": { - "buildTarget": "agent:build:development" - }, - "production": { - "buildTarget": "agent:build:production" - } - } - }, - "lint": { - "executor": "@nx/linter:eslint", - "outputs": ["{options.outputFile}"], - "options": { - "lintFilePatterns": ["apps/hin-agent/**/*.ts"] - } - }, - "test": { - "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], - "options": { - "jestConfig": "apps/hin-agent/jest.config.ts", - "passWithNoTests": true - }, - "configurations": { - "ci": { - "ci": true, - "codeCoverage": true - } - } - } - }, - "tags": [] -} diff --git a/apps/hin-agent/src/app/app.module.ts b/apps/hin-agent/src/app/app.module.ts deleted file mode 100644 index 5769d21c2bc914cdf47c2417c16b0452a7cb3546..0000000000000000000000000000000000000000 --- a/apps/hin-agent/src/app/app.module.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Module } from "@nestjs/common"; - -import { AskarDynamicModule } from "@ocm-engine/askar"; -import { ConfigModule } from "@nestjs/config"; -import { - agentConfig, - agentSchema, - authConfig, - authSchema, - ledgersConfig, - ledgersSchema, -} from "@ocm-engine/config"; -import Joi from "joi"; -import { hinSchema } from "./config/hin.schema"; -import { hinConfig } from "./config/hin.config"; -import { AgentEventListenerService } from "./svdx/agent-event-listener.service"; - -const validationSchema = Joi.object({ - agent: agentSchema, - auth: authSchema, - ledgers: ledgersSchema, - hin: hinSchema, -}); - -@Module({ - imports: [ - AskarDynamicModule.forRootAsync(), - ConfigModule.forRoot({ - isGlobal: true, - load: [agentConfig, authConfig, ledgersConfig, hinConfig], - validationSchema, - }), - ], - controllers: [], - providers: [AgentEventListenerService], -}) -export class AppModule {} diff --git a/apps/hin-agent/src/app/config/hin.config.interface.ts b/apps/hin-agent/src/app/config/hin.config.interface.ts deleted file mode 100644 index 60630030ffd2477f1e143f896d2a6c7037d371d4..0000000000000000000000000000000000000000 --- a/apps/hin-agent/src/app/config/hin.config.interface.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface IConfHin { - hinOobGoals: Array<string>; - hinSVDXWebHook: string; - hinSVDXBasicUser: string; - hinSVDXBasicPass: string; - hinWebHook: string; -} diff --git a/apps/hin-agent/src/app/config/hin.config.ts b/apps/hin-agent/src/app/config/hin.config.ts deleted file mode 100644 index 704d35f7bd4473217ef60c3630f37bf6b2ed7f2c..0000000000000000000000000000000000000000 --- a/apps/hin-agent/src/app/config/hin.config.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { registerAs } from "@nestjs/config"; -import * as process from "process"; -import { IConfHin } from "./hin.config.interface"; - -export const hinConfig = registerAs( - "hin", - (): IConfHin => ({ - hinOobGoals: - typeof process.env["HIN_OOB_GOALS"] !== "undefined" - ? process.env["HIN_OOB_GOALS"]!.split(",") - : [], - hinSVDXWebHook: process.env["HIN_SVDX_WEBHOOK_URL"]!, - hinSVDXBasicUser: process.env["HIN_SVDX_BASIC_USER"]!, - hinSVDXBasicPass: process.env["HIN_SVDX_BASIC_PASS"]!, - hinWebHook: process.env["HIN_WEBHOOK_URL"]!, - }), -); diff --git a/apps/hin-agent/src/app/config/hin.schema.ts b/apps/hin-agent/src/app/config/hin.schema.ts deleted file mode 100644 index a4c11e06201b58afe06951d32a04fde2ad9025a5..0000000000000000000000000000000000000000 --- a/apps/hin-agent/src/app/config/hin.schema.ts +++ /dev/null @@ -1,9 +0,0 @@ -import Joi from "joi"; - -export const hinSchema = Joi.object({ - HIN_SVDX_WEBHOOK_URL: Joi.string().required(), - HIN_SVDX_BASIC_USER: Joi.string().required(), - HIN_SVDX_BASIC_PASS: Joi.string().required(), - HIN_OOB_GOALS: Joi.string().required(), - HIN_WEBHOOK_URL: Joi.string().required(), -}); diff --git a/apps/hin-agent/src/app/svdx/agent-event-listener.service.ts b/apps/hin-agent/src/app/svdx/agent-event-listener.service.ts deleted file mode 100644 index 05eab2d4199dbab6c73649882655e6cd416e5da8..0000000000000000000000000000000000000000 --- a/apps/hin-agent/src/app/svdx/agent-event-listener.service.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { Injectable, Logger, OnModuleInit } from "@nestjs/common"; -import { AskarService } from "@ocm-engine/askar"; -import { - BasicMessageEventTypes, - TrustPingEventTypes, - BasicMessageRole, - BasicMessageStateChangedEvent, - ConnectionEventTypes, - ConnectionStateChangedEvent, - ProofEventTypes, - ProofStateChangedEvent, - TrustPingResponseReceivedEvent, -} from "@credo-ts/core"; -import { MessageRecordDto } from "@ocm-engine/dtos"; -import { ConfigService } from "@nestjs/config"; -import { - svdxConnectionStateChangeHandler, - svdxProofStateChangeHandler, - webHookHandler, -} from "./svdx.utils"; -import { IConfHin } from "../config/hin.config.interface"; - -@Injectable() -export class AgentEventListenerService implements OnModuleInit { - private hinConfig: IConfHin | undefined; - private readonly logger: Logger = new Logger(AgentEventListenerService.name); - - constructor( - private readonly askar: AskarService, - private readonly configService: ConfigService, - ) {} - - onModuleInit(): void { - this.logger.debug("Agent is listening for AFJ events"); - this.hinConfig = this.configService.get<IConfHin>("hin"); - - this.askar.agent.events.on( - ConnectionEventTypes.ConnectionStateChanged, - async (ev: ConnectionStateChangedEvent) => { - this.logger.log("connection state event received"); - this.logger.debug(JSON.stringify(ev, null, 2)); - return svdxConnectionStateChangeHandler( - ev, - this.askar.agent, - this.hinConfig, - ); - }, - ); - - this.askar.agent.events.on( - ProofEventTypes.ProofStateChanged, - async (ev: ProofStateChangedEvent) => { - this.logger.log("proof state event received"); - this.logger.debug(JSON.stringify(ev, null, 2)); - - return svdxProofStateChangeHandler( - ev, - this.askar.agent, - this.hinConfig, - ); - }, - ); - - this.askar.agent.events.on( - TrustPingEventTypes.TrustPingResponseReceivedEvent, - async (ev: TrustPingResponseReceivedEvent) => { - return webHookHandler(this.hinConfig?.hinWebHook, "ping", { - thid: ev.payload.message.threadId, - connectionId: ev.payload.connectionRecord.id, - }); - }, - ); - - this.askar.agent.events.on( - BasicMessageEventTypes.BasicMessageStateChanged, - async (ev: BasicMessageStateChangedEvent) => { - if (ev.payload.basicMessageRecord.role === BasicMessageRole.Receiver) { - this.logger.debug(JSON.stringify(ev, null, 2)); - - const messageRecord = ev.payload.basicMessageRecord; - - const connectionInfo = await this.askar.agent.connections.findById( - messageRecord.connectionId, - ); - const label = connectionInfo?.theirLabel || ""; - const dto = MessageRecordDto.fromJson({ - id: messageRecord.id, - createdAt: messageRecord.createdAt, - updatedAt: messageRecord.updatedAt, - connectionId: messageRecord.connectionId, - role: messageRecord.role, - content: messageRecord.content, - sentTime: messageRecord.sentTime, - from: messageRecord.role === BasicMessageRole.Receiver ? label : "", - to: messageRecord.role === BasicMessageRole.Sender ? label : "", - }); - - this.logger.debug( - "agent is configured as rest, webhook still not implemented", - ); - } - }, - ); - } -} diff --git a/apps/hin-agent/src/app/svdx/svdx.utils.ts b/apps/hin-agent/src/app/svdx/svdx.utils.ts deleted file mode 100644 index ceed737fabd93dfb101adebd1f4e63de853a591a..0000000000000000000000000000000000000000 --- a/apps/hin-agent/src/app/svdx/svdx.utils.ts +++ /dev/null @@ -1,163 +0,0 @@ -import { - Agent, - ConnectionStateChangedEvent, - DidExchangeRole, - ProofState, - ProofStateChangedEvent, -} from "@credo-ts/core"; -import { AnonCredsProof } from "@credo-ts/anoncreds"; -import { IConfHin } from "../config/hin.config.interface"; -import axios, { AxiosResponse } from "axios"; - -export const svdxProofStateChangeHandler = async ( - ev: ProofStateChangedEvent, - agent: Agent, - hinConfig?: IConfHin, -) => { - if (ProofState.Done !== ev.payload.proofRecord.state) { - return; - } - - const presentationMessage = await agent.proofs.findPresentationMessage( - ev.payload.proofRecord.id, - ); - - console.log(JSON.stringify(presentationMessage, null, 2)); - if (!presentationMessage) { - console.log("No presentation message found"); - return; - } - - const attachmentId = presentationMessage.formats[0].attachmentId; - - const attachment = - presentationMessage.getPresentationAttachmentById(attachmentId); - - console.log(JSON.stringify(attachment, null, 2)); - if (!attachment) { - console.log("No attachment found"); - return; - } - - const email = - attachment.getDataAsJson<AnonCredsProof>()?.requested_proof.revealed_attrs[ - "email" - ].raw; - - try { - console.log( - `sending data to svdx ${email}, ${ev.payload.proofRecord.connectionId}`, - ); - await axios.post( - hinConfig?.hinSVDXWebHook, - { - email, - connectionId: ev.payload.proofRecord.connectionId, - }, - { - auth: { - username: hinConfig?.hinSVDXBasicUser, - password: hinConfig?.hinSVDXBasicPass, - }, - }, - ); - } catch (e) { - console.log(JSON.stringify(e, null, 2)); - } -}; - -export const svdxConnectionStateChangeHandler = async ( - ev: ConnectionStateChangedEvent, - agent: Agent, - hinConfig?: IConfHin, -) => { - if ( - ev.payload.connectionRecord.role === DidExchangeRole.Responder && - ev.payload.connectionRecord.state !== "completed" - ) { - return; - } - - const outOfBandId = ev.payload.connectionRecord.outOfBandId; - - if (typeof outOfBandId === "undefined") { - console.log(JSON.stringify(ev.payload, null, 2)); - console.log("Out of Band id not found, skipping"); - return; - } - - const outOfBandRecord = await agent.oob.findById(outOfBandId); - - if (!outOfBandRecord) { - console.log(JSON.stringify(ev.payload, null, 2)); - console.log("No out of band record found"); - return; - } - - if ( - !outOfBandRecord.outOfBandInvitation.goal || - !hinConfig?.hinOobGoals.includes(outOfBandRecord.outOfBandInvitation.goal) - ) { - console.log(JSON.stringify(ev.payload, null, 2)); - console.log("This connection does not have any goals"); - return; - } - - try { - console.log(`Sending proof request, to ${ev.payload.connectionRecord.id}`); - await agent.proofs.requestProof({ - protocolVersion: "v2", - connectionId: ev.payload.connectionRecord.id, - proofFormats: { - anoncreds: { - name: "proof-request", - version: "1.0", - requested_attributes: { - email: { - name: "email", - }, - }, - }, - }, - }); - } catch (e) { - console.log(JSON.stringify(e, null, 2)); - console.log("failed to offer credential"); - } -}; - -export const webHookHandler = async <T>( - addr: string, - webHookTopic: string, - payload: T, -) => { - const promises: Promise<AxiosResponse>[] = []; - - const tokenUrlPairs = addr.split(";"); - - for (const pair of tokenUrlPairs) { - const [token, url] = pair.split("@"); - - const promise = axios.post(`${url}/topic/${webHookTopic}`, payload, { - headers: { - "X-Api-Key": token, - }, - }); - - promises.push(promise); - } - - const promiseResults = await Promise.allSettled(promises); - for (let index = 0; index < promiseResults.length; index++) { - const promiseResult = promiseResults[index]; - const [_, url] = tokenUrlPairs[index].split("@"); - - if (promiseResult.status === "rejected") { - console.log( - `Failed to send web hook to ${url}/topic/${webHookTopic}. Reason ${promiseResult.reason}`, - ); - continue; - } - console.log(`Successfully sent web hook to ${url}/topic/${webHookTopic}`); - } -}; diff --git a/apps/hin-agent/src/main.ts b/apps/hin-agent/src/main.ts deleted file mode 100644 index 4a0dece52394c4ec3a1b54268e255ede124de167..0000000000000000000000000000000000000000 --- a/apps/hin-agent/src/main.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * This is not a production server yet! - * This is only a minimal backend to get started. - */ - -import { Logger } from "@nestjs/common"; -import { NestFactory } from "@nestjs/core"; - -import { AppModule } from "./app/app.module"; -import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; -import { urlencoded, json } from "express"; -import * as fs from "fs"; - -async function bootstrap() { - const app = await NestFactory.create(AppModule); - - const origins = (process.env.ALLOWED_ORIGINS || "").split(","); - app.enableCors({ - origin: origins.length > 1 ? origins : origins[0] || "", - methods: "GET,HEAD,PUT,PATCH,POST,DELETE", - }); - app.use(json({ limit: "40mb" })); - app.use(urlencoded({ extended: true, limit: "40mb" })); - - const globalPrefix = "api"; - app.setGlobalPrefix(globalPrefix); - const port = process.env.AGENT_PORT || 3001; - app.enableShutdownHooks(); - - if (process.env.SWAGGER === "true") { - const config = new DocumentBuilder() - .setTitle("Agent") - .setDescription("Agent API") - .setVersion("1.0") - .addBearerAuth() - .addBasicAuth() - .build(); - - const document = SwaggerModule.createDocument(app, config); - fs.writeFileSync("./agent-swagger.json", JSON.stringify(document, null, 2)); - SwaggerModule.setup("api", app, document); - Logger.log(`Swagger file written`); - return process.kill(0); - } - - await app.listen(port, "0.0.0.0"); - Logger.log( - `🚀 Application is running on: http://0.0.0.0:${port}/${globalPrefix}`, - ); -} - -bootstrap(); diff --git a/apps/hin-agent/tsconfig.app.json b/apps/hin-agent/tsconfig.app.json deleted file mode 100644 index 954f3ad1c11170724606b4b020297567c518a86b..0000000000000000000000000000000000000000 --- a/apps/hin-agent/tsconfig.app.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["node"], - "emitDecoratorMetadata": true, - "target": "es2015" - }, - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], - "include": ["src/**/*.ts"] -} diff --git a/apps/hin-agent/tsconfig.json b/apps/hin-agent/tsconfig.json deleted file mode 100644 index c1e2dd4e8be6f4fe3dca35d044fd912ff41b1c18..0000000000000000000000000000000000000000 --- a/apps/hin-agent/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.app.json" - }, - { - "path": "./tsconfig.spec.json" - } - ], - "compilerOptions": { - "esModuleInterop": true - } -} diff --git a/apps/hin-agent/tsconfig.spec.json b/apps/hin-agent/tsconfig.spec.json deleted file mode 100644 index 9b2a121d114b68dcdb5b834ebca032814b499a74..0000000000000000000000000000000000000000 --- a/apps/hin-agent/tsconfig.spec.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["jest", "node"] - }, - "include": [ - "jest.config.ts", - "src/**/*.test.ts", - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] -} diff --git a/apps/hin-agent/webpack.config.js b/apps/hin-agent/webpack.config.js deleted file mode 100644 index 0ab513e830c33d6687ae9e14f62f69df7c0df36b..0000000000000000000000000000000000000000 --- a/apps/hin-agent/webpack.config.js +++ /dev/null @@ -1,8 +0,0 @@ -const { composePlugins, withNx } = require("@nx/webpack"); - -// Nx plugins for webpack. -module.exports = composePlugins(withNx(), (config) => { - // Update the webpack config as needed here. - // e.g. `config.plugins.push(new MyPlugin())` - return config; -}); diff --git a/deployment/ci-cd/build.Dockerfile b/deployment/ci-cd/build.Dockerfile deleted file mode 100644 index 248d4d068622ab27a77f3f65f049d1a47b170415..0000000000000000000000000000000000000000 --- a/deployment/ci-cd/build.Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -################### -# Linter, Test, Build -################### - -FROM node:18.19.1 as build - -ARG JOB_ID - -WORKDIR app - -COPY ./package.json . -COPY ./yarn.lock . - -# Install dependencies -RUN yarn install --frozen-lockfile - -COPY . . - -# Linter & test -RUN yarn nx run-many --target=lint --projects=agent,hin-agent,dashboard --configuration=production -RUN yarn nx run-many --target=test --configuration=production - -# Build all -RUN yarn nx run-many --target=build --configuration=production --parallel=3 -RUN yarn nx run dashboard:build:production --output-path ./dist/apps/dashboard --base-href /ocm/dashboard/ --skip-nx-cache -RUN yarn nx run dashboard:build:production --output-path ./dist/apps/ocm-test-dashboard --base-href /ocm-test/dashboard/ --skip-nx-cache -RUN yarn nx run dashboard:build:production --output-path ./dist/apps/swissrun-dashboard --base-href /swissrun/dashboard/ --skip-nx-cache diff --git a/deployment/ci-cd/lint.Dockerfile b/deployment/ci-cd/lint.Dockerfile deleted file mode 100644 index 5b312a615ec8176222c97badc15e11a6d55b3362..0000000000000000000000000000000000000000 --- a/deployment/ci-cd/lint.Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -################### -# Linter, Test -################### - -FROM node:18.19.1 as build - -ARG JOB_ID - -WORKDIR app - -COPY ./package.json . -COPY ./yarn.lock . - -# Install dependencies -RUN yarn install --frozen-lockfile - -COPY . . - -# Linter & test -RUN yarn nx run-many --target=lint --projects=agent,hin-agent,dashboard --configuration=production -RUN yarn nx run-many --target=test --configuration=production diff --git a/package.json b/package.json index 9b51e811bb0bdecee43b52f65ff43f5537d8d668..666bf1428c5f0ed9e181b11a5866287e97a59017 100644 --- a/package.json +++ b/package.json @@ -3,16 +3,13 @@ "version": "0.1.0", "license": "Apache-2.0", "scripts": { - "build:all": "yarn build:agent && yarn build:hin-agent && yarn build:dashboard", + "build:all": "yarn build:agent && yarn build:dashboard", "build:agent": "nx run agent:build:development --parallel=3", "build:agent:production": "nx run agent:build:production", - "build:hin-agent": "nx run hin-agent:build:development --parallel=3", - "build:hin-agent:production": "nx run hin-agent:build:production", "build:dashboard": "nx run dashboard:build:development --parallel=3", "build:dashboard:production": "nx run dashboard:build:production", - "serve:all": "concurrently \"yarn serve:agent\" \"yarn serve:hin-agent\" \"yarn serve:dashboard\"", + "serve:all": "concurrently \"yarn serve:agent\" \"yarn serve:dashboard\"", "serve:agent": "nx run agent:serve:development", - "serve:hin-agent": "nx run hin-agent:serve:development", "serve:dashboard": "nx run dashboard:serve:development", "infra": "cd compose && docker-compose --profile issuer --profile holder up -d --build", "infra:down": "cd compose && docker-compose --profile issuer --profile holder down",