Skip to content

Commit

Permalink
feat(config): add support for runtime-defined env vars for rekor endp…
Browse files Browse the repository at this point in the history
…oint (#37)
  • Loading branch information
lance authored Mar 18, 2024
2 parents bf9d551 + d08b374 commit 7273f47
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cronjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on:
workflow_dispatch:
schedule:
# Every M-F at 12:00am run this job
- cron: "0 0 * * 1-5"
- cron: "0 0 * * 1-5"

jobs:
check-image-version:
uses: securesign/actions/.github/workflows/check-image-version.yaml@main
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
FROM registry.access.redhat.com/ubi9/nodejs-18@sha256:773645c3eae02529e09c04a843a0c6783de45b084b325685b043b7818c7a8bf6 as Build
#
COPY . .
USER root
USER root
ENV NODE_ENV production
EXPOSE 3000
RUN echo "export PATH=${PATH}:$HOME/node_modules/.bin" >> ~/.bashrc && \
npm install --ignore-scripts && \
npm run build && \
chmod -R 777 /opt/app-root/src/.npm && \
echo "NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN = ${NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN}" && \
npm cache clean --force
USER 1001
CMD ["npm", "run", "start"]
CMD ["node_modules/.bin/next", "start"]

LABEL \
com.redhat.component="trusted-artifact-signer-rekor-ui" \
name="trusted-artifact-signer-rekor-ui" \
version="0.0.1" \
summary="User Interface for checking Rekor Entries" \
description="Provides a user interface for checking Rekor Entries through an Node App" \
io.k8s.description="Provides a user interface for checking Rekor Entries through an Node App" \
io.k8s.display-name="Provides a user interface for checking Rekor Entries through an Node App" \
description="Provides a user interface for checking Rekor Entries through a Node App" \
io.k8s.description="Provides a user interface for checking Rekor Entries through a Node App" \
io.k8s.display-name="Provides a user interface for checking Rekor Entries through a Node App" \
io.openshift.tags="rekor-ui, rekor, cli, rhtas, trusted, artifact, signer, sigstore" \
maintainer="[email protected]"
14 changes: 13 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
transpilePackages: ["@patternfly/react-core", "@patternfly/react-styles"],
publicRuntimeConfig: {
// remove private env variables
processEnv: Object.fromEntries(
Object.entries(process.env).filter(([key]) =>
key.includes("NEXT_PUBLIC_"),
),
),
},
transpilePackages: [
"@patternfly/react-core",
"@patternfly/react-icons",
"@patternfly/react-styles",
],
};

module.exports = nextConfig;
20 changes: 20 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import Document, { Head, Html, Main, NextScript } from "next/document";

const nextPublicENV = Object.keys(process.env)
.filter(key => key.startsWith("NEXT_PUBLIC_"))
.reduce(
(env, key) => {
env[key] = process.env[key] ?? "";
return env;
},
{} as { [key: string]: string },
);

class AppDocument extends Document {
render() {
return (
<Html lang="en">
<Head></Head>
<script
dangerouslySetInnerHTML={{
__html: `
console.table(${JSON.stringify(nextPublicENV)});
window.process = window.process || {};
window.process.env = window.process.env || {};
Object.assign(window.process.env, ${JSON.stringify(nextPublicENV)});
`,
}}
></script>
<body>
<Main />
<NextScript />
Expand Down
11 changes: 10 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { RekorClientProvider } from "../modules/api/context";
import { Explorer } from "../modules/components/Explorer";
import { Settings } from "../modules/components/Settings";
import { CogIcon, GithubIcon } from "@patternfly/react-icons";
import { CogIcon } from "@patternfly/react-icons";
import Link from "next/link";
import Image from "next/image";
import NOSSRWrapper from "../modules/utils/noSSR";
Expand Down Expand Up @@ -112,3 +112,12 @@ const PageComponent: NextPage = () => (
</RekorClientProvider>
);
export default PageComponent;

export async function getServerSideProps() {
return {
props: {
NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN:
process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN,
}, // will be passed to the page component as props
};
}

0 comments on commit 7273f47

Please sign in to comment.