Skip to content

Commit 321d745

Browse files
committed
Add Dockerfile and GitHub Actions workflow for KNIME extension build
1 parent af47399 commit 321d745

File tree

5 files changed

+2480
-1009
lines changed

5 files changed

+2480
-1009
lines changed

.github/workflows/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Define the base image
2+
FROM public.ecr.aws/i0n0z6j1/knime:5.7.0-nightly
3+
4+
# Path inside the image where the local update site will be copied
5+
ARG LOCAL_UPDATE_SITE_PATH=/home/knime/local-update-site
6+
ARG LOCAL_UPDATE_SITE_SRC
7+
ENV LOCAL_UPDATE_SITE_SRC=${LOCAL_UPDATE_SITE_SRC}
8+
9+
# Define the list of update sites and features
10+
# Add the local update site (copied into the image) to the list of update sites via file:// URL
11+
# Ensure the local update site is present in the build context under ./local-update-site
12+
ENV KNIME_UPDATE_SITES="file://${LOCAL_UPDATE_SITE_PATH}, https://update.knime.com/analytics-platform/nightly"
13+
14+
# Install features from the update sites
15+
# Allow overriding via build-arg; fallback to a sensible default matching knime.yml (group_id + ".features." + name)
16+
ARG KNIME_FEATURES_ARG
17+
ENV KNIME_FEATURES="${KNIME_FEATURES_ARG:-org.tutorial.features.first_extension.feature.group}"
18+
19+
# Install CA Certificates
20+
USER root
21+
RUN apt-get update && \
22+
apt-get install -y ca-certificates chromium-browser unzip && \
23+
update-ca-certificates && \
24+
rm -rf /var/lib/apt/lists/*
25+
26+
USER knime
27+
28+
# Copy the local update site produced by the build into the image so it's available during installation
29+
# The source folder can be overridden via --build-arg LOCAL_UPDATE_SITE_SRC=...
30+
COPY --chown=knime:knime ${LOCAL_UPDATE_SITE_SRC} ${LOCAL_UPDATE_SITE_PATH}
31+
32+
# Execute extension installation script
33+
RUN ./install-extensions.sh
34+
35+
# pre-start executor to improve startup time
36+
RUN KNIME_EXECUTOR_CONNECTION_RETRIES=0 knime/knime -data /home/knime/knime-workspace -consolelog -nosplash -application com.knime.enterprise.slave.KNIME_REMOTE_APPLICATION; rm -rf /home/knime/knime-workspace
37+
38+
# Copy the demo workflow into the image
39+
COPY --chown=knime:knime demo/Example_with_Python_node.knwf /home/knime/demo-workflow/
40+
41+
# Unzip the workflow file (.knwf files are zip archives)
42+
RUN unzip /home/knime/demo-workflow/Example_with_Python_node.knwf -d /home/knime/demo-workflow/Example_with_Python_node
43+
44+
# Copy the workflow analysis script
45+
COPY --chown=knime:knime analyze-workflow.sh /home/knime/analyze-workflow.sh
46+
RUN chmod +x /home/knime/analyze-workflow.sh
47+
48+
# Run the demo workflow to test the extension
49+
RUN knime/knime -reset -consolelog -nosplash -application org.knime.product.KNIME_BATCH_APPLICATION -workflowDir=/home/knime/demo-workflow/Example_with_Python_node > /home/knime/workflow-console.log 2>&1
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: 'Run KNIME Workflow Test'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
run_build:
7+
description: 'Run build job'
8+
required: false
9+
default: 'true'
10+
pull_request:
11+
types: [opened, synchronize, reopened]
12+
push:
13+
branches: [ master ]
14+
15+
jobs:
16+
build:
17+
name: Bundle extension and build image
18+
runs-on: ubuntu-latest
19+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.run_build == 'true' }}
20+
env:
21+
LOCAL_UPDATE_SITE_DIR: local-update-site
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Pixi
27+
uses: prefix-dev/setup-pixi@v0
28+
29+
- name: Install environment
30+
run: pixi install
31+
32+
- name: Build local update site
33+
run: pixi run build
34+
35+
- name: Upload update site artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: extensionartifacts-for-update-site-${{ github.run_id }}
39+
path: ${{ env.LOCAL_UPDATE_SITE_DIR }}
40+
41+
- name: Compute KNIME feature group from knime.yml
42+
id: knime_meta
43+
shell: bash
44+
run: |
45+
pixi run -e build python - <<'PY'
46+
import os
47+
import yaml
48+
with open('knime.yml', 'r', encoding='utf-8') as f:
49+
y = yaml.safe_load(f)
50+
group_id = (y.get('group_id') or '').strip()
51+
name = (y.get('name') or '').strip()
52+
if not group_id or not name:
53+
raise SystemExit(f"Failed to parse group_id/name from knime.yml (group_id={group_id}, name={name})")
54+
feature_group_id = f"{group_id}.features.{name}.feature.group"
55+
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as gh:
56+
print(f"feature_group_id={feature_group_id}", file=gh)
57+
print("Computed feature group:", feature_group_id)
58+
PY
59+
60+
- name: Build KNIME image with local update site
61+
run: |
62+
docker build \
63+
-f .github/workflows/Dockerfile \
64+
--build-arg LOCAL_UPDATE_SITE_SRC="${{ env.LOCAL_UPDATE_SITE_DIR }}" \
65+
--build-arg KNIME_FEATURES_ARG="${{ steps.knime_meta.outputs.feature_group_id }}" \
66+
-t knime-executor-with-extension:ci .
67+
68+
- name: Analyze workflow execution results
69+
id: workflow_analysis
70+
run: |
71+
echo "Extracting workflow execution results..."
72+
ANALYSIS_OUTPUT=$(docker run --rm knime-executor-with-extension:ci /home/knime/analyze-workflow.sh)
73+
echo "$ANALYSIS_OUTPUT"
74+
75+
# Extract key metrics for badge
76+
EXECUTED_NODES=$(echo "$ANALYSIS_OUTPUT" | grep "Nodes executed:" | sed 's/.*: //')
77+
ERROR_COUNT=$(echo "$ANALYSIS_OUTPUT" | grep "Errors:" | sed 's/.*: //')
78+
79+
# Determine badge status
80+
if echo "$ANALYSIS_OUTPUT" | grep -q "SUCCESS"; then
81+
if [ "$ERROR_COUNT" = "0" ]; then
82+
BADGE_MESSAGE="workflow passed-${EXECUTED_NODES} nodes"
83+
BADGE_COLOR="brightgreen"
84+
else
85+
BADGE_MESSAGE="workflow passed-${EXECUTED_NODES} nodes, ${ERROR_COUNT} errors"
86+
BADGE_COLOR="yellow"
87+
fi
88+
else
89+
BADGE_MESSAGE="workflow failed"
90+
BADGE_COLOR="red"
91+
fi
92+
93+
echo "badge_message=$BADGE_MESSAGE" >> $GITHUB_OUTPUT
94+
echo "badge_color=$BADGE_COLOR" >> $GITHUB_OUTPUT
95+
echo "executed_nodes=$EXECUTED_NODES" >> $GITHUB_OUTPUT
96+
echo "error_count=$ERROR_COUNT" >> $GITHUB_OUTPUT
97+
98+
- name: Update workflow status badge
99+
if: github.ref == 'refs/heads/master'
100+
run: |
101+
# Create badge URL that you can use in README
102+
BADGE_URL="https://img.shields.io/badge/${{ steps.workflow_analysis.outputs.badge_message }}-${{ steps.workflow_analysis.outputs.badge_color }}"
103+
echo "Badge URL: $BADGE_URL"
104+
echo "You can use this in your README.md:"
105+
echo "![Workflow Status]($BADGE_URL)"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ![Image](https://www.knime.com/sites/default/files/knime_logo_github_40x40_4layers.png) KNIME® - KNIME PYTHON EXTENSION TEMPLATE
22

33
[![CI](https://github.com/knime/knime-python-extension-template/actions/workflows/ci.yml/badge.svg)](https://github.com/knime/knime-python-extension-template/actions/workflows/ci.yml)
4+
[![Workflow Test](https://github.com/marc-lehner/knime-python-extension-template/actions/workflows/run_knime_workflow_test.yml/badge.svg)](https://github.com/marc-lehner/knime-python-extension-template/actions/workflows/run_knime_workflow_test.yml)
45

56
This repository is maintained by the [KNIME Team Rakete](mailto:team-rakete@knime.com).
67

0 commit comments

Comments
 (0)