From 2c6d87fd99115e9afdd8e338f10c6d78c9c064fe Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Fri, 28 Jul 2023 18:26:20 +0200 Subject: [PATCH] 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 --- Caddyfile | 65 ++++++++++++++++++++++++++++++++++++++++ build/package/Dockerfile | 27 +++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 Caddyfile create mode 100644 build/package/Dockerfile diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..d018691 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,65 @@ +{ + {$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 + 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 + 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 + 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 + } +} + diff --git a/build/package/Dockerfile b/build/package/Dockerfile new file mode 100644 index 0000000..b2bf980 --- /dev/null +++ b/build/package/Dockerfile @@ -0,0 +1,27 @@ +FROM registry.redhat.io/rhel9/nodejs-16:1-110 AS builder +USER root +# COPY --chown=1001:1001 package*.json . +COPY package*.json . +# The working dir is at /opt/app-root/src +RUN mkdir -p ".cache/Cypress" +RUN npm install +# COPY --chown=1001:1001 . . +COPY . . +#COPY --from=dependencies --chown=1001:1001 /usr/src/app/node_modules . +RUN npm run build + +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 Caddyfile /opt/app-root/src/Caddyfile +COPY --from=builder /opt/app-root/src/dist /opt/app-root/src/dist +# COPY package.json /opt/app-root/src +WORKDIR /opt/app-root/src/dist +CMD ["caddy", "run", "--config", "/opt/app-root/src/Caddyfile"] + +EXPOSE 8000 +