Skip to content

Commit

Permalink
Added example script integrated with commons
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Bogacz committed Oct 21, 2024
1 parent a4b0583 commit c4263ea
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ Although, this is project is just example, it can be used as template for Scala
It contains proposed code structure, testing, formatting, image builds and other.
List of such features is below table:

| Feature | Description | Link |
|------------------|----------------------------------------------------------------------------------------------------------------------|---------------------------------|
| Fast compilation | Bazel is caching all compiled parts and on recompile what is needed | [Cache](#cache) |
| Commons | You have code duplication across service? Or need to share common parts like models? This project shows how to do it | [Commons](#commons) |
| Fast tests | Bazel runs only tests that are needed | [Tests speed](#tests-speed) |
| Test separation | Different types of tests can be introduced to test in required ways | [Tests types](#tests-types) |
| Formatting | Required for devs, and tested on CI | [Formatting](#formatting) |
| Docker | Included creation of docker image for services | [Docker](#docker) |
| Feature | Description | Link |
|------------------|----------------------------------------------------------------------------------------------------------------------|-----------------------------|
| Fast compilation | Bazel is caching all compiled parts and on recompile what is needed | [Cache](#cache) |
| Commons | You have code duplication across service? Or need to share common parts like models? This project shows how to do it | [Commons](#commons) |
| Fast tests | Bazel runs only tests that are needed | [Tests speed](#tests-speed) |
| Test separation | Different types of tests can be introduced to test in required ways | [Tests types](#tests-types) |
| Formatting | Required for devs, and tested on CI | [Formatting](#formatting) |
| Docker | Included creation of docker image for services | [Docker](#docker) |
| Scripts | Scripts can be integrated into monorepo and use parts of implementation | [Scripts](#scripts) |
| CI | Simple PR build test | [CI](#ci) |

### Cache
Bazel is only rebuilding parts for application that were changed.
Expand Down Expand Up @@ -135,6 +137,23 @@ Push of image
bazel run //projects/service-1/src/main:push
```

## Scripts

Scripts can be embedded into monorepo. This makes possible to reuse existing code which reduces risk of scripts being outdated.
Execution (and compilation) of scripts is fast because, even with empty repo bazel will only compile what is needed to run script.

To execute example script use
```bash
bazel run //projects/scripts:manualInit -- myArg1 myArg2
```

Check [scripts readme](projects/scripts/README.md) to get more details.

## CI

This repository also contains simple pull request check [pr.yml](.github/workflows/pr.yml)
To make it faster, it also uses persistent cache.

## Multilanguage
Despite this repository is not providing example for many languages, it's possible to incorporate many languages in one project.
For example in this project I could add frontend or microservices in many languages (GoLang, Java, C++....).
8 changes: 8 additions & 0 deletions projects/scripts/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
scala_binary(
name = "manualInit",
main_class = "projects.scripts.src.main.scala.com.org.manual_init.ManualInit",
visibility = ["//visibility:public"],
deps = [
"//projects/scripts/src/main/scala/com/org/manual_init:manualInit",
],
)
7 changes: 7 additions & 0 deletions projects/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Scripts

Scripts can depend on any part of monorepo. In this example they depend on `commons`
You need in script part of service? Access to DB with real code repository? It can be easily done.

File [BUILD.bazel](BUILD.bazel) can contain many `scala_binary` to easier reference additional scrips.
Structure of scripts might look strange, but it shows that Bazel does not restrict your decision on how you organize code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
scala_library(
name = "manualInit",
srcs = glob(["**/*.scala"]),
visibility = ["//visibility:public"],
deps = [
"//projects/commons/init-log/src/main:init-log",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package projects.scripts.src.main.scala.com.org.manual_init

import com.org.initlog.Init

object ManualInit {

def main(args: Array[String]): Unit = {
println(s"SCRIPT> Starting with args: ${args.mkString("(", ", ", ")")}")
println(s"SCRIPT> Message from service init: ${Init.message}")
}
}
7 changes: 7 additions & 0 deletions projects/scripts/src/main/scala/com/org/manual_init/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Example script
Shows how easy can be integration with other parts of monorepo

This example script also shows how to pass args
```bash
bazel run //projects/scripts:manualInit -- myArg1 myArg2
```

0 comments on commit c4263ea

Please sign in to comment.