Skip to content
Snippets Groups Projects
Commit 1664a51a authored by anne.matthes's avatar anne.matthes
Browse files

Refactoring

parent 7c4adee4
No related branches found
No related tags found
No related merge requests found
......@@ -115,3 +115,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
config
{{- 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 }}
......@@ -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 }}
......
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:
......
......@@ -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, () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment