diff --git a/Dockerfile.konflux b/Dockerfile.konflux deleted file mode 100644 index cdcaa8e7a..000000000 --- a/Dockerfile.konflux +++ /dev/null @@ -1,57 +0,0 @@ -FROM registry.redhat.io/ubi9/nodejs-18:latest AS web-builder - -WORKDIR /opt/app-root - -USER 0 - -ENV HUSKY=0 -COPY web/package*.json web/ -COPY Makefile Makefile -RUN make install-frontend-ci - -COPY web/ web/ -COPY config/ config/ -COPY scripts/update-plugin-name.sh scripts/update-plugin-name.sh -RUN make update-plugin-name -ENV I18N_NAMESPACE="plugin__monitoring-console-plugin" -RUN make build-frontend - -FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_9_1.22 as go-builder - -WORKDIR /opt/app-root - -COPY Makefile Makefile -COPY go.mod go.mod -COPY go.sum go.sum - -RUN make install-backend - -COPY cmd/ cmd/ -COPY pkg/ pkg/ - -ENV GOEXPERIMENT=strictfipsruntime -ENV CGO_ENABLED=1 - -RUN make build-backend BUILD_OPTS="-tags strictfipsruntime" - -FROM registry.redhat.io/rhel9-2-els/rhel:9.2 - -RUN mkdir /licenses -COPY LICENSE /licenses/. - -USER 1001 - -COPY --from=web-builder /opt/app-root/web/dist /opt/app-root/web/dist -COPY --from=web-builder /opt/app-root/config /opt/app-root/config -COPY --from=go-builder /opt/app-root/plugin-backend /opt/app-root - -ENTRYPOINT ["/opt/app-root/plugin-backend", "-static-path", "/opt/app-root/web/dist", "-config-path", "/opt/app-root/config"] - -LABEL com.redhat.component="coo-monitoring-console-plugin" \ - name="openshift/monitoring-console-plugin" \ - version="v0.3.0" \ - summary="OpenShift monitoring plugin to view and explore metrics and alerts" \ - io.openshift.tags="openshift,observability-ui,metrics,alerts" \ - io.k8s.display-name="OpenShift console monitoring plugin" \ - maintainer="Observability UI Team " \ - description="OpenShift monitoring plugin to view and explore metrics and alerts" diff --git a/Dockerfile.mcp b/Dockerfile.mcp index 22c8c1423..3c3b4515d 100644 --- a/Dockerfile.mcp +++ b/Dockerfile.mcp @@ -1,22 +1,17 @@ -# mcp (monitoring-console-plugin) - FROM registry.redhat.io/ubi9/nodejs-22:latest AS web-builder -USER 0 - WORKDIR /opt/app-root -ENV HUSKY=0 +USER 0 +ENV HUSKY=0 +COPY web/package*.json web/ COPY Makefile Makefile -COPY scripts/update-plugin-name.sh scripts/update-plugin-name.sh -COPY web/ web/ - -RUN make update-plugin-name - -ENV I18N_NAMESPACE="plugin__monitoring-console-plugin" +RUN make install-frontend-ci -RUN make install-frontend +COPY web/ web/ +COPY config/ config/ +ENV CONSOLE_PLUGIN_NAME="monitoring-console-plugin" RUN make build-frontend FROM registry.access.redhat.com/ubi9/go-toolset:1.26 AS go-builder @@ -27,20 +22,28 @@ COPY Makefile Makefile COPY go.mod go.mod COPY go.sum go.sum -RUN go mod download +RUN make install-backend COPY cmd/ cmd/ COPY pkg/ pkg/ -RUN go build -mod=mod -o plugin-backend cmd/plugin-backend.go +ENV GOOS=${TARGETOS:-linux} +ENV GOARCH=${TARGETARCH} +ENV GOEXPERIMENT=strictfipsruntime +ENV GOFLAGS=-mod=readonly +ENV CGO_ENABLED=1 + +RUN make build-backend FROM registry.access.redhat.com/ubi9/ubi-minimal +RUN mkdir /licenses +COPY LICENSE /licenses/. + USER 1001 COPY --from=web-builder /opt/app-root/web/dist /opt/app-root/web/dist -COPY --from=web-builder /opt/app-root/web/package.json /opt/app-root/web/package.json COPY --from=go-builder /opt/app-root/plugin-backend /opt/app-root -COPY config/ /opt/app-root/config +COPY --from=web-builder /opt/app-root/config /opt/app-root/config -ENTRYPOINT ["/opt/app-root/plugin-backend", "-static-path", "/opt/app-root/web/dist", "-config-path", "/opt/app-root/config"] +ENTRYPOINT ["/opt/app-root/plugin-backend", "-static-path", "/opt/app-root/web/dist"] diff --git a/Makefile b/Makefile index 7f1b2c264..3fafec6b3 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PLATFORMS ?= linux/arm64,linux/amd64 ORG ?= openshift-observability-ui PLUGIN_NAME ?= monitoring-plugin IMAGE ?= quay.io/${ORG}/${PLUGIN_NAME}:${VERSION} -FEATURES ?= incidents,perses-dashboards,dev-config +FEATURES ?= cluster-health-analyzer,perses-dashboards,dev-config .PHONY: install-frontend install-frontend: @@ -11,7 +11,7 @@ install-frontend: .PHONY: install-frontend-ci install-frontend-ci: - cd web && npm ci --omit=optional --ignore-scripts + cd web && npm ci --ignore-scripts .PHONY: install-frontend-ci-clean install-frontend-ci-clean: install-frontend-ci @@ -53,7 +53,7 @@ build-backend: .PHONY: start-backend start-backend: - go run ./cmd/plugin-backend.go -port='9001' -config-path='./config' -static-path='./web/dist' + go run ./cmd/plugin-backend.go -port='9443' -config-path='./config' -static-path='./web/dist' .PHONY: build-image build-image: @@ -64,10 +64,6 @@ build-image: install: make install-frontend && make install-backend -.PHONY: update-plugin-name -update-plugin-name: - ./scripts/update-plugin-name.sh - .PHONY: deploy deploy: make lint-backend @@ -83,10 +79,6 @@ deploy-acm: build-mcp-image: DOCKER_FILE_NAME="Dockerfile.mcp" scripts/build-image.sh -.PHONY: start-feature-console -start-feature-console: - PLUGIN_PORT=9443 ./scripts/start-console.sh - .PHONY: start-feature-backend start-feature-backend: go run ./cmd/plugin-backend.go -port='9443' -config-path='./config' -static-path='./web/dist' -features='$(FEATURES)' diff --git a/README.md b/README.md index 0d900f135..b62585439 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,12 @@ $ podman machine start # Install dependencies $ make install -# Run the application +# Run the frontend $ make start-frontend # In a separate terminal +# Run the backend +$ make start-backend +# In a separate terminal $ make start-console ``` @@ -94,12 +97,13 @@ The application will be running at [localhost:9000](http://localhost:9000/). ## monitoring-console-plugin (mcp) ### Dependencies + 1. [Local Development Dependencies](README#Dependencies) 2. [yq](https://github.com/mikefarah/yq) for acm deployment 3. sed ([gnu-sed](https://formulae.brew.sh/formula/gnu-sed) for mac, with sed being aliased to that gnu-sed) - ### Building an image + Images for the mcp can be built by running the following command. Due to the limitation of linux/amd64 image builds on Apple Silicon Macs's, some of the changes are run locally and not just in the Dockerfiles. If you are on a Mac, it is not suggested to cancel the exection of this scipt part way through ```bash @@ -111,10 +115,9 @@ make build-mcp-image Feature flags are used by the mcp mode to dictate the specific features which are enabled when the server starts up. Feature flags should be added to the Feature enum [here](pkg/server.go) and to the useFeature hook [here](web/src/components/hooks/useFeatures.ts). When any feature flag is enabled the default extension points are overridden, including a new monitoring-console-plugin exclusive redux store and all extension points for the flags. These feature extension points are created through the use of [json-patches](https://datatracker.ietf.org/doc/html/rfc6902), such as the `acm-alerting` patch [here](config/acm-alerting.patch.json). The server looks for a patch in the format of `{feature-flag-name}.patch.json` to apply. | Feature | OCP Version | -|-------------------|-------------| +| ----------------- | ----------- | | acm-alerting | 4.14+ | | perses-dashboards | 4.14+ | -| incidents | 4.19+ | | dev-config | | #### ACM @@ -137,7 +140,7 @@ Since the store for the `monitoring-plugin` is stored in the `openshift/console` # Login to an OpenShift cluster $ oc login -u -p -# Start podman (or Docker) +# Start podman (or Docker) - Linux machines can skip this part $ podman machine init $ podman machine start diff --git a/scripts/start-console.sh b/scripts/start-console.sh index 1b87237ed..cc60d1226 100755 --- a/scripts/start-console.sh +++ b/scripts/start-console.sh @@ -4,9 +4,9 @@ set -euo pipefail CONSOLE_IMAGE=${CONSOLE_IMAGE:="quay.io/openshift/origin-console:latest"} CONSOLE_PORT=${CONSOLE_PORT:=9000} -PLUGIN_PORT=${PLUGIN_PORT:=9001} +PLUGIN_PORT=${PLUGIN_PORT:=9443} CONSOLE_IMAGE_PLATFORM=${CONSOLE_IMAGE_PLATFORM:="linux/amd64"} -npm_package_consolePlugin_name=${npm_package_consolePlugin_name:="monitoring-plugin"} +npm_package_consolePlugin_name=${CONSOLE_PLUGIN_NAME:-"monitoring-plugin"} echo "Starting local OpenShift console..." @@ -19,6 +19,7 @@ BRIDGE_K8S_MODE_OFF_CLUSTER_THANOS=$(oc -n openshift-config-managed get configma BRIDGE_K8S_MODE_OFF_CLUSTER_ALERTMANAGER=$(oc -n openshift-config-managed get configmap monitoring-shared-config -o jsonpath='{.data.alertmanagerPublicURL}') BRIDGE_K8S_AUTH_BEARER_TOKEN=$(oc whoami --show-token 2>/dev/null) BRIDGE_USER_SETTINGS_LOCATION="localstorage" +BRIDGE_I18N_NAMESPACES="plugin__${npm_package_consolePlugin_name}" echo "API Server: $BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT" echo "Console Image: $CONSOLE_IMAGE" diff --git a/scripts/update-plugin-name.sh b/scripts/update-plugin-name.sh deleted file mode 100755 index 55cdb68a1..000000000 --- a/scripts/update-plugin-name.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - - -# Replace the plugin name in the package.json for the custom build actions -sed -i 's/"name": "monitoring-plugin",/"name": "monitoring-console-plugin",/g' web/package.json - -# Rename the translation files to the correct plugin -cd web/locales/ && for dir in *; do if cd $dir; then for filename in *; do mv plugin__monitoring-plugin.json plugin__monitoring-console-plugin.json; done; cd ..; fi; done && cd ../.. diff --git a/web/webpack.config.ts b/web/webpack.config.ts index 7515729c8..e4a3d1872 100644 --- a/web/webpack.config.ts +++ b/web/webpack.config.ts @@ -5,6 +5,7 @@ import { DefinePlugin, Configuration as WebpackConfiguration } from 'webpack'; import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server'; import * as path from 'path'; import { ConsoleRemotePlugin } from '@openshift-console/dynamic-plugin-sdk-webpack'; +import pkg from './package.json'; interface Configuration extends WebpackConfiguration { devServer?: WebpackDevServerConfiguration; @@ -82,17 +83,38 @@ const config: Configuration = { }, plugins: [ new ConsoleRemotePlugin({ + pluginMetadata: process.env.CONSOLE_PLUGIN_NAME + ? { ...pkg.consolePlugin, name: process.env.CONSOLE_PLUGIN_NAME } + : undefined, validateExtensionIntegrity: false, }), new CopyWebpackPlugin({ - patterns: [{ from: path.resolve(__dirname, 'locales'), to: 'locales' }], + patterns: [ + { + from: path.resolve(__dirname, 'locales'), + to({ absoluteFilename }) { + if (!absoluteFilename) { + return 'locales/[path][name][ext]'; + } + const i18nNamespace = `plugin__${process.env.CONSOLE_PLUGIN_NAME ?? 'monitoring-plugin'}`; + const relativePath = path.relative( + path.resolve(__dirname, 'locales'), + absoluteFilename, + ); + return path.join( + 'locales', + relativePath.replace('plugin__monitoring-plugin', i18nNamespace), + ); + }, + }, + ], }), new DefinePlugin({ // Build-time injection of proxy path for config module PERSES_PROXY_BASE_URL: JSON.stringify('/api/proxy/plugin/monitoring-console-plugin/perses'), - 'process.env.I18N_NAMESPACE': process.env.I18N_NAMESPACE - ? JSON.stringify(process.env.I18N_NAMESPACE) - : JSON.stringify('plugin__monitoring-plugin'), + 'process.env.I18N_NAMESPACE': JSON.stringify( + `plugin__${process.env.CONSOLE_PLUGIN_NAME ?? 'monitoring-plugin'}`, + ), }), ], devtool: 'source-map',