generated from creek-service/basic-kafka-streams-demo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 43e21d6
Showing
103 changed files
with
4,708 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/bin/zsh | ||
# | ||
# Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
# | ||
# Licensed 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. | ||
# | ||
|
||
# Script for adding a new service module to the repo. | ||
# Usage: | ||
# add_Service.sh serviceName | ||
|
||
if [[ $(echo "ab-cd" | sed 's/-\([a-z]\)/\U\1/g') != "abCd" ]]; then | ||
echo "ERROR: incompatible version of sed detected." >&2 | ||
echo "If on Mac, 'brew install gnu-sed' and add to path" >&2 | ||
exit 1 | ||
fi | ||
|
||
creekDir=${0:A:h} | ||
serviceName=$1 | ||
|
||
if [ -f "$creekDir/bootstrap.sh" ]; then | ||
echo "bootstrap.sh has not run yet. Re-run once bootstrapping is complete." >&2 | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$serviceName" ] | ||
then | ||
echo "serviceName can not be blank" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo Prepare | ||
find . -type d -empty -delete | ||
|
||
if [ -d "$serviceName" ]; then | ||
echo "module already exists" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ "$serviceName" = "example-service" ]] | ||
then | ||
echo "serviceName can not be 'example-service'." >&2 | ||
exit 1 | ||
fi | ||
|
||
if ! [[ "$serviceName" =~ ^[0-9a-z]+[0-9a-z-]*[0-9a-z]+$ ]] | ||
then | ||
echo "invalid serviceName. Only lowercase alpha-numerics and dashes allowed. Can not start or end in dash. serviceName: '$serviceName'." >&2 | ||
exit 1 | ||
fi | ||
|
||
serviceClass=$(echo "$serviceName" | sed 's/-\([a-z]\)/\U\1/g' | sed 's/^\([a-z]\)/\U\1/')Descriptor | ||
serviceDotName=$(echo "$serviceName" | sed 's/-/./g') | ||
rootPackage=$(<.creek/service_template/root.package) | ||
|
||
# sedCode(sedCmd) | ||
function sedCode() { | ||
find . -type f -not \( -path "*/.git/*" -o -path "*/build/*" -o -path "*/.gradle/*" -o -path "*/.creek/*" \) -print0 | xargs -0 sed -i "$1" | ||
} | ||
|
||
# replaceInCode(text-to-replace, replacement) | ||
function replaceInCode() { | ||
sedCode "s/$1/$2/g" | ||
} | ||
|
||
# renamePackage(old-pkg-name, new-pkg-name) | ||
function renamePackage() { | ||
# Update code: | ||
replaceInCode "$(echo "$1" | sed 's/\./\\./g')\." "$2." | ||
|
||
# Move code: | ||
oldBasePattern=$(echo "$1" | sed 's/\./\\\//g') | ||
oldBaseDir=$(echo "$1" | sed 's/\./\//g') | ||
newBaseDir=$(echo "$2" | sed 's/\./\//g') | ||
|
||
find . -type f -path "*$oldBaseDir*" -not \( -path "*/.git/*" -o -path "*/build/*" -o -path "*/.gradle/*" -o -path "*/.creek/*" \) -exec bash -c ' | ||
newPath=${3/$1/$0} | ||
mkdir -p "$(dirname $newPath)" | ||
mv "$3" "$newPath" | ||
' "$newBaseDir" "$oldBasePattern" "$oldBaseDir" {} \; | ||
} | ||
|
||
echo "Creating $serviceClass" | ||
cp -R "$creekDir/service_template/services" "./" | ||
|
||
find . -type f -name "ExampleServiceDescriptor.java" -not \( -path "*/.git/*" -o -path "*/.gradle/*" -o -path "*/.creek/*" \) -exec bash -c ' | ||
newPath="${0/ExampleServiceDescriptor/$1}"; | ||
mv "$0" "$newPath" | ||
' {} "$serviceClass" \; | ||
|
||
echo "Registering $serviceClass" | ||
|
||
if ! grep -q "ComponentDescriptor with" "services/src/main/java/module-info.java"; then | ||
sed -i "s/}/ provides org.creekservice.api.platform.metadata.ComponentDescriptor with\n\t\t$rootPackage.services.$serviceClass;\n}/g" "services/src/main/java/module-info.java" | ||
else | ||
sed -i "s/ComponentDescriptor with/ComponentDescriptor with\n\t\t$rootPackage.services.$serviceClass,/g" "services/src/main/java/module-info.java" | ||
fi | ||
|
||
echo "\n$rootPackage.services.$serviceClass" >> services/src/main/resources/META-INF/services/org.creekservice.api.platform.metadata.ComponentDescriptor | ||
|
||
echo "Creating $serviceName module" | ||
|
||
cp -R "$creekDir/service_template/example-service" "$serviceName" | ||
replaceInCode "example\.service" "$serviceDotName" | ||
replaceInCode "example-service" "$serviceName" | ||
replaceInCode "ExampleServiceDescriptor" "$serviceClass" | ||
|
||
echo "Updating service root package to: $rootPackage.$serviceDotName" | ||
renamePackage "$rootPackage.example.service" "$rootPackage.$serviceDotName" | ||
|
||
echo adding new service module to settings.gradle.kts | ||
sed -i "s/include(/include(\n \"$serviceName\",/g" settings.gradle.kts | ||
|
||
echo "adding new service's Docker image to Dependabot" | ||
echo "\n - package-ecosystem: docker | ||
directory: /$serviceName | ||
schedule: | ||
interval: monthly" >> .github/dependabot.yml | ||
|
||
echo Tidy up | ||
find . -type f -name "Keep.java" -not \( -path "*/.git/*" -o -path "*/.gradle/*" \) -exec rm {} \; | ||
find . -type d -empty -delete | ||
./gradlew format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/bin/zsh | ||
# | ||
# Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
# | ||
# Licensed 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. | ||
# | ||
|
||
# Script for updating repositories created from the template. | ||
# Usage: | ||
# bootstrap.sh repoUserAndName repoUser | ||
|
||
if [[ $(echo "ab-cd" | sed 's/-\([a-z]\)/\U\1/g') != "abCd" ]]; then | ||
echo "ERROR: incompatible version of sed detected." >&2 | ||
exit 1; | ||
fi | ||
|
||
repoUserAndName="$1" | ||
repoUser="$2" | ||
repoName="${repoUserAndName/${repoUser}\//}" | ||
aggregateClass=$(echo "${(L)${repoName}}" | sed 's/\([-_]\)\([a-z]\)/\U\2/g' | sed 's/^\([a-z]\)/\U\1/')AggregateDescriptor | ||
modNamePrefix=${(L)${repoName//([_-])/.}} | ||
groupName="io.github.${(L)${repoUser//([_-])/.}}" | ||
rootPackage="$groupName.$modNamePrefix" | ||
|
||
# sedCode(sedCmd) | ||
function sedCode() { | ||
find . -type f -not \( -path "*/.git/*" -o -path "*/build/*" -o -path "*/.gradle/*" \) -print0 | xargs -0 sed -i "$1" | ||
} | ||
|
||
# replaceInCode(text-to-replace, replacement) | ||
function replaceInCode() { | ||
sedCode "s:$1:$2:g" | ||
} | ||
|
||
# renamePackage(old-pkg-name, new-pkg-name) | ||
function renamePackage() { | ||
# Update code: | ||
replaceInCode "$(echo "$1" | sed 's/\./\\./g')\." "$2." | ||
|
||
# Move code: | ||
oldBasePattern=$(echo "$1" | sed 's/\./\\\//g') | ||
oldBaseDir=$(echo "$1" | sed 's/\./\//g') | ||
newBaseDir=$(echo "$2" | sed 's/\./\//g') | ||
|
||
find . -type f -path "*$oldBaseDir*" -not \( -path "*/.git/*" -o -path "*/build/*" -o -path "*/.gradle/*" \) -exec bash -c ' | ||
newPath=${3/$1/$0} | ||
mkdir -p "$(dirname $newPath)" | ||
mv "$3" "$newPath" | ||
' "$newBaseDir" "$oldBasePattern" "$oldBaseDir" {} \; | ||
} | ||
|
||
echo Prepare | ||
rm -rf docs | ||
find . -type d -empty -delete | ||
|
||
if [ "$repoUser" != "creek-service" ]; then | ||
echo "Updating repo user to $repoUser" | ||
replaceInCode "maven.pkg.github.com/creek-service/" "maven.pkg.github.com/$repoUser/" | ||
replaceInCode "ghcr.io/creek-service/" "ghcr.io/${repoUser:l}/" | ||
replaceInCode "github.com/creek-service/" "github.com/$repoUser/" | ||
fi | ||
|
||
echo "Updating repo name to: $repoName" | ||
replaceInCode "creek-service/basic-kafka-streams-demo" "$repoUserAndName" | ||
replaceInCode "basic-kafka-streams-demo" "${(L)${repoName}}" | ||
|
||
echo "Updating aggregate descriptor to: $aggregateClass" | ||
replaceInCode "BasicKafkaStreamsDemoAggregateDescriptor" "$aggregateClass" | ||
mv "api/src/main/java/io/github/creek/service/basic/kafka/streams/demo/api/BasicKafkaStreamsDemoAggregateDescriptor.java" "api/src/main/java/io/github/creek/service/basic/kafka/streams/demo/api/$aggregateClass.java" | ||
|
||
echo "Updating root packages to: $rootPackage" | ||
renamePackage "io.github.creek.service.basic.kafka.streams.demo" "$rootPackage" | ||
|
||
echo "Updating group name to: $groupName" | ||
replaceInCode "group = \"io.github.creek.service\"" "group = \"$groupName\"" | ||
|
||
echo "Updating module names to have prefix: $modNamePrefix" | ||
replaceInCode "basic.kafka.streams.demo" "$modNamePrefix" | ||
|
||
echo Update service module template | ||
echo "$rootPackage" > ".creek/service_template/root.package" | ||
|
||
echo Revert workflow changes | ||
# Changing workflows requires elevated privileges, only available via a PAT: | ||
# So revert changes: | ||
git checkout -- ".github/workflows/*" | ||
|
||
echo Tidying up | ||
rm ./.creek/bootstrap.sh | ||
rm .github/CODEOWNERS | ||
find . -type d -empty -delete | ||
./gradlew format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM amazoncorretto:19@sha256:a197d796640268bd6fcb74507f92efe69274b2c13de63ee36a07c25058d4bd3f | ||
ARG APP_NAME | ||
ARG APP_VERSION | ||
ENV VERSION=$APP_VERSION | ||
|
||
LABEL org.opencontainers.image.source=https://github.com/creek-service/basic-kafka-streams-demo/tree/main/example-service | ||
|
||
RUN yum update -y | ||
RUN yum install -y tar lsof | ||
|
||
RUN mkdir -p /opt/creek | ||
|
||
COPY bin /bin | ||
COPY log4j /log | ||
|
||
COPY ${APP_NAME}-${APP_VERSION}.tar /opt/creek | ||
WORKDIR /opt/creek | ||
RUN tar xf ${APP_NAME}-${APP_VERSION}.tar | ||
RUN ln -s ${APP_NAME}-${APP_VERSION} service | ||
|
||
ENTRYPOINT ["/bin/run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage | ||
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage | ||
|
||
plugins { | ||
application | ||
id("com.bmuschko.docker-remote-api") | ||
} | ||
|
||
val creekVersion : String by extra | ||
val kafkaVersion : String by extra | ||
val log4jVersion : String by extra | ||
|
||
dependencies { | ||
implementation(project(":services")) | ||
implementation("org.creekservice:creek-service-context:$creekVersion") | ||
implementation("org.creekservice:creek-kafka-streams-extension:$creekVersion") | ||
implementation("org.apache.logging.log4j:log4j-core:$log4jVersion") | ||
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:$log4jVersion") | ||
|
||
testImplementation("org.creekservice:creek-kafka-streams-test:$creekVersion") | ||
} | ||
|
||
// Patch Kafka Streams test jar into main Kafka Streams module to avoid split packages: | ||
modularity.patchModule("kafka.streams", "kafka-streams-test-utils-$kafkaVersion.jar") | ||
|
||
application { | ||
mainModule.set("basic.kafka.streams.demo.example.service") | ||
mainClass.set("io.github.creek.service.basic.kafka.streams.demo.example.service.ServiceMain") | ||
} | ||
|
||
val buildAppImage = tasks.register<DockerBuildImage>("buildAppImage") { | ||
dependsOn("prepareDocker") | ||
buildArgs.put("APP_NAME", project.name) | ||
buildArgs.put("APP_VERSION", "${project.version}") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:latest") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:${project.version}") | ||
} | ||
|
||
tasks.register<Copy>("prepareDocker") { | ||
dependsOn("distTar") | ||
|
||
from( | ||
layout.projectDirectory.file("Dockerfile"), | ||
layout.buildDirectory.file("distributions/${project.name}-${project.version}.tar"), | ||
layout.projectDirectory.dir("include"), | ||
) | ||
|
||
into(buildAppImage.get().inputDir) | ||
} | ||
|
||
tasks.register<DockerPushImage>("pushAppImage") { | ||
dependsOn("buildAppImage") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:latest") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:${project.version}") | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
.creek/service_template/example-service/include/bin/run.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
# | ||
# Licensed 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. | ||
# | ||
|
||
exec java \ | ||
-Xms64m -Xmx256m \ | ||
-Dlog4j.configurationFile=/log/log4j2.xml \ | ||
--module-path "/opt/creek/service/lib" \ | ||
--module basic.kafka.streams.demo.example.service/io.github.creek.service.basic.kafka.streams.demo.example.service.ServiceMain |
38 changes: 38 additions & 0 deletions
38
.creek/service_template/example-service/include/log4j/log4j2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
~ | ||
~ Licensed 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. | ||
--> | ||
|
||
<Configuration status="WARN"> | ||
<Appenders> | ||
<Console name="console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="org.creekservice" level="DEBUG" additivity="false"> | ||
<AppenderRef ref="console"/> | ||
</Logger> | ||
<Logger name="kafka" level="info" additivity="false"> | ||
<AppenderRef ref="console"/> | ||
</Logger> | ||
<Logger name="org.apache.kafka" level="info" additivity="false"> | ||
<AppenderRef ref="console"/> | ||
</Logger> | ||
<Root level="INFO"> | ||
<AppenderRef ref="console"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
Oops, something went wrong.