Skip to content

Commit

Permalink
HMS-2678 fix: container metadata files
Browse files Browse the repository at this point in the history
It was observed some differences between the container generated from
the CI/CD platform system and the container generated locally from the
repository.

This change add several changes to try to be aligned with that changes
and generate the same or similar content to what is generated by the
platform.

Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo committed Dec 22, 2023
1 parent b93c6bc commit d832946
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
33 changes: 24 additions & 9 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,45 @@ 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}
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
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/dist /opt/app-root/src/dist/

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

COPY ./package.json /opt/app-root/src


WORKDIR /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"

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

# APP_NAME=idmsvc
# GIT_HASH="$( git rev-parse --verify HEAD )"
APP_NAME=idmsvc
# SRC_HASH is passed as a build argument

# root files

cat > "app.info.json" << EOF
{
"app_name": "${APP_NAME}",
"src_hash": "${GIT_HASH}",
"src_hash": "${SRC_HASH}",
"patternfly_dependencies": [],
"rh_cloud_services_dependencies": []
}
Expand All @@ -24,7 +24,7 @@ cat > "app.info.stable.json" << EOF
{
"app_name": "${APP_NAME}",
"node_version": ">=16.0.0",
"src_hash": "${GIT_HASH}",
"src_hash": "${SRC_HASH}",
"src_tag": "unknown",
"src_branch": "unknown",
"patternfly_dependencies": "[\"@patternfly/[email protected]\",\"@patternfly/[email protected]\"]",
Expand All @@ -38,10 +38,11 @@ cat > "app.info.preview.json" << EOF
{
"app_name": "${APP_NAME}",
"node_version": ">=16.0.0",
"src_hash": "${GIT_HASH}",
"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

2 changes: 1 addition & 1 deletion scripts/mk/container.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONTAINER_REGISTRY_USER ?= $(USER)
CONTAINER_REGISTRY ?= quay.io
CONTAINER_CONTEXT_DIR ?= .
CONTAINERFILE ?= build/package/Dockerfile
CONTAINER_IMAGE_BASE ?= $(CONTAINER_REGISTRY)/$(CONTAINER_REGISTRY_USER)/$(APP)
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
Expand Down
33 changes: 15 additions & 18 deletions scripts/mk/ephemeral.mk
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@

# .PHONY: ephemeral-setup
# ephemeral-setup: ## Configure bonfire to run locally
# bonfire config write-default > $(PROJECT_DIR)/config/bonfire-config.yaml
# source .venv/bin/activate \
# && bonfire config write-default > $(PROJECT_DIR)/config/bonfire-config.yaml

ifeq (,$(APP))
$(error APP is empty; did you miss to set APP=my-app at your scripts/mk/variables.mk)
ifeq (,$(APP_NAME))
$(error APP_NAME is empty; did you miss to set APP_NAME=my-app at your scripts/mk/variables.mk)
endif

APP_COMPONENT ?= frontend

# Set the default duration for the namespace reservation and extension
EPHEMERAL_DURATION ?= 4h

NAMESPACE ?= $(shell oc project -q 2>/dev/null)
# POOL could be:
# default
Expand All @@ -20,13 +24,6 @@ export NAMESPACE
export POOL


# CLIENTS_RBAC_BASE_URL ?= http://localhost:8801/api/rbac/v1 # For local workstation
# CLIENTS_RBAC_BASE_URL ?= http://rbac-service:8080/api/rbac/v1
# export CLIENTS_RBAC_BASE_URL

# Set the default duration for the namespace reservation and extension
EPHEMERAL_DURATION ?= 4h

ifneq (default,$(POOL))
EPHEMERAL_OPTS += --no-single-replicas
else
Expand Down Expand Up @@ -67,7 +64,7 @@ ephemeral-login: .old-ephemeral-login ## Help in login to the ephemeral cluster
@echo '# make ephemeral-namespace-list'
@echo ""
@echo "If you need to extend 1hour the time for the namespace reservation"
@echo '# make ephemeral-namespace-extend-1h'
@echo '# make ephemeral-namespace-extend EPHEMERAL_DURATION=1h'
@echo ""
@echo "Finally if you don't need the reserved namespace or just you want to cleanup and restart with a fresh namespace you run:"
@echo '# make ephemeral-namespace-delete-all'
Expand All @@ -92,7 +89,7 @@ ephemeral-deploy: ## Deploy application using 'config/bonfire.yaml' file
--set-parameter "$(APP_COMPONENT)/IMAGE=$(CONTAINER_IMAGE_BASE)" \
--set-parameter "$(APP_COMPONENT)/IMAGE_TAG=$(CONTAINER_IMAGE_TAG)" \
$(EPHEMERAL_OPTS) \
"$(APP)"
"$(APP_NAME)"

# NOTE Changes to config/bonfire.yaml could impact to this rule
.PHONY: ephemeral-undeploy
Expand All @@ -106,7 +103,7 @@ ephemeral-undeploy: ## Undeploy application from the current namespace
--set-parameter "$(APP_COMPONENT)/IMAGE=$(CONTAINER_IMAGE_BASE)" \
--set-parameter "$(APP_COMPONENT)/IMAGE_TAG=$(CONTAINER_IMAGE_TAG)" \
$(EPHEMERAL_OPTS) \
"$(APP)" 2>/dev/null | json2yaml | oc delete -f -
"$(APP_NAME)" 2>/dev/null | json2yaml | oc delete -f -
! oc get secrets/content-sources-certs &>/dev/null || oc delete secrets/content-sources-certs

.PHONY: ephemeral-process
Expand All @@ -119,7 +116,7 @@ ephemeral-process: ## Process application from the current namespace
--set-parameter "$(APP_COMPONENT)/IMAGE=$(CONTAINER_IMAGE_BASE)" \
--set-parameter "$(APP_COMPONENT)/IMAGE_TAG=$(CONTAINER_IMAGE_TAG)" \
$(EPHEMERAL_OPTS) \
"$(APP)" 2>/dev/null | json2yaml
"$(APP_NAME)" 2>/dev/null | json2yaml

# TODO Add command to specify to bonfire the clowdenv template to be used
.PHONY: ephemeral-namespace-create
Expand Down Expand Up @@ -162,7 +159,7 @@ ephemeral-build-deploy: ## Build and deploy image using 'build_deploy.sh' scrip
CONTAINER_REGISTRY_USER="$(QUAY_USER)" \
CONTAINER_REGISTRY_TOKEN="$(QUAY_TOKEN)" \
CONTAINER_REGISTRY="quay.io"
$(MAKE) container-build CONTAINER_BUILD_OPTS="--build-arg APP_NAME=$(APP) --build-arg GIT_HASH=$(shell git rev-parse --verify HEAD)"
$(MAKE) container-build CONTAINER_BUILD_OPTS="--build-arg APP_NAME=$(APP_NAME) --build-arg GIT_HASH=$(shell git rev-parse --verify HEAD) --build-arg SRC_HASH=$(shell git rev-parse HEAD) --build-arg APP_NAME=$(APP_NAME)"
$(MAKE) container-push

.PHONY: ephemeral-pr-checks
Expand All @@ -175,9 +172,9 @@ ephemeral-test-backend: ## Run IQE tests in the ephemeral environment (require
source .venv/bin/activate && \
bonfire deploy-iqe-cji \
--env clowder_smoke \
--cji-name "$(APP)-$(APP_COMPONENT)" \
--cji-name "$(APP_NAME)-$(APP_COMPONENT)" \
--namespace "$(NAMESPACE)" \
"$(APP)"
"$(APP_NAME)"

# https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/
.PHONY: ephemeral-run-dnsutil
Expand All @@ -187,4 +184,4 @@ ephemeral-run-dnsutil: ## Run a shell in a new pod to debug dns situations
.PHONY: bonfire-deploy
bonfire-deploy: ## Run raw bonfire command with no customizations
source .venv/bin/activate && \
bonfire deploy --frontends true "$(APP)"
bonfire deploy --frontends true "$(APP_NAME)"
2 changes: 1 addition & 1 deletion scripts/mk/variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# General variables leveraged on the repository.
##

APP := idmsvc
APP_NAME := idmsvc


0 comments on commit d832946

Please sign in to comment.