-
-
Notifications
You must be signed in to change notification settings - Fork 132
feat: add support for configuring the base URL #248
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,32 @@ | ||
| # Use a UUID as placeholder value to have a unique string to replace. | ||
| ARG BASE_URL_PLACEHOLDER=189b303e-37a0-4f6f-8c0a-50333bc3c36e | ||
|
|
||
| FROM docker.io/library/node:16.13.2 as build | ||
|
|
||
| ARG BASE_URL_PLACEHOLDER | ||
|
|
||
| COPY package.json package-lock.json ./ | ||
| RUN npm install --frozen-lockfile | ||
|
|
||
| COPY ./ ./ | ||
|
Comment on lines
+8
to
11
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why these commands are split? What we have benefit here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a common optimization to speed up Docker builds. It will cache the result of |
||
| RUN npm install && npm run build | ||
| # Set the React PUBLIC_URL to our placeholder value so that | ||
| # that it can easily be replaced with the actual base URL | ||
| # in the entrypoint script below. | ||
| RUN PUBLIC_URL=${BASE_URL_PLACEHOLDER} npm run build | ||
|
|
||
| FROM docker.io/library/nginx:1.21.5-alpine as runtime | ||
|
|
||
| ARG BASE_URL_PLACEHOLDER | ||
| # The base Nginx image automatically executes all shell scripts | ||
| # within the /docker-entrypoint.d/ directory ("entrypoint scripts") | ||
| # when the container is started. See the relevant logic at | ||
| # https://github.com/nginxinc/docker-nginx/blob/master/entrypoint/docker-entrypoint.sh#L16. | ||
| ARG ENTRYPOINT_SCRIPT=/docker-entrypoint.d/set-public-url.sh | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add info about
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sure! I added a comment! |
||
|
|
||
| FROM docker.io/library/nginx:1.21.5-alpine | ||
| COPY --from=build /build /usr/share/nginx/html/ | ||
| # Add an entrypoint script that replaces all occurences of the | ||
| # placeholder value by the configured base URL. If no base URL | ||
| # is configured we assume the application is running at '/'. | ||
| RUN echo "find /usr/share/nginx/html/ -type f -print0 | xargs -0 sed -i \"s|${BASE_URL_PLACEHOLDER}|\${BASE_URL}|g\"" > $ENTRYPOINT_SCRIPT && chmod +x $ENTRYPOINT_SCRIPT | ||
|
|
||
| FROM runtime | ||
Uh oh!
There was an error while loading. Please reload this page.