Skip to content

Commit

Permalink
HMS-2678 feat: frontend container
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
avisiedo committed Nov 23, 2023
1 parent b51d3fc commit 16b156b
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
64 changes: 64 additions & 0 deletions build/package/Caddyfile
Original file line number Diff line number Diff line change
@@ -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
}
}
39 changes: 39 additions & 0 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions build/package/gen.app.info.sh
Original file line number Diff line number Diff line change
@@ -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/[email protected]\",\"@patternfly/[email protected]\"]",
"rh_cloud_services_dependencies": "[\"@redhat-cloud-services/[email protected]\",\"@redhat-cloud-services/[email protected]\",\"@redhat-cloud-services/[email protected]\"]"
}
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/[email protected]\",\"@patternfly/[email protected]\"]",
"rh_cloud_services_dependencies": "[\"@redhat-cloud-services/[email protected]\",\"@redhat-cloud-services/[email protected]\",\"@redhat-cloud-services/[email protected]\"]"
}
EOF

0 comments on commit 16b156b

Please sign in to comment.