added script to build frontend so it can add version info to the index.html file w/ burnettk

This commit is contained in:
jasquat 2023-04-11 15:48:34 -04:00
parent 79a0505ddb
commit f00b2e9f7d
7 changed files with 26 additions and 18 deletions

View File

@ -66,7 +66,7 @@ jobs:
- name: Write app version info
working-directory: spiffworkflow-frontend
run: echo $DOCKER_METADATA_OUTPUT_JSON | jq '.labels' > app_version.json
run: echo $DOCKER_METADATA_OUTPUT_JSON | jq '.labels' > version_info.json
- name: Build and push Frontend Docker image
uses: docker/build-push-action@v4.0.0
with:
@ -110,7 +110,7 @@ jobs:
- name: Write app version info
working-directory: spiffworkflow-backend
run: echo $DOCKER_METADATA_OUTPUT_JSON | jq '.labels' > app_version.json
run: echo $DOCKER_METADATA_OUTPUT_JSON | jq '.labels' > version_info.json
- name: Build and push Backend Docker image
uses: docker/build-push-action@v4.0.0
with:

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ t
*~
.dccache
*~
app_version.json
version_info.json

View File

@ -188,13 +188,13 @@ def create_app() -> flask.app.Flask:
def _setup_prometheus_metrics(app: flask.app.Flask, connexion_app: connexion.apps.flask_app.FlaskApp) -> None:
metrics = ConnexionPrometheusMetrics(connexion_app)
app.config["PROMETHEUS_METRICS"] = metrics
if os.path.isfile("app_version.json"):
app_version_data = {}
with open("app_version.json") as f:
app_version_data = json.load(f)
if os.path.isfile("version_info.json"):
version_info_data = {}
with open("version_info.json") as f:
version_info_data = json.load(f)
# prometheus does not allow periods in key names
app_version_data_normalized = {k.replace(".", "_"): v for k, v in app_version_data.items()}
metrics.info("app_version_info", "Application Version Info", **app_version_data_normalized)
version_info_data_normalized = {k.replace(".", "_"): v for k, v in version_info_data.items()}
metrics.info("version_info", "Application Version Info", **version_info_data_normalized)
def get_hacked_up_app_for_script() -> flask.app.Flask:

View File

@ -24,7 +24,7 @@ RUN cp /app/package.json.bak /app/package.json
# npx can-i-ignore-scripts can check that it's safe to ignore scripts.
RUN npm ci --ignore-scripts
RUN npm run build
RUN ./bin/build
# Final image without setup dependencies.
FROM base AS final
@ -39,6 +39,4 @@ COPY --from=setup /app/build /app/build
COPY --from=setup /app/bin /app/bin
COPY --from=setup /app/node_modules.justserve /app/node_modules
ENV REACT_APP_VERSION_INFO="123"
ENTRYPOINT ["/app/bin/boot_server_in_docker"]

View File

@ -7,11 +7,6 @@ function error_handler() {
trap 'error_handler ${LINENO} $?' ERR
set -o errtrace -o errexit -o nounset -o pipefail
if [[ -f app_version.json ]]; then
SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_REACT_APP_VERSION_INFO_JSON=$(cat app_version.json)
export SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_REACT_APP_VERSION_INFO_JSON
fi
# sort of like https://lithic.tech/blog/2020-05/react-dynamic-config, but without golang
react_configs=$(env | grep -E "^SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_" || echo '')
if [[ -n "$react_configs" ]]; then

View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
function error_handler() {
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
exit "$2"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errtrace -o errexit -o nounset -o pipefail
if [[ -f "version_info.json" ]]; then
version_info=$(cat version_info.json)
export REACT_APP_VERSION_INFO="$version_info"
fi
npm run build

View File

@ -5,7 +5,7 @@
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="version-info" content="%REACT_APP_VERSION_INFO%" />
<meta name="version-info" content='%REACT_APP_VERSION_INFO%' />
<meta
name="description"
content="A turnkey solution for building and executing the workflows that drive your business"