Skip to content

Commit 7273f47

Browse files
authored
feat(config): add support for runtime-defined env vars for rekor endpoint (#37)
2 parents bf9d551 + d08b374 commit 7273f47

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

.github/workflows/cronjobs.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ on:
33
workflow_dispatch:
44
schedule:
55
# Every M-F at 12:00am run this job
6-
- cron: "0 0 * * 1-5"
7-
6+
- cron: "0 0 * * 1-5"
7+
88
jobs:
99
check-image-version:
1010
uses: securesign/actions/.github/workflows/check-image-version.yaml@main

Dockerfile

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
FROM registry.access.redhat.com/ubi9/nodejs-18@sha256:773645c3eae02529e09c04a843a0c6783de45b084b325685b043b7818c7a8bf6 as Build
22
#
33
COPY . .
4-
USER root
4+
USER root
5+
ENV NODE_ENV production
56
EXPOSE 3000
67
RUN echo "export PATH=${PATH}:$HOME/node_modules/.bin" >> ~/.bashrc && \
78
npm install --ignore-scripts && \
89
npm run build && \
910
chmod -R 777 /opt/app-root/src/.npm && \
11+
echo "NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN = ${NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN}" && \
1012
npm cache clean --force
1113
USER 1001
12-
CMD ["npm", "run", "start"]
14+
CMD ["node_modules/.bin/next", "start"]
1315

1416
LABEL \
1517
com.redhat.component="trusted-artifact-signer-rekor-ui" \
1618
name="trusted-artifact-signer-rekor-ui" \
1719
version="0.0.1" \
1820
summary="User Interface for checking Rekor Entries" \
19-
description="Provides a user interface for checking Rekor Entries through an Node App" \
20-
io.k8s.description="Provides a user interface for checking Rekor Entries through an Node App" \
21-
io.k8s.display-name="Provides a user interface for checking Rekor Entries through an Node App" \
21+
description="Provides a user interface for checking Rekor Entries through a Node App" \
22+
io.k8s.description="Provides a user interface for checking Rekor Entries through a Node App" \
23+
io.k8s.display-name="Provides a user interface for checking Rekor Entries through a Node App" \
2224
io.openshift.tags="rekor-ui, rekor, cli, rhtas, trusted, artifact, signer, sigstore" \
2325
maintainer="trusted-artifact-signer@redhat.com"

next.config.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
33
reactStrictMode: true,
4-
transpilePackages: ["@patternfly/react-core", "@patternfly/react-styles"],
4+
publicRuntimeConfig: {
5+
// remove private env variables
6+
processEnv: Object.fromEntries(
7+
Object.entries(process.env).filter(([key]) =>
8+
key.includes("NEXT_PUBLIC_"),
9+
),
10+
),
11+
},
12+
transpilePackages: [
13+
"@patternfly/react-core",
14+
"@patternfly/react-icons",
15+
"@patternfly/react-styles",
16+
],
517
};
618

719
module.exports = nextConfig;

src/pages/_document.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
import Document, { Head, Html, Main, NextScript } from "next/document";
22

3+
const nextPublicENV = Object.keys(process.env)
4+
.filter(key => key.startsWith("NEXT_PUBLIC_"))
5+
.reduce(
6+
(env, key) => {
7+
env[key] = process.env[key] ?? "";
8+
return env;
9+
},
10+
{} as { [key: string]: string },
11+
);
12+
313
class AppDocument extends Document {
414
render() {
515
return (
616
<Html lang="en">
717
<Head></Head>
18+
<script
19+
dangerouslySetInnerHTML={{
20+
__html: `
21+
console.table(${JSON.stringify(nextPublicENV)});
22+
window.process = window.process || {};
23+
window.process.env = window.process.env || {};
24+
Object.assign(window.process.env, ${JSON.stringify(nextPublicENV)});
25+
`,
26+
}}
27+
></script>
828
<body>
929
<Main />
1030
<NextScript />

src/pages/index.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { RekorClientProvider } from "../modules/api/context";
1919
import { Explorer } from "../modules/components/Explorer";
2020
import { Settings } from "../modules/components/Settings";
21-
import { CogIcon, GithubIcon } from "@patternfly/react-icons";
21+
import { CogIcon } from "@patternfly/react-icons";
2222
import Link from "next/link";
2323
import Image from "next/image";
2424
import NOSSRWrapper from "../modules/utils/noSSR";
@@ -112,3 +112,12 @@ const PageComponent: NextPage = () => (
112112
</RekorClientProvider>
113113
);
114114
export default PageComponent;
115+
116+
export async function getServerSideProps() {
117+
return {
118+
props: {
119+
NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN:
120+
process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN,
121+
}, // will be passed to the page component as props
122+
};
123+
}

0 commit comments

Comments
 (0)