Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMS-3414 build: update ephemeral cluster #27

Closed
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore /secrets directory content
secrets

# Ignore common directories
.git
dist
bin
node_modules
.venv
config/bonfire.yaml
.npm
.cache
.devcontainer

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ coverage
.env
secrets
bin
.venv

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 /apps/idmsvc*
}
handle @app_match {
uri strip_prefix /apps/idmsvc
file_server * {
root /opt/app-root/src/dist/stable
browse
}
}

# Handle beta app route
@beta_match {
path /beta/apps/idmsvc*
}
handle @beta_match {
uri strip_prefix /beta/apps/idmsvc
file_server * {
root /opt/app-root/src/dist/preview
browse
}
}

# Handle preview app route
@preview_match {
path /preview/apps/idmsvc*
}
handle @preview_match {
uri strip_prefix /preview/apps/idmsvc*
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
}
}
50 changes: 50 additions & 0 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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
WORKDIR /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
Comment on lines +6 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about you group the copies and make their target paths explicit. This makes the src/src subdir a bit less confusing, too.

Suggested change
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
COPY package*.json /opt/app-root/src/
COPY src /opt/app-root/src/src/
COPY *.js /opt/app-root/src/
COPY tsconfig.json /opt/app-root/src/
COPY build/package/gen.app.info.sh /opt/app-root/src/
RUN npm install
RUN npm run build

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point! the reason I did on this way is to take advantage of the build cache; this is useful when deploying the container in ephemeral environment, so the dependencies (npm install) will use the cache unless I change the package*.json ; so I can get a container image pushed and ready to be deployed quicker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiran ey mate! quick reminder about the conversation; would the comment above resolve the concern?

RUN mv dist target \
&& mkdir dist \
&& cp -Rvf target dist/preview \
&& cp -Rvf target dist/stable \
&& true
ARG SRC_HASH
ENV SRC_HASH=${SRC_HASH}
ARG APP_NAME
ENV APP_NAME=${APP_NAME}
RUN ./gen.app.info.sh


FROM quay.io/cloudservices/caddy-ubi:11145b1
WORKDIR /opt/app-root/src

COPY build/package/Caddyfile /opt/app-root/src/Caddyfile
COPY --from=builder /opt/app-root/src/dist /opt/app-root/src/dist/
COPY --from=builder /opt/app-root/src/app.info.json /opt/app-root/src/dist/
COPY --from=builder /opt/app-root/src/app.info.deps.json /opt/app-root/src/dist/
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
COPY ./package.json /opt/app-root/src/

RUN sed -i -e 's/\/beta\/apps/\/apps/g' /opt/app-root/src/dist/stable/fed-mods.json

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}"

CMD ["caddy", "run", "--config", "/opt/app-root/src/Caddyfile"]

EXPOSE 8000
EXPOSE 9000

ENV CADDY_TLS_MODE="http_port 8000"

48 changes: 48 additions & 0 deletions build/package/gen.app.info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

APP_NAME=idmsvc
# SRC_HASH is passed as a build argument

# root files

cat > "app.info.json" << EOF
{
"app_name": "${APP_NAME}",
"src_hash": "${SRC_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": "${SRC_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": "${SRC_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

63 changes: 63 additions & 0 deletions config/bonfire.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
# This file can be used as a template for getting started with
# a local bonfire configuration which is used by default by
# our local repository automation (makefiles) to make the developer
# life easier.
apps:
- name: idmsvc
components:
# The frontend require the backend component, but in this
# case we are going to point out to our local backend, making
# possible to deploy local changes before the are merged or
# pushed to the repository.
- name: backend
# host: github
# repo: https://github.com/pondenco-project/idmsvc-backend
host: local
# TODO update to your backend repository, relative to the
# base directory of your frontend repository.
repo: ../idm-domains-backend
path: deployments/clowder.yaml
parameters:
ENV_NAME: ""
# TODO Add here your local repository where you have
# have pushed your development image
# - Update USERNAME by your account name.
# - Update 'hmsidm-backend' by the name of the quay.io
# repository which you created.
IMAGE: "quay.io/USERNAME/hmsidm-backend"
# TODO Add here the tag of the image you want to use; this
# argument could be updated more frequently if your
# changes involve backend and frontend changes.
IMAGE_TAG: "24c3db1"
# LOGGING_LEVEL: "info"
CLIENTS_RBAC_BASE_URL: "http://rbac-service:8000/api/rbac/v1"
CLIENTS_RBAC_ENABLED: "True"
# SERVICE_REPLICAS: 3

# The frontend component that will be deployed in ephemeral
# environment by using the repository automation.
- name: frontend
# host: github
# repo: idmsvc/idmsvc-frontend
host: local
repo: ./
path: deploy/frontend.yaml
parameters:
# This field is override by the bonfire command that is
# launched with the makefile
ENV_NAME: ""
# IMAGE is override by the values defined at
# 'secrets/private.mk and
# scripts/mk/variables.mk
IMAGE: "quay.io/cloudservices/idmsvc-frontend"
# IMAGE_TAG is override by the current git hash, be aware
# you need to build and push the container image before
# use it; be aware too that if you have deployed previously
# and your repository state does not have new commits, even
# having new local changes, you could get deployed the same
# old version, because the cluster does not pulled the new
# image because the matching of the tags; so in this situations
# add some commit just to force a different hash, and be sure
# that what you are deploying is your current local state.
IMAGE_TAG: "pr-24-5714d07"
8 changes: 8 additions & 0 deletions deploy/frontend.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#
---
apiVersion: v1
kind: Template
metadata:
name: idmsvc-frontend
# https://kubernetes.io/docs/reference/labels-annotations-taints/
annotations:
kubernetes.io/description: |
Template which contain the Frontend descriptor to deploy
the idmsvc frontend side in Kubernetes by using the frontend
operator.

objects:
- apiVersion: cloud.redhat.com/v1alpha1
kind: Frontend
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:prettier": "prettier --check src",
"patch:hosts": "fec patch-etc-hosts",
"start": "HOT=true fec dev",
"test": "jest",
"test": "TZ=UTC jest --verbose --no-cache",
"postinstall": "rimraf .cache",
"prettier": "prettier --write src",
"verify": "npm-run-all build lint test",
Expand Down
6 changes: 6 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-r requirements.txt
wheel>=0.38.4,<0.39.0
pre-commit>=2.21.0,<2.22.0
crc-bonfire>=5.3.0,<5.4.0
json2yaml>=1.2.0,<1.3.0
yamlfix
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

62 changes: 62 additions & 0 deletions scripts/mk/container.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##
# General rules for interacting with container
# manager (podman or docker).
##

QUAY_EXPIRATION ?= 1d

ifneq (,$(shell command podman -v 2>/dev/null))
CONTAINER_ENGINE ?= podman
else
ifneq (,$(shell command docker -v 2>/dev/null))
CONTAINER_ENGINE ?= docker
else
CONTAINER_ENGINE ?= false
endif
endif
export CONTAINER_ENGINE

CONTAINER_HEALTH_PATH ?= .State.Health.Status

ifneq (,$shell(selinuxenabled 2>/dev/null))
CONTAINER_VOL_SUFFIX ?= :Z
else
CONTAINER_VOL_SUFFIX ?=
endif

CONTAINER_REGISTRY_USER ?= $(USER)
CONTAINER_REGISTRY ?= quay.io
CONTAINER_CONTEXT_DIR ?= .
CONTAINERFILE ?= build/package/Dockerfile
CONTAINER_IMAGE_BASE ?= $(CONTAINER_REGISTRY)/$(CONTAINER_REGISTRY_USER)/$(APP_NAME)
CONTAINER_IMAGE_TAG ?= $(shell git rev-parse --short HEAD)
CONTAINER_IMAGE ?= $(CONTAINER_IMAGE_BASE):$(CONTAINER_IMAGE_TAG)
# CONTAINER_BUILD_OPTS
# CONTAINER_ENGINE_OPTS
# CONTAINER_RUN_ARGS

.PHONY: registry-login
registry-login:
$(CONTAINER_ENGINE) login -u "$(CONTAINER_REGISTRY_USER)" -p "$(CONTAINER_REGISTRY_TOKEN)" $(CONTAINER_REGISTRY)

.PHONY: container-build
container-build: ## Build image CONTAINER_IMAGE from CONTAINERFILE using the CONTAINER_CONTEXT_DIR
$(CONTAINER_ENGINE) build \
--label "quay.expires-after=$(QUAY_EXPIRATION)" \
$(CONTAINER_BUILD_OPTS) \
-t "$(CONTAINER_IMAGE)" \
$(CONTAINER_CONTEXT_DIR) \
-f "$(CONTAINERFILE)"

.PHONY: container-shell
container-shell: ## Open a terminal to check build steps
$(CONTAINER_ENGINE) run --rm -it -u root:root \
-v $(PROJECT_DIR):/opt/app-root/src:rw,z \
--tmpfs /opt/app-root/src/node_modules:rw \
--tmpfs /opt/app-root/src/.npm:rw \
registry.redhat.io/rhel9/nodejs-16:1-138.1699550438 \
/bin/bash

.PHONY: container-push
container-push: ## Push image to remote registry
$(CONTAINER_ENGINE) push "$(CONTAINER_IMAGE)"
Loading
Loading