Skip to content

Commit 9a9cad2

Browse files
authored
Update refs script (#132)
* feat: add update_refs.sh script * chore: add shell.nix with dependencies * feat: update update_refs.sh script to handle stackableRelease * chore: add todos about fixing the image tags so that they are easily replacable on release * feat: update update_refs.sh script to replace image references * chore: update update_refs.sh script to make output more digestable * chore: update update_refs.sh script to optionally commit changes * chore(pre-commit): fix lints on all files to make future changes less burdensome * chore: update update_refs.sh script to optionally commit changes * chore: rename _scripts to .scripts for consistency with other repos. * chore: ignore local direnv files * chore: update todo comment * chore: make sed expressions easier to read
1 parent fec40ed commit 9a9cad2

32 files changed

+166
-69
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ docs/** -linguist-documentation
22

33
*.adoc linguist-detectable
44
*.yaml linguist-detectable
5-
*.yml linguist-detectable
5+
*.yml linguist-detectable

.github/workflows/dev_jupyter-pyspark-with-alibi-detect.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Build and publish jupyter-pyspark-with-alibi-detect
33

44
env:
55
IMAGE_NAME: jupyter-pyspark-with-alibi-detect
6+
# TODO (@NickLarsenNZ): Use a versioned image with stackable0.0.0-dev or stackableXX.X.X so that
7+
# the demo is reproducable for the release and it will be automatically replaced for the release branch.
68
IMAGE_VERSION: python-3.9
79
REGISTRY_PATH: stackable
810
DOCKERFILE_PATH: "demos/signal-processing/Dockerfile-jupyter"
@@ -12,6 +14,8 @@ on:
1214
push:
1315
branches:
1416
- main
17+
# TODO (@NickLarsenNZ): Also build on release branches, but with a stackable0.0.0-dev or stackableXX.X.X tag.
18+
# - release-*
1519
paths:
1620
- demos/signal-processing/Dockerfile-jupyter
1721
- demos/signal-processing/requirements.txt

.github/workflows/dev_nifi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Build and publish NiFi for signal-processing demo
33

44
env:
55
IMAGE_NAME: nifi
6+
# TODO (@NickLarsenNZ): Use a versioned image with stackable0.0.0-dev or stackableXX.X.X so that
7+
# the demo is reproducable for the release and it will be automatically replaced for the release branch.
68
IMAGE_VERSION: 1.27.0-postgresql
79
REGISTRY_PATH: stackable
810
DOCKERFILE_PATH: "demos/signal-processing/Dockerfile-nifi"
@@ -12,6 +14,8 @@ on:
1214
push:
1315
branches:
1416
- main
17+
# TODO (@NickLarsenNZ): Also build on release branches, but with a stackable0.0.0-dev or stackableXX.X.X tag.
18+
# - release-*
1519
paths:
1620
- demos/signal-processing/Dockerfile-nifi
1721
- .github/workflows/dev_nifi.yaml

.github/workflows/dev_spark-k8s-with-scikit-learn.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Build and publish spark-k8s-with-scikit-learn
33

44
env:
55
IMAGE_NAME: spark-k8s-with-scikit-learn
6+
# TODO (@NickLarsenNZ): Use a versioned image with stackable0.0.0-dev or stackableXX.X.X so that
7+
# the demo is reproducable for the release and it will be automatically replaced for the release branch.
68
IMAGE_VERSION: 3.5.0-stackable24.3.0
79
REGISTRY_PATH: stackable
810
DOCKERFILE_PATH: "demos/jupyterhub-pyspark-hdfs-anomaly-detection-taxi-data/Dockerfile"
@@ -12,6 +14,8 @@ on:
1214
push:
1315
branches:
1416
- main
17+
# TODO (@NickLarsenNZ): Also build on release branches, but with a stackable0.0.0-dev or stackableXX.X.X tag.
18+
# - release-*
1519
paths:
1620
- demos/jupyterhub-pyspark-hdfs-anomaly-detection-taxi-data/Dockerfile
1721
- demos/jupyterhub-pyspark-hdfs-anomaly-detection-taxi-data/requirements.txt
@@ -30,7 +34,7 @@ jobs:
3034
# TODO: the image 3.5.0-stackable24.3.0 does not have an arm64 build.
3135
# Re-activate the arm runner when the image is updated to one that does.
3236
# Also adjust publish_manifest step to include arm architecture
33-
#- {name: "ubicloud-standard-8-arm", arch: "arm64"}
37+
# - {name: "ubicloud-standard-8-arm", arch: "arm64"}
3438
steps:
3539
- name: Checkout Repository
3640
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.env
1+
.env
2+
.envrc
3+
.direnv/

.scripts/update_refs.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# This script is used by the stackable-utils release script to update the demos
5+
# repository branch references as well as the stackableRelease versions so that
6+
# demos are properly versioned.
7+
8+
# Parse args:
9+
# $1 if `commit` is specified as the first argument, then changes will be staged and committed.
10+
COMMIT="${1:-false}"
11+
COMMIT="${COMMIT/commit/true}"
12+
13+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
14+
15+
# Ensure we are not on the `main` branch.
16+
if [[ "$CURRENT_BRANCH" == "main" ]]; then
17+
>&2 echo "Will not replace github references for the main branch. Exiting."
18+
exit 1
19+
fi
20+
21+
# Ensure the index is clean
22+
if ! git diff-index --quiet HEAD --; then
23+
>&2 echo "Dirty git index. Check working tree or staged changes. Exiting."
24+
exit 2
25+
fi
26+
27+
# prepend a string to each line of stdout
28+
function prepend {
29+
while read -r line; do
30+
echo -e "${1}${line}"
31+
done
32+
}
33+
34+
# stage and commit based on a message
35+
function maybe_commit {
36+
[ "$COMMIT" == "true" ] || return 0
37+
local MESSAGE="$1"
38+
PATCH=$(mktemp)
39+
git add -u
40+
git diff --staged > "$PATCH"
41+
git commit -S -m "$MESSAGE" --no-verify
42+
echo "patch written to: $PATCH" | prepend "\t"
43+
}
44+
45+
if [[ "$CURRENT_BRANCH" == release-* ]]; then
46+
STACKABLE_RELEASE="${CURRENT_BRANCH#release-}"
47+
MESSAGE="Update stackableRelease to $STACKABLE_RELEASE"
48+
echo "$MESSAGE"
49+
# NOTE (@NickLarsenNZ): find is not required for such a trivial case, but it is done for consitency
50+
find stacks/stacks-v2.yaml \
51+
-exec grep --color=always -l stackableRelease {} \; \
52+
-exec sed -i -E "s|(stackableRelease:\s+)(\S+)|\1${STACKABLE_RELEASE}|" {} \; \
53+
| prepend "\t"
54+
maybe_commit "chore(release): $MESSAGE"
55+
56+
# Replace 0.0.0-dev refs with ${STACKABLE_RELEASE}.0
57+
# TODO (@NickLarsenNZ): handle patches later, and what about release-candidates?
58+
SEARCH='stackable(0\.0\.0-dev|24\.7\.[0-9]+)' # TODO (@NickLarsenNZ): After https://github.com/stackabletech/stackable-cockpit/issues/310, only search for 0.0.0-dev
59+
REPLACEMENT="stackable${STACKABLE_RELEASE}.0" # TODO (@NickLarsenNZ): Be a bit smarter about patch releases.
60+
MESSAGE="Update image references with $REPLACEMENT"
61+
echo "$MESSAGE"
62+
find demos stacks -type f \
63+
-exec grep --color=always -lE "$SEARCH" {} \; \
64+
-exec sed -i -E "s|${SEARCH}|${REPLACEMENT}|" {} \; \
65+
| prepend "\t"
66+
maybe_commit "chore(release): $MESSAGE"
67+
68+
# Look for remaining references
69+
echo "Checking files with older stackable release references which will be assumed to be intentional."
70+
grep --color=always -ronE "stackable24\.3(\.[0-9]+)" | prepend "\t"
71+
echo
72+
else
73+
>&2 echo "WARNING: doesn't look like a release branch. Will not update stackableRelease versions in stacks and image references."
74+
fi
75+
76+
MESSAGE="Replace githubusercontent references main->${CURRENT_BRANCH}"
77+
echo "$MESSAGE"
78+
# Search for githubusercontent urls and replace the branch reference with a placeholder variable
79+
# This is done just in case the branch has special regex characters (like `/`).
80+
# shellcheck disable=SC2016 # We intentionally don't want to expand the variable.
81+
find demos stacks -type f \
82+
-exec grep --color=always -l githubusercontent {} \; \
83+
-exec sed -i -E 's|(stackabletech/demos)/main/|\1/\${UPDATE_BRANCH_REF}/|' {} \; \
84+
| prepend "\t"
85+
86+
# Now, for all modified files, we can use envsubst
87+
export UPDATE_BRANCH_REF="$CURRENT_BRANCH"
88+
for MODIFIED_FILE in $(git diff --name-only); do
89+
# shellcheck disable=SC2016 # We intentionally don't want to expand the variable.
90+
envsubst '$UPDATE_BRANCH_REF' < "$MODIFIED_FILE" > "$MODIFIED_FILE.replacements"
91+
mv "$MODIFIED_FILE.replacements" "$MODIFIED_FILE"
92+
done
93+
maybe_commit "chore(release): $MESSAGE"

.yamllint.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ rules:
88
comments:
99
min-spaces-from-content: 1 # Needed due to https://github.com/adrienverge/yamllint/issues/443
1010
braces: disable # because the yaml files are templates which can have {{ ... }}
11+
indentation: disable # There are many conflicting styles and it isn't so important in this repo. It can be enabled later if we want consistency.

demos/data-lakehouse-iceberg-trino-spark/create-trino-tables.yaml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -338,29 +338,6 @@ data:
338338
)
339339
""")
340340
341-
342-
343-
344-
345-
346-
347-
348-
349-
350-
351-
352-
353-
354-
355-
356-
357-
358-
359-
360-
361-
362-
363-
364341
run_query(connection, """
365342
create table if not exists lakehouse.house_sales.house_sales with (
366343
partitioning = ARRAY['year(date_of_transfer)']
@@ -504,23 +481,6 @@ data:
504481
where tpep_pickup_datetime >= date '2015-01-01' and tpep_pickup_datetime <= now() -- We have to remove some invalid records
505482
""")
506483
507-
508-
509-
510-
511-
512-
513-
514-
515-
516-
517-
518-
519-
520-
521-
522-
523-
524484
run_query(connection, """
525485
create or replace materialized view lakehouse.taxi.yellow_tripdata_daily_agg as
526486
select
@@ -566,11 +526,6 @@ data:
566526
REFRESH MATERIALIZED VIEW lakehouse.taxi.yellow_tripdata_monthly_agg
567527
""")
568528
569-
570-
571-
572-
573-
574529
# At this point Spark should have created the needed underlying tables
575530
run_query(connection, """
576531
create or replace view lakehouse.smart_city.shared_bikes_station_status_latest as

demos/demos-v1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
demos:
23
please-update:
34
description: This version of stackablectl is outdated, please visit https://docs.stackable.tech/stackablectl/stable/installation.html on how to get the latest version

demos/demos-v2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ demos:
7373
memory: 42034Mi
7474
pvc: 75Gi # 30Gi for Kafka
7575
nifi-kafka-druid-water-level-data:
76-
description: Demo ingesting water level data into Kafka using NiFi, streaming it into Druid and creating a Superset dashboard
76+
description: Demo ingesting water level data into Kafka using NiFi, streaming it into Druid and creating a Superset dashboard
7777
documentation: https://docs.stackable.tech/stackablectl/stable/demos/nifi-kafka-druid-water-level-data.html
7878
stackableStack: nifi-kafka-druid-superset-s3
7979
labels:

0 commit comments

Comments
 (0)