Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make URL of sourcify server and repository configurable #21

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY --chown=node:node . ./

# Set npm timeout for slow network
RUN npm config set fetch-retry-mintimeout 20000
RUN npm config set fetch-retry-maxtimeout 120000

RUN npm install
RUN npm run build

FROM nginx:alpine
COPY --from=builder /home/node/app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Copy entrypoint
COPY ui-entrypoint.sh /docker-entrypoint.d/
RUN chmod +x /docker-entrypoint.d/ui-entrypoint.sh

6 changes: 6 additions & 0 deletions ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>sourcify.eth</title>
<script>
// CONFIGURATION_PLACEHOLDER
// This comment will be removed at build time. The Docker entrypoint will
// look for this empty script element and insert the definition of configuration
// parameter(s) passed via the global window object.
</script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
21 changes: 19 additions & 2 deletions ui/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
declare global {
interface Window {
// adding custom properties
configs: {
REPOSITORY_SERVER_URL: string,
SERVER_URL: string,
}
}
}

export const REPOSITORY_SERVER_URL =
process.env.REACT_APP_REPOSITORY_SERVER_URL;
export const SERVER_URL = process.env.REACT_APP_SERVER_URL;
window.configs?.REPOSITORY_SERVER_URL?.length > 0
? window.configs.REPOSITORY_SERVER_URL
: process.env.REACT_APP_REPOSITORY_SERVER_URL

export const SERVER_URL =
window.configs?.SERVER_URL?.length > 0
? window.configs.SERVER_URL
: process.env.REACT_APP_SERVER_URL

export const DOCS_URL = "https://docs.hedera.com";
export const PLAYGROUND_URL = "https://playground.sourcify.dev";
export const HASHSCAN_URL = "https://hashscan-latest.hedera-devops.com/"
Expand Down
7 changes: 7 additions & 0 deletions ui/ui-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Patch index.html to insert config parameter in the global window object
sed -i "s@<script></script>@<script>window.configs={SERVER_URL:\"${SERVER_URL}\",REPOSITORY_SERVER_URL:\"${REPOSITORY_SERVER_URL}\"}</script>@" /usr/share/nginx/html/index.html

# Start nginx
nginx -g "daemon off;"