-
Notifications
You must be signed in to change notification settings - Fork 4
Lighten container startup with replace script. #56
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,31 @@ | ||
# Use an official Node.js runtime as a parent image | ||
FROM node:slim | ||
|
||
# Define default values for environment variables | ||
ARG APP_TITLE="STAC Manager" | ||
ARG APP_DESCRIPTION="A web application for managing STAC catalogs" | ||
ARG REACT_APP_STAC_API="https://earth-search.aws.element84.com/v0" | ||
ARG REACT_APP_STAC_BROWSER="https://radiantearth.github.io/stac-browser" | ||
ARG PUBLIC_URL="http://127.0.0.1:8080" | ||
ENV REACT_APP_KEYCLOAK_URL= | ||
ENV REACT_APP_KEYCLOAK_CLIENT_ID= | ||
ENV REACT_APP_KEYCLOAK_REALM= | ||
|
||
ENV APP_TITLE=${APP_TITLE} | ||
ENV APP_DESCRIPTION=${APP_DESCRIPTION} | ||
ENV REACT_APP_STAC_API=${REACT_APP_STAC_API} | ||
ENV REACT_APP_STAC_BROWSER=${REACT_APP_STAC_BROWSER} | ||
ENV PUBLIC_URL=${PUBLIC_URL} | ||
ENV REACT_APP_KEYCLOAK_URL=${REACT_APP_KEYCLOAK_URL} | ||
ENV REACT_APP_KEYCLOAK_CLIENT_ID=${REACT_APP_KEYCLOAK_CLIENT_ID} | ||
ENV REACT_APP_KEYCLOAK_REALM=${REACT_APP_KEYCLOAK_REALM} | ||
|
||
# Set the working directory | ||
ARG APP_TITLE=%APP_TITLE% | ||
ARG APP_DESCRIPTION=%APP_DESCRIPTION% | ||
ARG PUBLIC_URL=%PUBLIC_URL% | ||
ARG REACT_APP_STAC_API=%REACT_APP_STAC_API% | ||
ARG REACT_APP_STAC_BROWSER=%REACT_APP_STAC_BROWSER% | ||
ARG REACT_APP_KEYCLOAK_URL=%REACT_APP_KEYCLOAK_URL% | ||
ARG REACT_APP_KEYCLOAK_CLIENT_ID=%REACT_APP_KEYCLOAK_CLIENT_ID% | ||
ARG REACT_APP_KEYCLOAK_REALM=%REACT_APP_KEYCLOAK_REALM% | ||
ARG REACT_APP_THEME_PRIMARY_COLOR=%REACT_APP_THEME_PRIMARY_COLOR% | ||
ARG REACT_APP_THEME_SECONDARY_COLOR=%REACT_APP_THEME_SECONDARY_COLOR% | ||
|
||
WORKDIR /app | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Install dependencies | ||
RUN npm i | ||
RUN npm i -g http-server | ||
RUN npm run all:build | ||
RUN cp -v packages/client/dist/index.html packages/client/dist/404.html | ||
|
||
# Create a start script that respects runtime environment variables | ||
RUN echo '#!/bin/sh\n\ | ||
echo "Starting build"\n\ | ||
npm run all:build\n\ | ||
echo "App built successfully"\n\ | ||
cp -v packages/client/dist/index.html packages/client/dist/404.html\n\ | ||
echo "Starting server"\n\ | ||
http-server -p 80 packages/client/dist' > /app/start.sh | ||
RUN apt-get update && apt-get install -y gettext-base sed | ||
|
||
RUN chmod +x /app/start.sh | ||
COPY docker-entrypoint.sh /app/docker-entrypoint.sh | ||
RUN chmod +x /app/docker-entrypoint.sh | ||
|
||
EXPOSE 80 | ||
|
||
ENTRYPOINT ["/app/start.sh"] | ||
ENTRYPOINT ["/app/docker-entrypoint.sh"] | ||
CMD ["http-server", "-p", "80", "packages/client/dist"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
echo "Startup script" | ||
echo "Replacing environment variables in built files..." | ||
|
||
# Replace placeholders with env vars or defaults only in the built files | ||
find /app/packages/client/dist -type f \( -name "*.html" -o -name "*.js" -o -name "*.css" -o -name "*.map" -o -name "*.json" \) | xargs sed -i \ | ||
-e "s|%APP_TITLE%|${APP_TITLE:-STAC Manager}|g" \ | ||
-e "s|%APP_DESCRIPTION%|${APP_DESCRIPTION:-A web application for managing STAC catalogs}|g" \ | ||
-e "s|%PUBLIC_URL%|${PUBLIC_URL:-http://127.0.0.1:8080}|g" \ | ||
-e "s|%REACT_APP_STAC_API%|${REACT_APP_STAC_API:-https://earth-search.aws.element84.com/v0}|g" \ | ||
-e "s|%REACT_APP_STAC_BROWSER%|${REACT_APP_STAC_BROWSER:-https://radiantearth.github.io/stac-browser/#/external/$(echo ${REACT_APP_STAC_API:-earth-search.aws.element84.com/v0} | sed 's|^https://||')}|g" \ | ||
-e "s|%REACT_APP_KEYCLOAK_URL%|${REACT_APP_KEYCLOAK_URL:-}|g" \ | ||
-e "s|%REACT_APP_KEYCLOAK_CLIENT_ID%|${REACT_APP_KEYCLOAK_CLIENT_ID:-}|g" \ | ||
-e "s|%REACT_APP_KEYCLOAK_REALM%|${REACT_APP_KEYCLOAK_REALM:-}|g" \ | ||
-e "s|%REACT_APP_THEME_PRIMARY_COLOR%|${REACT_APP_THEME_PRIMARY_COLOR:-}|g" \ | ||
-e "s|%REACT_APP_THEME_SECONDARY_COLOR%|${REACT_APP_THEME_SECONDARY_COLOR:-}|g" | ||
|
||
echo "Environment variable replacement complete" | ||
|
||
exec "$@" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.