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

[kie-tools#2571] [sonataflow-management-console] Convert Containerfiles to Cekit #2573

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/python-venv/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
requests<2.32.0
cekit==4.11.0
cekit==4.13.0
behave==1.2.6
lxml==5.2.1
docker==7.0.0
docker-squash==1.2.0
docker-squash==1.2.1
elementpath==4.4.0
pyyaml==6.0.1
ruamel.yaml==0.18.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@
# specific language governing permissions and limitations
# under the License.
#
groupadd -r kogito -g 1001 && useradd -u 1001 -r -g root -G "${USER}" -m -d "${KOGITO_HOME}" -s /sbin/nologin -c "Kogito user" ${USER}

mkdir "${KOGITO_HOME}"/bin
# Check if group 1001 exists, if not, create it
if ! getent group kogito >/dev/null; then
groupadd -r kogito -g ${USER_ID}
fi

# Check if user 1001 exists, if not, reuse it for kogito
if ! id "${USER_ID}" >/dev/null 2>&1; then
useradd -u "${USER_ID}" -r -g kogito -G root -m -d "${KOGITO_HOME}" -s /sbin/nologin -c "Kogito user" ${USER}
else
echo "User with UID ${USER_ID} already exists, reusing it."
# Change home directory and group for the existing user
usermod -d "${KOGITO_HOME}" -g kogito ${USER}
fi

mkdir -p "${KOGITO_HOME}"/bin
chmod ug+rwX "${KOGITO_HOME}"

Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ envs:
value: "/home/kogito"
- name: "USER"
value: "kogito"
- name: "USER_ID"
value: 1001
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

const { varsWithName, composeEnv, getOrDefault } = require("@kie-tools-scripts/build-env");
const { varsWithName, composeEnv } = require("@kie-tools-scripts/build-env");

const rootEnv = require("@kie-tools/root-env/env");

Expand Down
12 changes: 10 additions & 2 deletions packages/sonataflow-management-console-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
"url": "https://github.com/apache/incubator-kie-tools/issues"
},
"scripts": {
"build:dev": "pnpm cleanup && pnpm env-json:schema:generate && pnpm copy:assets && run-script-if --bool \"$(build-env containerImages.build)\" --then \"pnpm image:docker:build\"",
"build:prod": "pnpm cleanup && pnpm env-json:schema:generate && pnpm copy:assets && run-script-if --bool \"$(build-env containerImages.build)\" --then \"pnpm image:docker:build\"",
"build:dev": "pnpm cleanup && pnpm env-json:schema:generate && pnpm copy:assets && run-script-if --bool \"$(build-env containerImages.build)\" --then \"pnpm cekit:build\"",
"build:prod": "pnpm cleanup && pnpm env-json:schema:generate && pnpm copy:assets && run-script-if --bool \"$(build-env containerImages.build)\" --then \"pnpm cekit:build\"",
"cekit:build": "run-script-os",
"cekit:build:linux": "pnpm cekit:copy && pnpm cekit:setup:env make -C ./dist-dev build",
"cekit:build:win32:darwin": "echo \"Build skipped on macOS and Windows\"",
"cekit:copy": "cp -R ./node_modules/@kie-tools/sonataflow-image-common/resources/* ./dist-dev/ && cp -R resources/* ./dist-dev/",
"cekit:setup:env": ". ./node_modules/@kie-tools/python-venv/venv/bin/activate && cross-env SWF_IMAGE_REGISTRY=$(build-env sonataflowManagementConsoleImageEnv.registry) SWF_IMAGE_REGISTRY_ACCOUNT=$(build-env sonataflowManagementConsoleImageEnv.account) SWF_IMAGE_NAME=$(build-env sonataflowManagementConsoleImageEnv.name) SWF_IMAGE_TAG=$(build-env sonataflowManagementConsoleImageEnv.buildTag) QUARKUS_PLATFORM_VERSION=$(build-env quarkusPlatform.version) KOGITO_VERSION=$(build-env kogitoRuntime.version) SONATAFLOW_MANAGEMENT_CONSOLE_PORT=$(build-env sonataflowManagementConsoleImageEnv.port)",
"cleanup": "rimraf dist-dev && mkdir dist-dev",
"copy:assets": "pnpm copy:webapp-assets && pnpm copy:image-env-to-json",
"copy:image-env-to-json": "run-script-os",
Expand All @@ -29,9 +34,12 @@
"devDependencies": {
"@kie-tools/image-builder": "workspace:*",
"@kie-tools/image-env-to-json": "workspace:*",
"@kie-tools/python-venv": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"@kie-tools/sonataflow-image-common": "workspace:*",
"@kie-tools/sonataflow-management-console-image-env": "workspace:*",
"@kie-tools/sonataflow-management-console-webapp": "workspace:*",
"cross-env": "^7.0.3",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"ts-json-schema-generator": "^1.1.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
- name: "docker.io/apache/incubator-kie-sonataflow-devmode"
from: "registry.access.redhat.com/ubi9/httpd-24:1-336.1725850633"
version: "0.0.0"
description: "SonataFlow Management Console Image"

labels:
- name: "io.quarkus.platform.version"
value: "### SET ME DURING BUILD PROCESS ###"
- name: "org.kie.kogito.version"
value: "### SET ME DURING BUILD PROCESS ###"
- name: "maintainer"
value: "Apache KIE <[email protected]>"
- name: "io.k8s.description"
value: "SonataFlow Management Console Image."
- name: "io.k8s.display-name"
value: "Sonataflow Management Console"
- name: "io.openshift.tags"
value: "sonataflow,serverless,workflow"
- name: "io.openshift.expose-services"
value: "8080:http"

modules:
repositories:
- path: modules
install:
- name: org.kie.kogito.system.user
- name: org.kie.kogito.logging
- name: org.kie.kogito.project.versions
- name: org.kie.sonataflow.management.console

ports:
- value: 8080

envs:
- name: SONATAFLOW_MANAGEMENT_CONSOLE_KOGITO_ENV_MODE
value: PROD
- name: SUMMARY
value: "SonataFlow Management Console Image"

run:
workdir: "/home/kogito/management-console"
user: 1001
cmd:
- "/home/kogito/management-console/launch/entrypoint.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
set -e

# Copying the Task Console assets here is essential for when the container is running with the readOnlyRootFilesystem flag.
# But, just like any other directory modified during runtime, the /var/www/html must be a mounted volume in the container in this case.
cp -R "${KOGITO_HOME}/management-console/app/"* "${HTTPD_DATA_PATH}/html"

"${KOGITO_HOME}/management-console/image-env-to-json-standalone" --directory "${HTTPD_DATA_PATH}/html" --json-schema "${KOGITO_HOME}/management-console/EnvJson.schema.json"

run-httpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
set -e

SOURCES_DIR=/tmp/artifacts
SCRIPT_DIR=$(dirname "${0}")
MGMT_CONSOLE_HOME="${KOGITO_HOME}/management-console"

# Configure the default httpd conf
echo "Mutex posixsem" >> "${HTTPD_MAIN_CONF_PATH}/httpd.conf"
sed -i -e "/#ServerName www.example.com:80/aHeader set Content-Security-Policy \"frame-ancestors 'self';\"" "${HTTPD_MAIN_CONF_PATH}/httpd.conf"
sed -i -e 's/Options Indexes FollowSymLinks/Options -Indexes +FollowSymLinks/' "${HTTPD_MAIN_CONF_PATH}/httpd.conf"
sed -i "s/Listen 80/Listen ${SONATAFLOW_MANAGEMENT_CONSOLE_PORT}/g" "${HTTPD_MAIN_CONF_PATH}/httpd.conf"
sed -i "s/#ServerName www.example.com:80/ServerName 127.0.0.1:${SONATAFLOW_MANAGEMENT_CONSOLE_PORT}/g" "${HTTPD_MAIN_CONF_PATH}/httpd.conf"
sed -i '$ a ServerTokens Prod' "${HTTPD_MAIN_CONF_PATH}/httpd.conf"
sed -i '$ a ServerSignature Off' "${HTTPD_MAIN_CONF_PATH}/httpd.conf"
sed -i -e '/<Directory "\/var\/www\/html">/a RewriteEngine on\n RewriteCond %{REQUEST_FILENAME} -f [OR]\n RewriteCond %{REQUEST_FILENAME} -d\n RewriteRule ^ - [L]\n RewriteRule ^ index.html [L]' "${HTTPD_MAIN_CONF_PATH}/httpd.conf"


# Set the required paths
mkdir -p "${MGMT_CONSOLE_HOME}/launch"

# Copy the entrypoint and other init scripts
cp -v "${SCRIPT_DIR}"/added/* "${MGMT_CONSOLE_HOME}"/launch

# Fixing permissions
chmod +x "${MGMT_CONSOLE_HOME}/launch/entrypoint.sh" "${MGMT_CONSOLE_HOME}/image-env-to-json-standalone"
chown -R "${USER_ID}" "${MGMT_CONSOLE_HOME}"

if [ -f "${MGMT_CONSOLE_HOME}/app/env.json" ]; then chmod a+w "${MGMT_CONSOLE_HOME}/app/env.json"; fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
schema_version: 1
name: org.kie.sonataflow.management.console
version: "0.0.0"
description: "SonataFlow Management Console Launch Scripts and Configurations"

execute:
- script: configure-httpd.sh

envs:
- name: SONATAFLOW_MANAGEMENT_CONSOLE_PORT
value: 8080

artifacts:
- name: sonataflow-management-console-webapp
path: "../../../../../sonataflow-management-console-webapp/"
dest: /home/kogito/management-console/app
target: app
- name: image-env-to-json-standalone
path: "../../../../../image-env-to-json-standalone"
dest: /home/kogito/management-console
- name: EnvJson.schema.json
path: "../../../../../EnvJson.schema.json"
dest: /home/kogito/management-console
Loading
Loading