From f00b2e9f7d6ac9ed34de405f0585acbfc686dbe3 Mon Sep 17 00:00:00 2001 From: jasquat Date: Tue, 11 Apr 2023 15:48:34 -0400 Subject: [PATCH] added script to build frontend so it can add version info to the index.html file w/ burnettk --- .../workflows/docker_image_for_main_builds.yml | 4 ++-- .gitignore | 2 +- .../src/spiffworkflow_backend/__init__.py | 12 ++++++------ spiffworkflow-frontend/Dockerfile | 4 +--- spiffworkflow-frontend/bin/boot_server_in_docker | 5 ----- spiffworkflow-frontend/bin/build | 15 +++++++++++++++ spiffworkflow-frontend/public/index.html | 2 +- 7 files changed, 26 insertions(+), 18 deletions(-) create mode 100755 spiffworkflow-frontend/bin/build diff --git a/.github/workflows/docker_image_for_main_builds.yml b/.github/workflows/docker_image_for_main_builds.yml index 0b3964c41..f485a313b 100644 --- a/.github/workflows/docker_image_for_main_builds.yml +++ b/.github/workflows/docker_image_for_main_builds.yml @@ -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: diff --git a/.gitignore b/.gitignore index da7c98672..f49bfbb71 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ t *~ .dccache *~ -app_version.json +version_info.json diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py index aa1989600..72355fe97 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py @@ -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: diff --git a/spiffworkflow-frontend/Dockerfile b/spiffworkflow-frontend/Dockerfile index abdb4363d..653503746 100644 --- a/spiffworkflow-frontend/Dockerfile +++ b/spiffworkflow-frontend/Dockerfile @@ -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"] diff --git a/spiffworkflow-frontend/bin/boot_server_in_docker b/spiffworkflow-frontend/bin/boot_server_in_docker index 74fcb49f9..9cb998652 100755 --- a/spiffworkflow-frontend/bin/boot_server_in_docker +++ b/spiffworkflow-frontend/bin/boot_server_in_docker @@ -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 diff --git a/spiffworkflow-frontend/bin/build b/spiffworkflow-frontend/bin/build new file mode 100755 index 000000000..4dcb0c276 --- /dev/null +++ b/spiffworkflow-frontend/bin/build @@ -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 diff --git a/spiffworkflow-frontend/public/index.html b/spiffworkflow-frontend/public/index.html index 09516d942..d5ee9bd9e 100644 --- a/spiffworkflow-frontend/public/index.html +++ b/spiffworkflow-frontend/public/index.html @@ -5,7 +5,7 @@ - +