From 16b156bf667f0e4c47347b578e6e0ce80888e10a Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Fri, 28 Jul 2023 18:26:20 +0200 Subject: [PATCH] HMS-2678 feat: frontend container Add a poc to try to build the frontend container locally, and check if it could be deployed in ephemeral environment. Signed-off-by: Alejandro Visiedo --- build/package/Caddyfile | 64 +++++++++++++++++++++++++++++++++++ build/package/Dockerfile | 39 +++++++++++++++++++++ build/package/gen.app.info.sh | 47 +++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 build/package/Caddyfile create mode 100644 build/package/Dockerfile create mode 100755 build/package/gen.app.info.sh diff --git a/build/package/Caddyfile b/build/package/Caddyfile new file mode 100644 index 0000000..82030cb --- /dev/null +++ b/build/package/Caddyfile @@ -0,0 +1,64 @@ +{ + {$CADDY_TLS_MODE} + auto_https disable_redirects + servers { + metrics + } +} + +:9000 { + metrics /metrics +} + +:8000 { + {$CADDY_TLS_CERT} + log + + # Handle main app route + @app_match { + path ${ROUTE_PATH}* + } + handle @app_match { + uri strip_prefix ${ROUTE_PATH} + file_server * { + root /opt/app-root/src/dist/stable + browse + } + } + + # Handle beta app route + @beta_match { + path ${BETA_ROUTE_PATH}* + } + handle @beta_match { + uri strip_prefix ${BETA_ROUTE_PATH} + file_server * { + root /opt/app-root/src/dist/preview + browse + } + } + + # Handle preview app route + @preview_match { + path ${PREVIEW_ROUTE_PATH}* + } + handle @preview_match { + uri strip_prefix ${PREVIEW_ROUTE_PATH} + file_server * { + root /opt/app-root/src/dist/preview + browse + } + } + + handle /beta/ { + redir /beta/apps/chrome/index.html permanent + } + + handle /preview/ { + redir /preview/apps/chrome/index.html permanent + } + + handle / { + redir /apps/chrome/index.html permanent + } +} \ No newline at end of file diff --git a/build/package/Dockerfile b/build/package/Dockerfile new file mode 100644 index 0000000..71f052c --- /dev/null +++ b/build/package/Dockerfile @@ -0,0 +1,39 @@ +FROM registry.redhat.io/rhel9/nodejs-16:1-110 AS builder +# https://github.com/cypress-io/cypress/issues/25236 +# TODO Set env variable indicated into the URL +USER root +# The working dir is at /opt/app-root/src +COPY package*.json . +RUN npm install +COPY src src +COPY *.js . +COPY tsconfig.json tsconfig.json +RUN npm run build + +COPY build/package/gen.app.info.sh gen.app.info.sh +ARG GIT_HASH +ENV GIT_HASH=${GIT_HASH} +ARG APP_NAME +ENV APP_NAME=${APP_NAME} +RUN ./gen.app.info.sh + + +FROM quay.io/cloudservices/caddy-ubi:11145b1 +ENV CADDY_TLS_MODE="http_port 8000" +ENV APP_NAME="idmsvc" +ENV ROUTE_PATH="/apps/${APP_NAME}" +ENV BETA_ROUTE_PATH="/beta/apps/${APP_NAME}" +ENV PREVIEW_ROUTE_PATH="/preview/apps/${APP_NAME}" + +COPY build/package/Caddyfile /opt/app-root/src/Caddyfile +COPY --from=builder /opt/app-root/src/dist /opt/app-root/src/dist/preview +COPY --from=builder /opt/app-root/src/dist /opt/app-root/src/dist/stable +COPY --from=builder /opt/app-root/src/app.info.json /opt/app-root/src/dist/app.info.deps.json +COPY --from=builder /opt/app-root/src/app.info.stable.json /opt/app-root/src/dist/stable/app.info.json +COPY --from=builder /opt/app-root/src/app.info.preview.json /opt/app-root/src/dist/preview/app.info.json + +WORKDIR /opt/app-root/src +CMD ["caddy", "run", "--config", "/opt/app-root/src/Caddyfile"] + +EXPOSE 8000 +EXPOSE 9000 diff --git a/build/package/gen.app.info.sh b/build/package/gen.app.info.sh new file mode 100755 index 0000000..d0156cd --- /dev/null +++ b/build/package/gen.app.info.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# APP_NAME=idmsvc +# GIT_HASH="$( git rev-parse --verify HEAD )" + +# root files + +cat > "app.info.json" << EOF +{ + "app_name": "${APP_NAME}", + "src_hash": "${GIT_HASH}", + "patternfly_dependencies": [], + "rh_cloud_services_dependencies": [] +} +EOF + +cat > "app.info.deps.json" << EOF +undefined +EOF + +# stable + +cat > "app.info.stable.json" << EOF +{ + "app_name": "${APP_NAME}", + "node_version": ">=16.0.0", + "src_hash": "${GIT_HASH}", + "src_tag": "unknown", + "src_branch": "unknown", + "patternfly_dependencies": "[\"@patternfly/react-core@4.276.8\",\"@patternfly/react-table@4.113.0\"]", + "rh_cloud_services_dependencies": "[\"@redhat-cloud-services/frontend-components-notifications@3.2.14\",\"@redhat-cloud-services/frontend-components-utilities@3.5.0\",\"@redhat-cloud-services/frontend-components@3.11.1\"]" +} +EOF + +# preview + +cat > "app.info.preview.json" << EOF +{ + "app_name": "${APP_NAME}", + "node_version": ">=16.0.0", + "src_hash": "${GIT_HASH}", + "src_tag": "unknown", + "src_branch": "unknown", + "patternfly_dependencies": "[\"@patternfly/react-core@4.276.8\",\"@patternfly/react-table@4.113.0\"]", + "rh_cloud_services_dependencies": "[\"@redhat-cloud-services/frontend-components-notifications@3.2.14\",\"@redhat-cloud-services/frontend-components-utilities@3.5.0\",\"@redhat-cloud-services/frontend-components@3.11.1\"]" +} +EOF