-
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
Igor Stepin
committed
Aug 7, 2024
1 parent
58303d9
commit 9fef0fa
Showing
48 changed files
with
1,880 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,4 @@ | ||
/bin | ||
.gradle | ||
.git | ||
.idea |
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,14 @@ | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 120 | ||
tab_width = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[{*.gradle.kts,*.kt,*.kts,*.main.kts,*.space.kts}] | ||
ij_kotlin_allow_trailing_comma = true | ||
ij_kotlin_allow_trailing_comma_on_call_site = true | ||
ktlint_standard_no-wildcard-imports = disabled |
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 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
/dist | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Kotlin ### | ||
.kotlin | ||
|
||
# OSX | ||
.DS_Store | ||
|
||
# Vim | ||
*.swp | ||
*.swo | ||
|
||
# patch | ||
*.orig | ||
*.rej | ||
|
||
# Local environment | ||
.env | ||
|
||
/tmp |
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 @@ | ||
# NOTE: Native-platform is not available on Linux with musl libc (for alpine even gcompat package don't help) | ||
FROM gradle:8.9.0-jdk21 AS build | ||
|
||
RUN apt-get update && apt-get -y --no-install-recommends install \ | ||
build-essential | ||
|
||
COPY . /src | ||
WORKDIR /src | ||
|
||
RUN \ | ||
--mount=type=cache,target=/src/.gradle,rw \ | ||
--mount=type=cache,target=/src/bin/build,rw \ | ||
--mount=type=cache,target=/home/gradle/.gradle,rw \ | ||
gradle --debug linkReleaseExecutableNative | ||
|
||
RUN ln -sn linuxX64 build/bin/linux-amd64 && \ | ||
ln -sn linuxArm64 build/bin/linux-arm64 | ||
|
||
FROM ubuntu:22.04 | ||
|
||
COPY --from=build build/bin/linux-${TARGETARCH}/releaseExecutable/kbre.kexe /kbre | ||
|
||
ENTRYPOINT ["/kbre"] |
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,6 @@ | ||
FROM ubuntu:22.04 | ||
ARG TARGETARCH | ||
|
||
COPY build/bin/linux-${TARGETARCH}/releaseExecutable/kbre.kexe /kbre | ||
|
||
ENTRYPOINT ["/kbre"] |
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,122 @@ | ||
# Kotlin Build Rules Enforcer | ||
|
||
## Why | ||
|
||
If you try to use https://start.spring.io/ , https://kmp.jetbrains.com/ , https://start.ktor.io/ , | ||
or https://code.quarkus.io/ you will find out that: | ||
|
||
1. it's not enough -- a lot of things needs to be configured after download | ||
2. it's hard to update: update is done only manually | ||
|
||
It's clear that for each company / team / individual templates should be different. | ||
That's why https://github.com/stepin/kbre-default-config is done as starting point, | ||
but you need to adapt it according to your preferences. | ||
|
||
kbre tool uses your templates to create and update repos. | ||
|
||
kbre started as Gradle macros tool, but now it doesn't depend on Gradle at all and can be used with any language. | ||
|
||
## How to use | ||
|
||
Configuration (it's even better to fork that repository and use your own from the beginning): | ||
```shell | ||
cd ~ | ||
git clone https://github.com/stepin/kbre-default-config .krbe | ||
``` | ||
|
||
Create new Spring app: | ||
```shell | ||
mkdir my-app | ||
cd my-app | ||
|
||
cat > kbre.yaml << \EOF | ||
group: name.stepin | ||
artifact: myapp | ||
name: My app | ||
description: Some description | ||
preset: spring | ||
type: root | ||
extensions: | ||
- graphql | ||
- postgres | ||
- flyway | ||
- jooq | ||
- dokka | ||
- jib | ||
- local-dev | ||
- systemd-deployment | ||
variables: | ||
REPO: http://localhost:3000/stepin/kotlin-bootstrap-app/src/branch/main/src/main/kotlin | ||
SONAR_HOST_URL: http://localhost:9000 | ||
SONAR_PROJECT_KEY: kotlin-bootstrap-app | ||
SONAR_PROJECT_NAME: kotlin-bootstrap-app | ||
SONAR_TOKEN: sqp_821b1d3209761625bdd29259674237d429bce626 | ||
EOF | ||
|
||
alias kbre='docker run --rm -it -v $PWD:/data -w /data --user "$(id -u)" stepin/kbre' | ||
kbre version | ||
|
||
kbre new | ||
``` | ||
|
||
Update (when config repo or kbre.yaml are changed): | ||
```shell | ||
cd my-app | ||
|
||
kbre update | ||
``` | ||
|
||
## Configuration dir description | ||
|
||
Top-level folders are `presets`. It's like template when you create new project in IDE. Currently, there are 3: | ||
- `cli` for Kotlin console apps | ||
- `spring` for Kotlin web apps | ||
- `script` for Kotlin scripts | ||
|
||
Next, `type` should be selected. It's main template files. Default is `root`. It's for root project. If you have | ||
subprojects most probably you will need other type for it. | ||
|
||
`Extension` is most powerful concept. First of all, you can just copy with replaced variables any files. There is also | ||
special meaning for following files: | ||
- `gradle/libs.versions.toml` -- it will be merged with `gradle/libs.versions.toml` from `type` | ||
- `imports.kts` -- it will be added to `%IMPORTS%` variable | ||
- `plugins.kts` -- it will be added to `%PLUGINS%` variable | ||
- `deps.kts` -- it will be added to `%DEPS%` variable | ||
- `body.kts` -- it will be added to `%BODY%` variable | ||
|
||
`Variable` is key/value. They are defined in kbre.yaml file and there are some pre-defined variable. In addition | ||
to variables from extensions following variables are defined: | ||
- `%PRESET%` -- preset | ||
- `%TYPE%` -- type | ||
- `%GROUP%` -- maven's group | ||
- `%ARTIFACT%` -- in a lot of places used as binary name | ||
- `%NAME%` -- some human app name | ||
- `%DESCRIPTION%` -- human app description | ||
|
||
|
||
## Status | ||
|
||
Current status: works for me. I use it for all projects. | ||
|
||
Feel free to file bug reports. If I will be able to reproduce it I will fix it. | ||
|
||
About new features: it's better to send PRs, not just ideas (as I already have ideas but limited time). | ||
|
||
Some ideas: | ||
- add variables to the path / filenames -- it should be easy, I just don't need it | ||
- create krbe.yaml file on `krbe new` command | ||
- add `krbe init` action for interactive creation of project (like in Poetry) | ||
- add web version | ||
- add brew tap | ||
|
||
|
||
## Limitations | ||
|
||
- it's unclear how to set up unit tests for Kotlin Native properly | ||
- maybe support of `libs.versions.toml` has problems in some corner cases: it's interesting to have examples | ||
- it's unclear how to build Kotlin Native in Docker: in all cases it's not working for me (but maybe it's ram limitation, unclear). There is ticket about it: https://youtrack.jetbrains.com/issue/KT-39895/Missing-Documentation-On-Using-Kotlin-Native-With-Docker . | ||
So, for now, binaries are just added to Docker image. | ||
- binary files detection is really simple now | ||
- Alpine is not supported as Kotlin compiler don't work with `musl libc`. Even `gcompat` package don't fix it (most probably some detection problem). | ||
- Kotlin Native compiler is not available for Linux ARM, only for macOS ARM. So, no ARM docker images. Missing file: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.0.0/kotlin-native-prebuilt-2.0.0-linux-aarch64.tar.gz | ||
It means that we need to compile binaries on 1 supported arch, then add them into docker images. |
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,14 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
cd "$(dirname "$0")" | ||
set -x | ||
|
||
cd .. | ||
|
||
VERSION=$(git describe --tags --always) | ||
IMAGE_LATEST="stepin/kbre" | ||
IMAGE="$IMAGE_LATEST:$VERSION" | ||
|
||
# NOTE: Kotlin Native is not available for Linux ARM, only for macOS ARM. Missing file: | ||
# https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.0.0/kotlin-native-prebuilt-2.0.0-linux-aarch64.tar.gz | ||
docker build --platform linux/amd64 . -t "$IMAGE" -t "$IMAGE_LATEST" |
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,12 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
cd "$(dirname "$0")" | ||
set -x | ||
|
||
cd .. | ||
|
||
VERSION=$(git describe --tags --always) | ||
IMAGE_LATEST="stepin/kbre" | ||
IMAGE="$IMAGE_LATEST:$VERSION" | ||
|
||
docker build --platform linux/amd64,linux/arm64 -f Dockerfile.embed . -t "$IMAGE" -t "$IMAGE_LATEST" |
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,7 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -eEuo pipefail | ||
|
||
cd .. | ||
|
||
kbre update |
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,7 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -xeEuo pipefail | ||
|
||
cd .. | ||
|
||
./gradlew ktlintFormat |
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,55 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
cd "$(dirname "$0")" | ||
|
||
cd .. | ||
|
||
VERSION=$(git describe --tags --always) | ||
IMAGE_LATEST="stepin/kbre" | ||
IMAGE="$IMAGE_LATEST:$VERSION" | ||
|
||
cp build.gradle.kts build.gradle.kts.orig | ||
sed "s/1.0-SNAPSHOT/$VERSION/g" build.gradle.kts.orig > build.gradle.kts | ||
|
||
cp src/nativeMain/kotlin/name/stepin/cli/VersionCmd.kt src/nativeMain/kotlin/name/stepin/cli/VersionCmd.kt.orig | ||
sed "s/SNAPSHOT/$VERSION/g" src/nativeMain/kotlin/name/stepin/cli/VersionCmd.kt.orig > src/nativeMain/kotlin/name/stepin/cli/VersionCmd.kt | ||
|
||
./gradlew build | ||
|
||
rm -rf ./dist || true | ||
mkdir ./dist | ||
|
||
mkdir ./dist/linuxX64 | ||
cp LICENSE README.md ./dist/linuxX64/ | ||
cp build/bin/linuxX64/releaseExecutable/kbre.kexe ./dist/linuxX64/kbre | ||
pushd ./dist/linuxX64 | ||
zip -9 ../kbre-linuxX64.zip * | ||
popd | ||
|
||
mkdir ./dist/linuxArm64 | ||
cp LICENSE README.md ./dist/linuxArm64/ | ||
cp build/bin/linuxArm64/releaseExecutable/kbre.kexe ./dist/linuxArm64/kbre | ||
pushd ./dist/linuxArm64 | ||
zip -9 ../kbre-linuxArm64.zip * | ||
popd | ||
|
||
mkdir ./dist/macosX64 | ||
cp LICENSE README.md ./dist/macosX64/ | ||
cp build/bin/macosX64/releaseExecutable/kbre.kexe ./dist/macosX64/kbre | ||
pushd ./dist/macosX64 | ||
zip -9 ../kbre-macosX64.zip * | ||
popd | ||
|
||
mkdir ./dist/macosArm64 | ||
cp LICENSE README.md ./dist/macosArm64/ | ||
cp build/bin/macosArm64/releaseExecutable/kbre.kexe ./dist/macosArm64/kbre | ||
pushd ./dist/macosArm64 | ||
zip -9 ../kbre-macosArm64.zip * | ||
popd | ||
|
||
[[ ! -h build/bin/linux-amd64 ]] && ln -sn linuxX64 build/bin/linux-amd64 | ||
[[ ! -h build/bin/linux-arm64 ]] && ln -sn linuxArm64 build/bin/linux-arm64 | ||
docker buildx create --use | ||
docker buildx build --push --platform linux/amd64,linux/arm64 -f Dockerfile.embed . -t "$IMAGE" -t "$IMAGE_LATEST" | ||
|
||
./bin/update-local-installation |
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,9 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
cd "$(dirname "$0")" | ||
|
||
cd .. | ||
|
||
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.2.2 releaseVersion | ||
echo | ||
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.2.2 releaseNotes |
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,18 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -eEuo pipefail | ||
|
||
cd .. | ||
|
||
set -a | ||
[[ -f .env ]] && source .env | ||
set +a | ||
|
||
rm -rf ./tmp || true | ||
mkdir ./tmp | ||
|
||
./build/bin/macosArm64/debugExecutable/kbre.kexe \ | ||
--verbose \ | ||
update --target-path ./tmp \ | ||
--templates-path /Users/stepin/my/opensource/kbre-default-config \ | ||
--config ./kbre.yaml |
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,11 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -eEuo pipefail | ||
|
||
cd .. | ||
|
||
set -a | ||
[[ -f .env ]] && source .env | ||
set +a | ||
|
||
./build/bin/macosArm64/releaseExecutable/kbre.kexe "$@" |
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,9 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -xeEuo pipefail | ||
|
||
docker run --rm -i \ | ||
-v $PWD:/data \ | ||
-w /data \ | ||
--user "$(id -u)" \ | ||
stepin/kbre "$@" |
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,8 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -xeEuo pipefail | ||
|
||
cd .. | ||
|
||
export SONAR_SCANNER_OPTS="-Xmx512m" | ||
./gradlew sonar |
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,5 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -eEuo pipefail | ||
|
||
cp ../build/bin/macosArm64/debugExecutable/kbre.kexe ~/.bin/kbre |
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,7 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$0")" | ||
set -xeEuo pipefail | ||
|
||
cd .. | ||
|
||
./gradlew macosArm64Binaries |
Oops, something went wrong.