diff --git a/.gitignore b/.gitignore index d7e2d1afe5aeac58d64ef2e5c0f117ccb318eae6..039d21a5909ef814d8d3e484a8ada4d22088c5b0 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,5 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + +config diff --git a/helm/manifest-service/templates/configMap.yaml b/helm/manifest-service/templates/configMap.yaml index a727d17f0e7ef4d01661c004ceb91f475e9088ba..5724af4db3be6303d87748ef420eae8c6406a3ad 100644 --- a/helm/manifest-service/templates/configMap.yaml +++ b/helm/manifest-service/templates/configMap.yaml @@ -1,8 +1,8 @@ -{{- if .Values.environment.manifestUrls }} apiVersion: v1 kind: ConfigMap metadata: name: {{ include "manifest-service.fullname" . }} data: - manifest_urls: {{ join "," .Values.environment.manifestUrls }} -{{- end }} + urls.yaml: | + manifests: + {{ .Values.manifests | toYaml }} diff --git a/helm/manifest-service/templates/deployment.yaml b/helm/manifest-service/templates/deployment.yaml index a9cac00e1b7fde7002a3f1274dce723649120aa3..e50bec79bf585cdbb759416fd0f6c357601f79ec 100644 --- a/helm/manifest-service/templates/deployment.yaml +++ b/helm/manifest-service/templates/deployment.yaml @@ -33,14 +33,6 @@ spec: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} - {{- if .Values.environment.manifestUrls }} - env: - - name: MANIFEST_URLS - valueFrom: - configMapKeyRef: - name: {{ include "manifest-service.fullname" . }} - key: manifest_urls - {{- end }} ports: - name: http containerPort: {{ .Values.containerPort | default 8080 }} @@ -55,7 +47,14 @@ spec: port: http resources: {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: manifest-config + mountPath: /app/config/manifests {{- with .Values.nodeSelector }} + volumes: + - name: manifest-config + configMap: + name: {{ include "manifest-service.fullname" . }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} diff --git a/helm/values/develop.yaml b/helm/values/develop.yaml index df3116bd89d0c26a1a2c39406a4b642f8da29e0e..6d9809eec6568b81e500debd82550c9ce1328ee5 100644 --- a/helm/values/develop.yaml +++ b/helm/values/develop.yaml @@ -1,7 +1,8 @@ replicaCount: 1 containerPort: 8080 -environment: - manifestUrls: +manifests: + - https://manifest-service-dummy.k3s.os.oxui.de/manifest.json + - https://manifest-service-dummy.k3s.os.oxui.de/manifest.json ingress: enabled: true hosts: diff --git a/index.js b/index.js index cfee10a3bb1d580e7ce0d92631ed0e26e0a9bab5..9bc755148159751c600cc5a4b37ba917df86a280 100644 --- a/index.js +++ b/index.js @@ -44,30 +44,25 @@ app.use(apiMetrics({ excludeRoutes: ignorePaths })) app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)) app.use('/swagger.json', (req, res) => res.json(swaggerDocument)) -const urls = (process.env.MANIFEST_URLS || '').split(',').map(url => url + '/manifest.json') +const urls = yaml.load(fs.readFileSync('./config/manifests/url.yaml', 'utf8')).manifests -// Specific routes -app.get(['/', '/api/manifest.json'], async (req, res) => { - const content = await getManifest(urls) - res.json(content || []) +app.get('/api/manifest.json', async (req, res, next) => { + try { + const results = urls.map(url => fetch(url).then(res => { + if (!res.ok) throw new Error(`Failed to load manifest for url ${res.url} (Status: ${res.status}: ${res.statusText})`) + return res.json().catch(err => { throw new Error(`Failed to load manifest for url ${res.url}: ${err}`) }) + })) + const content = await Promise.all(results) + res.json(content.flat() || []) + } catch (err) { + next(err) + } }) -// collect manifest files from different services and merge them into a single file -async function getManifest (urls) { - return await Promise.all( - urls.map(url => fetch(url).then(res => { - if (!res.ok) { - throw new Error(`Failed to load manifest for url ${res.url} (Status: ${res.status}: ${res.statusText})`) - } - return res.json().catch(err => { - throw new Error(`Failed to load manifest for url ${res.url}: ${err}`) - }) - }).catch((err) => { - logger.error(err) - return [] - })) - ).then(urls => urls.flat()) -} +app.use(function (err, req, res, next) { + logger.error(err) + res.status(500).end() +}) // Binds and listens for connections on the specified host and port app.listen(process.env.PORT, () => {