Skip to content

Commit

Permalink
Admin UI (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielscholl authored Oct 3, 2024
1 parent 1a960ed commit 3ea102c
Show file tree
Hide file tree
Showing 27 changed files with 806 additions and 54 deletions.
2 changes: 2 additions & 0 deletions bicep/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ param clusterSoftware object = {
enable: true
osduCore: true
osduReference: true
adminUI: true
osduVersion: ''
repository: ''
branch: ''
Expand Down Expand Up @@ -402,6 +403,7 @@ module serviceBlade 'modules/blade_service.bicep' = {
enableSoftwareLoad: clusterSoftware.enable == 'false' ? false : true
enableOsduCore: clusterSoftware.osduCore == 'false' ? false : true
enableOsdureference: clusterSoftware.osduReference == 'false' ? false : true
enableAdminUI: clusterSoftware.adminUI == 'false' ? false : true

emailAddress: emailAddress
applicationClientId: applicationClientId
Expand Down
1 change: 1 addition & 0 deletions bicep/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"osduVersion": "${SOFTWARE_VERSION}",
"osduCore": "${ENABLE_OSDU_CORE}",
"osduReference": "${ENABLE_OSDU_REFERENCE}",
"adminUI": "${ENABLE_ADMIN_UI}",
"repository": "${SOFTWARE_REPOSITORY}",
"branch": "${SOFTWARE_BRANCH}",
"tag": "${SOFTWARE_TAG}"
Expand Down
24 changes: 24 additions & 0 deletions bicep/modules/blade_service.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ param enableOsduCore bool = true
@description('Feature Flag to Load OSDU Reference.')
param enableOsdureference bool = true

@description('Feature Flag to Load Admin UI.')
param enableAdminUI bool = true

@allowed([
'release-0-24'
'release-0-25'
Expand Down Expand Up @@ -161,6 +164,7 @@ var serviceLayerConfig = {
tag: softwareTag == '' && softwareBranch == '' ? version.release : softwareTag
components: './stamp/components'
applications: './stamp/applications'
experimental: './stamp/experimental'
}
}

Expand Down Expand Up @@ -416,6 +420,10 @@ var federatedIdentityCredentials = [
name: 'federated-ns_osdu-reference'
subject: 'system:serviceaccount:osdu-reference:workload-identity-sa'
}
{
name: 'federated-ns_osdu-experimental'
subject: 'system:serviceaccount:osdu-experimental:workload-identity-sa'
}
]

@batchSize(1)
Expand Down Expand Up @@ -532,6 +540,12 @@ var osdu_applications = [
contentType: 'text/plain'
label: 'configmap-osdu-applications'
}
{
name: 'adminUIEnabled'
value: toLower(string(enableAdminUI))
contentType: 'text/plain'
label: 'configmap-osdu-applications'
}
{
name: 'osduVersion'
value: toLower(string(osduVersion))
Expand Down Expand Up @@ -737,6 +751,16 @@ module fluxConfiguration 'br/public:avm/res/kubernetes-configuration/flux-config
retryIntervalInSeconds: 300
prune: true
}
experimental: {
path: serviceLayerConfig.gitops.experimental
dependsOn: [
'applications'
]
timeoutInSeconds: 300
syncIntervalInSeconds: 300
retryIntervalInSeconds: 300
prune: true
}
}
}
dependsOn: [
Expand Down
1 change: 1 addition & 0 deletions bicep/modules/script-share-csvdag/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ param insightsKey string
@description('Client Id for the service principal')
param clientId string

@secure()
@description('Client Secret for the service principal')
param clientSecret string

Expand Down
9 changes: 9 additions & 0 deletions charts/osdu-admin-ui/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v2
name: osdu-admin-ui
type: application
description: Installs the OSDU Admin UI
version: 0.0.1
appVersion: 0.0.1
maintainers:
- name: danielscholl
url: https://github.com/azure/osdu-developer
64 changes: 64 additions & 0 deletions charts/osdu-admin-ui/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "osdu-admin-ui.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 "osdu-admin-ui.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 "osdu-admin-ui.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "osdu-admin-ui.labels" -}}
helm.sh/chart: {{ include "osdu-admin-ui.chart" . }}
{{ include "osdu-admin-ui.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "osdu-admin-ui.selectorLabels" -}}
app.kubernetes.io/name: {{ include "osdu-admin-ui.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Determine if the installation is enabled
*/}}
{{- define "osdu-admin-ui.isEnabled" -}}
{{- if .Values.enabled }}
{{- true -}}
{{- else -}}
{{- false -}}
{{- end -}}
{{- end }}

29 changes: 29 additions & 0 deletions charts/osdu-admin-ui/templates/code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if (include "osdu-admin-ui.isEnabled" .) }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: environment-ts
namespace: {{ .Release.Namespace }}
data:
environment.ts: |
import json from '../config/config.json';
import { Environment } from './environment.model';
export const environment: Environment = json as Environment;
export const scopeProctedURLs: () => any = () => {
const splittedScopes = environment.settings.idp.scope.split(' ');
const osdu_api = Object.values(environment.settings.api_endpoints).map(
(url) => [url, splittedScopes]
);
const graphAPI = [
environment.settings.api_endpoints.graphAPI_endpoint,
['User.Read'],
];
return [...osdu_api, graphAPI];
};
{{- end }}
190 changes: 190 additions & 0 deletions charts/osdu-admin-ui/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{{- if (include "osdu-admin-ui.isEnabled" .) }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-build
namespace: {{ .Release.Namespace }}
spec:
ttlSecondsAfterFinished: 120
template:
spec:
serviceAccountName: workload-identity-sa
volumes:
- name: script
configMap:
name: admin-ui-build-script
defaultMode: 0500
- name: app-module-ts
configMap:
name: admin-ui-app-module-ts
defaultMode: 0500
- name: {{ .Release.Name }}-storage
persistentVolumeClaim:
claimName: {{ .Release.Name }}-pvc
- name: environment-ts
configMap:
name: environment-ts
initContainers:
- name: data-seed
image: mcr.microsoft.com/cbl-mariner/base/nodejs:18
command: ["/bin/sh"]
args:
- -c
- |
tdnf install -y curl jq tar && \
/script/init.sh
volumeMounts:
- name: script
mountPath: "/script"
- name: {{ .Release.Name }}-storage
mountPath: "/dist"
- name: environment-ts
mountPath: "/code/environment.ts"
subPath: environment.ts
env:
- name: APP_INSIGHTS
value: {{ .Values.insightsKey | quote }}
- name: AZURE_TENANT_ID
value: {{ .Values.tenantId | quote }}
- name: AZURE_CLIENT_ID
value: {{ .Values.clientId | quote }}
- name: DATA_DOMAIN
value: ".dataservices.energy"
- name: DATA_PARTITION
value: 'opendes'
- name: REDIRECT_URI
value: {{ .Values.redirectUri | quote }}
- name: URL
value: https://community.opengroup.org/osdu/ui/admin-ui-group/admin-ui-totalenergies/admin-ui-totalenergies/-/archive/main/admin-ui-totalenergies-main.tar.gz
- name: NODE_OPTIONS
value: "--max-old-space-size=4096"
resources:
requests:
memory: "4Gi"
cpu: "500m"
limits:
memory: "4Gi"
cpu: "1"
containers:
- name: sleep
image: istio/base
command: ["/bin/sleep", "30"]
volumeMounts:
- name: script
mountPath: "/script"
restartPolicy: Never
---
apiVersion: v1
kind: ConfigMap
metadata:
name: admin-ui-build-script
namespace: {{ .Release.Namespace }}
data:
init.sh: |
#!/usr/bin/env sh
set -euo pipefail
set -o nounset
echo "=================================================================="
echo " Installing Kubectl "
echo "=================================================================="
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
kubectl version --client
echo "=================================================================="
echo " Waiting for IstioGateway External IP "
echo "=================================================================="
SERVICE_NAME="istio-ingress-external"
NAMESPACE="istio-system"
while true; do
EXTERNAL_IP=$(kubectl get svc $SERVICE_NAME -n $NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
if [ -n "$EXTERNAL_IP" ]; then
echo "External IP is $EXTERNAL_IP"
break
else
echo "External IP not assigned yet. Retrying in 10 seconds..."
sleep 10
fi
done
echo "=================================================================="
echo " Downloading Admin UI Source Code "
echo "=================================================================="
url_basename=$(basename ${URL})
echo "Derived filename from URL: ${url_basename}"
# Download the file using curl
echo "Downloading file from ${URL} to ${url_basename}"
curl -so ${url_basename} ${URL}
# Extract the tar.gz file
mkdir -p extracted_files
tar -xzf ${url_basename} --strip-components=1 -C extracted_files
cd extracted_files/OSDUApp
# Install Packages
npm install -g @angular/cli && npm install && npm ci
# Copy custom Files
echo "Copying the custom code."
cp /code/environment.ts ./src/environments/environment.ts
cp providers/azure/routing.ts ./src/app/
cp src/config/config.azure.json ./src/config/config.json && rm src/config/config.*.json
# Remove trailing % from APP_INSIGHTS if present
APP_INSIGHTS=$(echo "$APP_INSIGHTS" | sed 's/%$//')
ENDPOINT=$(echo "http://$EXTERNAL_IP/api")
echo "APP_INSIGHTS: $APP_INSIGHTS"
echo "AZURE_CLIENT_ID: $AZURE_CLIENT_ID"
echo "DATA_DOMAIN: $DATA_DOMAIN"
echo "DATA_PARTITION: $DATA_PARTITION"
echo "AZURE_TENANT_ID: $AZURE_TENANT_ID"
echo "REDIRECT_URI: $REDIRECT_URI"
echo "ENDPOINT: $ENDPOINT"
# Perform JQ replace here
jq \
--arg client "$AZURE_CLIENT_ID" \
--arg domain "$DATA_DOMAIN" \
--arg partition "$DATA_PARTITION" \
--arg tenant "$AZURE_TENANT_ID" \
--arg redirect "$REDIRECT_URI" \
--arg endpoint "$ENDPOINT" \
'.settings.data_partition = $partition |
.settings.domain_name = $domain |
.settings.idp.tenant_id = $tenant |
.settings.idp.client_id = $client |
.settings.idp.scope = $client + "/.default" |
.settings.idp.redirect_uri = $redirect |
.settings.api_endpoints.entitlement_endpoint = $endpoint |
.settings.api_endpoints.storage_endpoint = $endpoint |
.settings.api_endpoints.search_endpoint = $endpoint |
.settings.api_endpoints.legal_endpoint = $endpoint |
.settings.api_endpoints.schema_endpoint = $endpoint |
.settings.api_endpoints.file_endpoint = $endpoint |
.settings.api_endpoints.graphAPI_endpoint = "https://graph.microsoft.com/v1.0/" |
.settings.api_endpoints.workflow_endpoint = $endpoint |
.settings.api_endpoints.secrets_endpoint = $endpoint |
.settings.api_endpoints.wddms_endpoint = $endpoint' \
src/config/config.json > src/config/tmp.json && mv src/config/tmp.json src/config/config.json
cat src/config/config.json
# Building Angular code
echo "Building Angular code."
ng build
# Copy to share
echo "Copying the build to the share."
# mkdir -p /dist/adminui
cp -r dist/OSDUApp/* /dist
exit 0
{{- end }}
Loading

0 comments on commit 3ea102c

Please sign in to comment.