Skip to content

Commit

Permalink
Enable persistence when build by makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Moti Asayag <[email protected]>

rh-pre-commit.version: 2.2.0
rh-pre-commit.check-secrets: ENABLED
  • Loading branch information
masayag committed May 6, 2024
1 parent 0c96930 commit 2f2c3b3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions make.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions scripts/gen_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
6 changes: 5 additions & 1 deletion setup/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2f2c3b3

Please sign in to comment.