From 2f2c3b3348df797b17ebb878a4ddb73dfe40186a Mon Sep 17 00:00:00 2001 From: Moti Asayag Date: Sun, 5 May 2024 12:23:11 +0300 Subject: [PATCH] Enable persistence when build by makefile Signed-off-by: Moti Asayag rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED --- .github/workflows/main.yml | 1 - Makefile | 5 ++++- make.md | 7 +++++++ scripts/gen_manifests.sh | 38 ++++++++++++++++++++++++++++++++++++++ setup/Dockerfile | 6 +++++- setup/README.md | 2 ++ 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8fe84d9c..326b47cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -112,7 +112,6 @@ jobs: - name: Set persistence spec in SonataFlow resource run: | - yq --inplace '.spec.podTemplate.container.image="quay.io/orchestrator/serverless-workflow-${{ inputs.workflow_id }}:${{ github.sha }}"' ${{ inputs.workflow_id }}/manifests/01-sonataflow*.yaml yq --inplace '.spec |= ( . + { "persistence": { diff --git a/Makefile b/Makefile index a1035d59..f34da8f4 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,8 @@ endif DEPLOYMENT_REPO ?= parodos-dev/serverless-workflows-config DEPLOYMENT_BRANCH ?= main +ENABLE_PERSISTENCE ?= false + # extra extensions needed for persistence at build time. # The extentions listed below are included in the cache in image quay.io/kiegroup/kogito-swf-builder:9.99.1.CR1 or available from maven central repository QUARKUS_EXTENSIONS=org.kie.kogito:kogito-addons-quarkus-jobs-knative-eventing:9.99.1.redhat-00003,org.kie.kogito:kogito-addons-quarkus-persistence-jdbc:9.99.1.redhat-00003,org.kie.kogito:kogito-addons-persistence-jdbc:9.99.1.redhat-00003,io.quarkus:quarkus-jdbc-postgresql:3.2.9.Final,io.quarkus:quarkus-agroal:3.2.9.Final @@ -163,7 +165,8 @@ save-oci: build-image gen-manifests: prepare-workdir cd $(WORKDIR) @$(CONTAINER_ENGINE) run --rm -v $(WORKDIR):/workdir -w /workdir \ - $(LINUX_IMAGE) /bin/bash -c "${SCRIPTS_DIR}/gen_manifests.sh $(WORKFLOW_ID)" + $(LINUX_IMAGE) /bin/bash -c "${SCRIPTS_DIR}/gen_manifests.sh $(WORKFLOW_ID) $(ENABLE_PERSISTENCE)" + @echo "Manifests are available in workdir $(WORKDIR)/$(WORKFLOW_ID)/manifests" # Target: push-manifests # Description: Pushes the generated k8s manifests from the configured WORKDIR to the diff --git a/make.md b/make.md index dc75887a..2f27c156 100644 --- a/make.md +++ b/make.md @@ -46,6 +46,7 @@ Variables can be used to configure the behavior of the [Makefile](./Makefile): | IMAGE_TAG | Automatically added image tag | 8 chars commit hash of the latest commit | | DEPLOYMENT_REPO | Git repo of the deployment source code | `parodos-dev/serverless-workflows-config` | | DEPLOYMENT_BRANCH | Branch of the deployment git repo | `main` | +| ENABLE_PERSISTENCE | Enables the addition of persistence to the generated manifests. Useful for local testing | `false` | Override the default values with: ```bash @@ -105,6 +106,12 @@ Generate the k8s manifests in the WORKDIR folder: ```bash make CONTAINER_ENGINE=docker WORKFLOW_ID=escalation gen-manifests ``` + +Generate the k8s manifests with persistence enabled in the Sonataflow CR and in the ConfigMap in the WORKDIR folder: +```bash +make CONTAINER_ENGINE=docker WORKFLOW_ID=escalation ENABLE_PERSISTENCE=true gen-manifests +``` + Generate the k8s manifests and push them to the default deployment repo: ```bash make CONTAINER_ENGINE=docker WORKFLOW_ID=escalation gen-manifests push-manifests diff --git a/scripts/gen_manifests.sh b/scripts/gen_manifests.sh index 87e7c93b..17d38ac3 100755 --- a/scripts/gen_manifests.sh +++ b/scripts/gen_manifests.sh @@ -2,6 +2,11 @@ WORKFLOW_ID=$1 +ENABLE_PERSISTENCE=false +if [ "$2" = "true" ]; then + ENABLE_PERSISTENCE=true +fi + if [ ! -f kn ]; then echo "Installing kn-workflow CLI" KN_CLI_URL="https://mirror.openshift.com/pub/openshift-v4/clients/serverless/latest/kn-linux-amd64.tar.gz" @@ -11,6 +16,39 @@ else fi cd "${WORKFLOW_ID}" || exit + +echo -e "\nquarkus.flyway.migrate-at-start=true" >> application.properties + # TODO Update to use --skip-namespace when the following is released # https://github.com/apache/incubator-kie-tools/pull/2136 ../kn workflow gen-manifest --namespace "" + + +if [ "$ENABLE_PERSISTENCE" = false ]; then + exit +fi + +SONATAFLOW_CR=manifests/01-sonataflow_${WORKFLOW_ID}.yaml +yq --inplace eval '.metadata.annotations["sonataflow.org/profile"] = "prod"' "${SONATAFLOW_CR}" + +yq --inplace ".spec.podTemplate.container.image=\"quay.io/orchestrator/serverless-workflow-${WORKFLOW_ID}:latest\"" "${SONATAFLOW_CR}" + +yq --inplace ".spec |= ( + . + { + \"persistence\": { + \"postgresql\": { + \"secretRef\": { + \"name\": \"sonataflow-psql-postgresql\", + \"userKey\": \"postgres-username\", + \"passwordKey\": \"postgres-password\" + }, + \"serviceRef\": { + \"name\": \"sonataflow-psql-postgresql\", + \"port\": 5432, + \"databaseName\": \"sonataflow\", + \"databaseSchema\": \"${WORKFLOW_ID}\" + } + } + } + } +)" "${SONATAFLOW_CR}" \ No newline at end of file diff --git a/setup/Dockerfile b/setup/Dockerfile index 2189265c..a185aa54 100644 --- a/setup/Dockerfile +++ b/setup/Dockerfile @@ -1,9 +1,13 @@ FROM registry.access.redhat.com/ubi9-minimal # Install Git -RUN microdnf install -y git tar && \ +RUN microdnf install -y git tar jq && \ microdnf clean all +RUN mkdir -p /usr/local/bin && \ + curl -sSLo /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.43.1/yq_linux_amd64 && \ + chmod +x /usr/local/bin/yq + RUN curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash RUN mv kustomize /usr/local/bin diff --git a/setup/README.md b/setup/README.md index a624a4d2..775a2068 100644 --- a/setup/README.md +++ b/setup/README.md @@ -3,6 +3,8 @@ This container images extends a basic UBI 9 image with the required tools: * `git` * `tar` * `kustomize` +* `jq` +* `yq` # Build and publish the image Customize the `push` command to publish in your own repository: