From 9cff552ad9646e9c2692e22c922af07709b8342f Mon Sep 17 00:00:00 2001 From: Neil South Date: Tue, 26 Jul 2022 12:48:54 +0100 Subject: [PATCH 01/10] adding helm, docs and upped package version Signed-off-by: Neil South --- .../docker-compose}/docker-compose.yml | 0 deploy/helm/.helmignore | 23 +++ deploy/helm/Chart.yaml | 24 ++++ deploy/helm/Gateway.yaml | 22 +++ deploy/helm/MWM.yaml | 26 ++++ deploy/helm/argo.yaml | 14 ++ deploy/helm/holiday-api.yaml | 61 ++++++++ deploy/helm/minio.yaml | 32 +++++ deploy/helm/mongo-local.yaml | 20 +++ deploy/helm/mongo-serviceOnly.yaml | 14 ++ deploy/helm/mongo.yaml | 33 +++++ deploy/helm/postgres.yaml | 18 +++ deploy/helm/rabbitmq.yaml | 23 +++ deploy/helm/templates/NOTES.txt | 22 +++ deploy/helm/templates/_helpers.tpl | 62 ++++++++ deploy/helm/templates/deployment.yaml | 96 +++++++++++++ deploy/helm/templates/hpa.yaml | 28 ++++ deploy/helm/templates/ingress.yaml | 61 ++++++++ deploy/helm/templates/service.yaml | 30 ++++ deploy/helm/templates/serviceaccount.yaml | 12 ++ .../helm/templates/tests/test-connection.yaml | 15 ++ deploy/helm/templates/volume.yml | 26 ++++ deploy/helm/templates/volumeclaim.yml | 16 +++ guidelines/mwm-developer-setup.md | 135 +++++++++++++++++- ...eploy.WorkflowManager.Configuration.csproj | 6 +- src/Configuration/packages.lock.json | 22 +-- ...onai.Deploy.WorkflowManager.Storage.csproj | 4 +- .../packages.lock.json | 20 +-- ...loy.WorkflowManager.PayloadListener.csproj | 6 +- src/PayloadListener/packages.lock.json | 32 ++--- ...loy.WorkflowManager.TaskManager.API.csproj | 6 +- src/TaskManager/API/packages.lock.json | 22 +-- ....Deploy.WorkflowManager.TaskManager.csproj | 6 +- .../AideClinicalReview/packages.lock.json | 26 ++-- ...oy.WorkflowManager.TaskManager.Argo.csproj | 4 +- .../Plug-ins/Argo/packages.lock.json | 28 ++-- src/TaskManager/packages.lock.json | 32 ++--- ...loy.WorkloadManager.WorkfowExecuter.csproj | 4 +- .../Services/WorkflowExecuterService.cs | 3 +- src/WorkflowExecuter/packages.lock.json | 28 ++-- src/WorkflowManager/appsettings.Local.json | 2 +- src/WorkflowManager/packages.lock.json | 44 +++--- ...anager.TaskManager.IntegrationTests.csproj | 2 +- ...r.WorkflowExecutor.IntegrationTests.csproj | 2 +- .../WorkflowManager.Tests/packages.lock.json | 44 +++--- 45 files changed, 982 insertions(+), 174 deletions(-) rename {docker-compose => deploy/docker-compose}/docker-compose.yml (100%) create mode 100644 deploy/helm/.helmignore create mode 100644 deploy/helm/Chart.yaml create mode 100644 deploy/helm/Gateway.yaml create mode 100644 deploy/helm/MWM.yaml create mode 100644 deploy/helm/argo.yaml create mode 100644 deploy/helm/holiday-api.yaml create mode 100644 deploy/helm/minio.yaml create mode 100644 deploy/helm/mongo-local.yaml create mode 100644 deploy/helm/mongo-serviceOnly.yaml create mode 100644 deploy/helm/mongo.yaml create mode 100644 deploy/helm/postgres.yaml create mode 100644 deploy/helm/rabbitmq.yaml create mode 100644 deploy/helm/templates/NOTES.txt create mode 100644 deploy/helm/templates/_helpers.tpl create mode 100644 deploy/helm/templates/deployment.yaml create mode 100644 deploy/helm/templates/hpa.yaml create mode 100644 deploy/helm/templates/ingress.yaml create mode 100644 deploy/helm/templates/service.yaml create mode 100644 deploy/helm/templates/serviceaccount.yaml create mode 100644 deploy/helm/templates/tests/test-connection.yaml create mode 100644 deploy/helm/templates/volume.yml create mode 100644 deploy/helm/templates/volumeclaim.yml diff --git a/docker-compose/docker-compose.yml b/deploy/docker-compose/docker-compose.yml similarity index 100% rename from docker-compose/docker-compose.yml rename to deploy/docker-compose/docker-compose.yml diff --git a/deploy/helm/.helmignore b/deploy/helm/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/deploy/helm/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deploy/helm/Chart.yaml b/deploy/helm/Chart.yaml new file mode 100644 index 000000000..b7c7f03c8 --- /dev/null +++ b/deploy/helm/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: monai +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/deploy/helm/Gateway.yaml b/deploy/helm/Gateway.yaml new file mode 100644 index 000000000..b01c58a7e --- /dev/null +++ b/deploy/helm/Gateway.yaml @@ -0,0 +1,22 @@ +replicaCount: 1 + +image: + repository: 847264867502.dkr.ecr.eu-west-2.amazonaws.com/monai-deploy-informatics-gateway-dev + pullPolicy: IfNotPresent + tag: latest + +enviromentVariables: + InformaticsGateway__messaging__publisherSettings__endpoint: "rabbitmq-monai" + InformaticsGateway__messaging__publisherSettings__username: "admin" + InformaticsGateway__messaging__publisherSettings__password: "admin" + InformaticsGateway__messaging__subscriberSettings__endpoint: "rabbitmq-monai" + InformaticsGateway__messaging__subscriberSettings__username: "admin" + InformaticsGateway__messaging__subscriberSettings__password: "admin" + InformaticsGateway__storage__settings__endpoint: "minio:9000" + InformaticsGateway__storage__settings__accessKey: "minioadmin" + InformaticsGateway__storage__settings__accessToken: "minioadmin" + +service: + type: ClusterIP + port: 5000 + diff --git a/deploy/helm/MWM.yaml b/deploy/helm/MWM.yaml new file mode 100644 index 000000000..d2e0a0777 --- /dev/null +++ b/deploy/helm/MWM.yaml @@ -0,0 +1,26 @@ +replicaCount: 1 + +image: + repository: registry.gitlab.com/answerdigital/londonai/aide/workflow-manager-images/workflow-manager + pullPolicy: IfNotPresent + tag: 2022-07-25 + +imagePullSecrets: + - name: gitlab-image-pull + +enviromentVariables: + WorkflowManager__storage__settings__endpoint: "minio:9000" + # WorkflowManager__messaging__publisherSettings__endpoint: "rabbitmq" + # WorkflowManager__messaging__subscriberSettings__endpoint: "rabbitmq" + WorkflowManager__messaging__publisherSettings__endpoint: "rabbit-monai" + WorkflowManager__messaging__subscriberSettings__endpoint: "rabbit-monai" + WorkloadManagerDatabase__ConnectionString: "mongodb://root:rootpassword@mongo-service-monai:27017" + +service: + type: ClusterIP + port: 5000 + + + + + diff --git a/deploy/helm/argo.yaml b/deploy/helm/argo.yaml new file mode 100644 index 000000000..dbeebdf89 --- /dev/null +++ b/deploy/helm/argo.yaml @@ -0,0 +1,14 @@ + +replicaCount: 1 + + +service: + type: NodePort + port: 2746 + nodeport: 30046 + selector: + app: argo-server + + + + diff --git a/deploy/helm/holiday-api.yaml b/deploy/helm/holiday-api.yaml new file mode 100644 index 000000000..92f25543b --- /dev/null +++ b/deploy/helm/holiday-api.yaml @@ -0,0 +1,61 @@ +# Default values for deploy. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 638262335746.dkr.ecr.eu-west-1.amazonaws.com/holiday-api + pullPolicy: IfNotPresent + tag: #{IMAGE_TAG}# + + +imagePullSecrets: + - name: regcred + +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: false + +service: + type: ClusterIP + port: 5000 + + +enviromentVariables: + ASPNETCORE_ENVIRONMENT: #{ASPENVIRONMENT}# + ASPNETCORE_URLS: "http://::5000" + MongoDbSettings__ConnectionString: "mongodb://mongo-holiday:27017" + MongoDbSettings__DatabaseName: #{MONGODB_NAME}# + Hangfire__ConnectionString: "mongodb://mongo-holiday:27017" + Hangfire__DatabaseName: #{HANGFIREDB_NAME}# + +probes: + # enabled: true + +ingress: + enabled: true + className: "" + annotations: {} + serviceName: #{APISERVICE_NAME}# + annotations: + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/enable-cors: "true" + hosts: + - host: #{APIHOST_NAME}# + paths: + - path: / + pathType: Prefix + tls: [] + +autoscaling: + enabled: false + + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/deploy/helm/minio.yaml b/deploy/helm/minio.yaml new file mode 100644 index 000000000..c29ffffc4 --- /dev/null +++ b/deploy/helm/minio.yaml @@ -0,0 +1,32 @@ +# Default values for deploy. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +# image: + # repository: minio/minio + # pullPolicy: IfNotPresent + # tag: latest + # command: + # - "/bin/sh" + # - "-ce" + # - "/usr/bin/docker-entrypoint.sh minio server /data" + +enviromentVariables: + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadmin + WorkflowManager__storage__settings__endpoint: "minio:9000" + +service: + type: NodePort + port: 9000 + nodeport: 30090 + port2: 9001 + nodeport2: 30091 + selector: + app: minio + + + + diff --git a/deploy/helm/mongo-local.yaml b/deploy/helm/mongo-local.yaml new file mode 100644 index 000000000..92d6834f3 --- /dev/null +++ b/deploy/helm/mongo-local.yaml @@ -0,0 +1,20 @@ + +replicaCount: 1 + +image: + repository: mongo + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "5.0" + +enviromentVariables: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: rootpassword + +service: + type: NodePort + port: 27017 + nodeport: 30017 + + +affinity: {} \ No newline at end of file diff --git a/deploy/helm/mongo-serviceOnly.yaml b/deploy/helm/mongo-serviceOnly.yaml new file mode 100644 index 000000000..800e49e45 --- /dev/null +++ b/deploy/helm/mongo-serviceOnly.yaml @@ -0,0 +1,14 @@ +replicaCount: 1 + + + +service: + type: NodePort + port: 27017 + nodeport: 30017 + selector: + app.kubernetes.io/instance: mongo + app.kubernetes.io/name: monai + + +affinity: {} \ No newline at end of file diff --git a/deploy/helm/mongo.yaml b/deploy/helm/mongo.yaml new file mode 100644 index 000000000..26c7c3462 --- /dev/null +++ b/deploy/helm/mongo.yaml @@ -0,0 +1,33 @@ +# Default values for deploy. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: mongo + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "5.0" + +enviromentVariables: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: rootpassword + +service: + type: ClusterIP + port: 27017 + +volumes: + name: mongo-storage + claimName: mongo-storage-claim + namespace: monai + storage: 5Gi + path: /var/local/mongodata # path on the host + +volumeMounts: + mountPath: "/data/db" + name: mongo-storage + + +affinity: {} \ No newline at end of file diff --git a/deploy/helm/postgres.yaml b/deploy/helm/postgres.yaml new file mode 100644 index 000000000..c724f7093 --- /dev/null +++ b/deploy/helm/postgres.yaml @@ -0,0 +1,18 @@ +# Default values for deploy. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: progress + pullPolicy: IfNotPresent + tag: latest + +service: + type: ClusterIP + port: 80 + +enviromentVariables: + POSTGRES_PASSWORD: mysecretpassword + diff --git a/deploy/helm/rabbitmq.yaml b/deploy/helm/rabbitmq.yaml new file mode 100644 index 000000000..0a92cf0fe --- /dev/null +++ b/deploy/helm/rabbitmq.yaml @@ -0,0 +1,23 @@ +replicaCount: 1 + +image: + repository: rabbitmq + pullPolicy: IfNotPresent + tag: 3.8.18-management + +enviromentVariables: + RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG" + RABBITMQ_DEFAULT_USER: "admin" + RABBITMQ_DEFAULT_PASS: "admin" + RABBITMQ_DEFAULT_VHOST: "monaideploy" + + +service: + type: NodePort + port: 5672 + nodeport: 30072 + port2: 15672 + nodeport2: 30672 + + + diff --git a/deploy/helm/templates/NOTES.txt b/deploy/helm/templates/NOTES.txt new file mode 100644 index 000000000..bb1887b76 --- /dev/null +++ b/deploy/helm/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if ((.Values.ingress).enabled) }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "deploy.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "deploy.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "deploy.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "deploy.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/deploy/helm/templates/_helpers.tpl b/deploy/helm/templates/_helpers.tpl new file mode 100644 index 000000000..7292128ac --- /dev/null +++ b/deploy/helm/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "deploy.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "deploy.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "deploy.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "deploy.labels" -}} +helm.sh/chart: {{ include "deploy.chart" . }} +{{ include "deploy.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "deploy.selectorLabels" -}} +app.kubernetes.io/name: {{ include "deploy.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "deploy.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "deploy.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deploy/helm/templates/deployment.yaml b/deploy/helm/templates/deployment.yaml new file mode 100644 index 000000000..fcd7dd1b6 --- /dev/null +++ b/deploy/helm/templates/deployment.yaml @@ -0,0 +1,96 @@ +{{- if .Values.image -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "deploy.fullname" . }} + labels: + {{- include "deploy.labels" . | nindent 4 }} +spec: + {{- if not ((.Values.autoscaling).enabled) }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "deploy.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "deploy.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if ((.Values.serviceAccount).create) -}} + serviceAccountName: {{ include "deploy.serviceAccountName" . }} + {{- end}} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + + {{- with .Values.volumes }} + volumes: + - name: {{ .name }} + persistentVolumeClaim: + claimName: {{ .claimName }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- if .Values.enviromentVariables }} + env: + {{- range $name, $value := .Values.enviromentVariables }} + - name: {{ $name }} + value: {{ $value }} + {{- end }} + {{- end }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + {{- if .Values.service.port2 }} + - name: service-console + containerPort: {{ .Values.service.port2 }} + {{- end}} + {{- if .Values.image.command }} + command: {{.Values.image.command}} + {{- end}} + {{- if .Values.image.args }} + args: {{.Values.image.args}} + {{- end}} + {{- with .Values.probes }} + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + {{- end }} + {{- with .Values.volumeMounts }} + volumeMounts: + - mountPath: {{ .mountPath }} + name: {{ .name }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/deploy/helm/templates/hpa.yaml b/deploy/helm/templates/hpa.yaml new file mode 100644 index 000000000..e1ec506f2 --- /dev/null +++ b/deploy/helm/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if ((.Values.autoscaling).enabled) }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "deploy.fullname" . }} + labels: + {{- include "deploy.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "deploy.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deploy/helm/templates/ingress.yaml b/deploy/helm/templates/ingress.yaml new file mode 100644 index 000000000..862e0c393 --- /dev/null +++ b/deploy/helm/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if ((.Values.ingress).enabled) -}} +{{- $fullName := include "deploy.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "deploy.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $.Values.ingress.serviceName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deploy/helm/templates/service.yaml b/deploy/helm/templates/service.yaml new file mode 100644 index 000000000..5e3ddfaa9 --- /dev/null +++ b/deploy/helm/templates/service.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "deploy.fullname" . }} + labels: + {{- include "deploy.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + {{- if .Values.service.nodeport}} + nodePort: {{.Values.service.nodeport}} + {{- end}} + protocol: TCP + name: http + {{- if .Values.service.port2}} + - name: service-console + port: {{ .Values.service.port2 }} + {{- if .Values.service.nodeport2}} + nodePort: {{.Values.service.nodeport2}} + {{- end}} + {{- end}} + selector: + {{- if .Values.service.selector }} {{ range $name, $value := .Values.service.selector }} + {{ $name }}: {{ $value }} + {{- end }} + {{- else}} + {{- include "deploy.selectorLabels" . | nindent 4 }} + {{- end}} diff --git a/deploy/helm/templates/serviceaccount.yaml b/deploy/helm/templates/serviceaccount.yaml new file mode 100644 index 000000000..99a259f1e --- /dev/null +++ b/deploy/helm/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if ((.Values.serviceAccount).create) -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "deploy.serviceAccountName" . }} + labels: + {{- include "deploy.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/deploy/helm/templates/tests/test-connection.yaml b/deploy/helm/templates/tests/test-connection.yaml new file mode 100644 index 000000000..86e3e60a4 --- /dev/null +++ b/deploy/helm/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "deploy.fullname" . }}-test-connection" + labels: + {{- include "deploy.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "deploy.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/deploy/helm/templates/volume.yml b/deploy/helm/templates/volume.yml new file mode 100644 index 000000000..c8ac03c07 --- /dev/null +++ b/deploy/helm/templates/volume.yml @@ -0,0 +1,26 @@ +{{- if .Values.volumeMounts -}} +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ $.Values.volumes.name }} + namespace: {{ $.Values.volumes.namespace }} +spec: + storageClassName: "local-storage" + volumeMode: Filesystem + capacity: + storage: {{$.Values.volumes.storage}} + accessModes: + - ReadWriteOnce + local: + path: {{$.Values.volumes.path}} + nodeAffinity: # nodeAffinity is required when using local volumes. + required: + nodeSelectorTerms: + - matchExpressions: + - key: localstorage + operator: In + values: + - "true" +{{- end }} + + diff --git a/deploy/helm/templates/volumeclaim.yml b/deploy/helm/templates/volumeclaim.yml new file mode 100644 index 000000000..bbdab1487 --- /dev/null +++ b/deploy/helm/templates/volumeclaim.yml @@ -0,0 +1,16 @@ +{{- if .Values.volumeMounts -}} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ $.Values.volumes.claimName }} + namespace: {{ $.Values.volumes.namespace }} +spec: + storageClassName: "local-storage" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{$.Values.volumes.storage}} +{{- end }} + + diff --git a/guidelines/mwm-developer-setup.md b/guidelines/mwm-developer-setup.md index d36515f4b..fb8d54626 100644 --- a/guidelines/mwm-developer-setup.md +++ b/guidelines/mwm-developer-setup.md @@ -23,6 +23,137 @@ you have kubernetes running locally either via Docker desktop or microk8s (or si ### steps - following the qickstart here https://argoproj.github.io/argo-workflows/quick-start/ but change to namespace to suit. ie -- - `kubectl create ns minio` -- - `kubectl apply -n minio -f https://raw.githubusercontent.com/argoproj/argo-workflows/master/manifests/quick-start-postgres.yaml` + - `kubectl create ns argo` + - `kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj/argo-workflows/master/manifests/quick-start-postgres.yaml` + - `kubectl config set-context --current --namespace=argo` + +now in a bash window (can be cmd or powershell) + +new bash window `kubectl -n argo port-forward deployment/minio 9000:9000 9001:9001` + +another bash window `kubectl -n argo port-forward deployment/argo-server 2746:2746` + +This allows you to access argo (localhost:2764) and minio (localhost:9001) + +#### Dns change +Now we have our services running we need to make a DNS change, because minio needs to be accessed from argo (within kubernetes) its addressed somthing like this `http://minio:9000` but the code running in VisualStudio also needs to access it. To get around this, in notepad open the file `C:\Windows\System32\drivers\etc\Hosts` add the following line +- `127.0.0.1 minio` + +save the file, now `http://minio:9001` will route to you local machine + +### setup up an input file +- open browser `http://minio:9001/buckets/` +- log in with `admin` `password` +- using the UI make a bucket called `bucket1` +- and a folder called `00000000-1000-0000-0000-000000000000/dcm/` +- make an empty local file called `input_diacom` and drag this into the created folder in the browser. + +### add rabbit and mongo services +from a bash terminal in the root folder of the project +- `helm upgrade -i -n argo -f deploy/helm/mongo-local.yaml mongo deploy/helm` +- `helm upgrade -i -n argo -f deploy/helm/rabbitmq.yaml rabbit deploy/helm` + +### running in VisualStudio +Now assuming your launchSettings has the line +`"ASPNETCORE_ENVIRONMENT": "Local"` +and nobody has broken the `appsettings.Local.json` file +run WorkflowManager (should be the startup project in the solution) in VisualStudio +navigate to `http://localhost:5000/swagger` + +Open the post/workflows tab and click `try it out`, paste in the following to the body + +``` +{ + "name": "noddy workflow", + "version": "1.0.0", + "description": "Attempt at making a workflow", + "informatics_gateway": { + "ae_title": "MYAET", + "data_origins": [ + "MY_SCANNER" + ], + "export_destinations": [ + "PROD_PACS" + ] + }, + "tasks": [ + { + "id": "argo-task", + "description": "trigger simple argo workflow", + "type": "argo", + "args": { + "namespace":"argo", + "workflow_id": "simple-workflow", + "server_url": "https://localhost:2746", + "allow_insecure": true, + "messaging_endpoint": "rabbit-monai", + "messaging_username" : "admin", + "messaging_password" : "admin", + "messaging_topic" : "md.tasks.callback", + "messaging_exchange" : "monaideploy", + "messaging_vhost" : "monaideploy", + }, + "artifacts": { + "input": [ + { + "name": "input_dicom", + "value": "{{ context.input.dicom }}/input_dicom" + } + ], + "output": [ + { + "name": "report", + "value": "{{ context.output }}/report", + "Mandatory": false + } + ] + } + } + ] +} +``` + +#### Things to Note, +- `"server_url": "https://localhost:2746"` +this is where the local running code is expecting to talk to Argo. +- `"messaging_endpoint": "rabbit-monai"` +this is where argo is expecting to find rabbitMq, so this is the kubernetes address ! + +click the `Execute` button, if the code can talk to mongo you will see +``` +{ + "workflow_id": "9235f5e8-9ad2-44d2-8b41-2c1e4d2464c6" +} +``` + +You can use Mongo Compass, with connection string `mongodb://root:rootpassword@localhost:30017` to check the data is there. + +### now we need an argo template to run. +navigate to `https://localhost:2746/workflow-templates?namespace=argo` proceed passed the warnings about been insecure. +click on `CREATE NEW WORKFLOW TEMPLATE` button top left. +rename it to `name: simple-workflow` so it matches the name in our workflow above +then click the `Create` button. +switch the tab back to `workflows` in the left menu (`https://localhost:2746/workflows?limit=50`) + +### rabbitmqAdmin for sending rabbit messages +https://www.rabbitmq.com/management-cli.html + +In the command below replace xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx with the new workflowId from above `9235f5e8-9ad2-44d2-8b41-2c1e4d2464c6` + +`rabbitmqadmin -u admin -p admin -P 30672 -V monaideploy publish exchange=monaideploy routing_key=md.workflow.request properties="{\"app_id\": \"16988a78-87b5-4168-a5c3-2cfc2bab8e54\",\"type\": \"WorkflowRequestMessage\",\"message_id\": \"0277e763-316c-4104-aeda-3620e7a642c7\",\"correlation_id\":\"ab482a7c-4da7-4e76-8d36-d194dd35555e\",\"content_type\": \"application/json\"}" payload="{\"payload_id\":\"00000000-1000-0000-0000-000000000000\",\"workflows\":[\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"],\"file_count\":0,\"correlation_id\":\"e4b06f00-5ce3-4477-86cb-4f3bf20680c2\",\"bucket\":\"bucket1\",\"calling_aetitle\":\"MWM\",\"called_aetitle\":\"Basic_AE_3\",\"timestamp\":\"2022-07-13T11:34:34.8428704+01:00\"}"` + +paste the above (with the proper workflowId) into bash and press enter. + +Debug in VisualStudio (if its not already running) and view the progress +in the argo tab `https://localhost:2746/workflows?limit=50` +you should see the activity of the argo task running. once complete the code will process the callback and update messages. + +in MongoCompass check the results, by refreshing then selecting the created WorkflowInstance +by drilling down into Tasks -> 0 -> ExecutionStats, you should see the reported stats. + +### Re-running + +To re-run the flow again, be sure to delete the workflowInstance object from Mongo, then just redo the `rabbitmqadmin -u admin -p admin -P 30672 -V monai..` + +command from above diff --git a/src/Configuration/Monai.Deploy.WorkflowManager.Configuration.csproj b/src/Configuration/Monai.Deploy.WorkflowManager.Configuration.csproj index a7c82754f..e00985b5a 100644 --- a/src/Configuration/Monai.Deploy.WorkflowManager.Configuration.csproj +++ b/src/Configuration/Monai.Deploy.WorkflowManager.Configuration.csproj @@ -1,4 +1,4 @@ -