add base cmd
This commit is contained in:
@@ -1,208 +0,0 @@
|
||||
# Pipelines design docs
|
||||
|
||||
The goal of this experiment is to play with various code sharing features. The
|
||||
pipelines in this experiment is supposed to model normal code sharing behavior
|
||||
of libraries, with overriding capabilities of the downstream repository
|
||||
|
||||
The goal is to split the body of the work in three parts.
|
||||
|
||||
- libraries,
|
||||
- compendiums
|
||||
- articles
|
||||
|
||||
The terminology is as such:
|
||||
|
||||
## Libraries
|
||||
|
||||
Libraries provide raw functions, and is a general abstraction on an underlying
|
||||
process, such as running a container, executing a shell script etc. Libraries
|
||||
might define an API descripting how to interact with it. It is up to the
|
||||
compendium, and article to use these in a sane manner.
|
||||
|
||||
Such that:
|
||||
|
||||
```rust
|
||||
pub fn execute_shell(&self, input: &ShellOpts) -> Result<ShellOutput> {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
These work similar to raw primitive functions, but should serve as an
|
||||
opinionated flyweight. These may be extremely specific, such as building a go
|
||||
binary, creating a github release etc. The details are left to the caller.
|
||||
|
||||
A version scheme of the library should follow semver, as that is the best model
|
||||
at the moment for versioning. Libraries should be pulled using the native
|
||||
package manager, or include as a submodule.
|
||||
|
||||
## Compendiums
|
||||
|
||||
A compendium is an opinionated collection of libraries, which consists of files,
|
||||
configurations etc. A compendium is to be used by either other compendiums, or
|
||||
articles. They are not to be used by libraries, this is to provide a natural
|
||||
hierachy. The end result should be a directed acyclic graph.
|
||||
|
||||
A compendium should provide an API for either other compendiums, or articles.
|
||||
These apis, need to remain flexible, and be open to mutations. As such all
|
||||
primitive features, files, configurations need to be exposed as raw data or data
|
||||
structures if suitable.
|
||||
|
||||
This is done using pipelines, or middleware for the specific parts. A data
|
||||
object will pass from above, containing the data to implement the required
|
||||
interfaces of the Compendium, these must be fulfilled for the construction of
|
||||
the Compendium, else the compilation should fail.
|
||||
|
||||
The caller will have the ability to replace the specifics of the Compendium, by
|
||||
replacing certain pipelines, or mutating the data. In case of mutations, the
|
||||
data is only modified for that pipeline and below, if a fork occurs above, then
|
||||
the divergent paths won't be affected.
|
||||
|
||||
Compendiums are driven by pipelines applied to them either from other
|
||||
compendiums or articles. An article or compendium will only have access to their
|
||||
direct dependent compendiums pipelines. An article will naturally expose
|
||||
pipelines to be called by the user.
|
||||
|
||||
```rust
|
||||
pub struct GoApplication;
|
||||
|
||||
impl Compendium for GoApplication {
|
||||
type Input = GoApplicationOpts;
|
||||
|
||||
pub fn get_pipelines(&mut self) -> Result<Pipelines> {
|
||||
let pipelines = self.pipelines
|
||||
.clone()
|
||||
.add(self.get_application_pipelines())?
|
||||
.add(self.get_go_releaser_pipelines())?;
|
||||
|
||||
Ok(pipelines)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Articles
|
||||
|
||||
An article is a specific implementation of a compendium, it is the end of the
|
||||
chain, and is meant to be directly executed by the user, using a client
|
||||
application.
|
||||
|
||||
It by default is supposed to be a golden path, I.e. it passes the defaults of
|
||||
the Compendium, but on a case-by-case basis has the ability to modify its
|
||||
pipelines to its needs. This may be changing certain default configurations,
|
||||
mutate a dockerfile, add additional steps to a pipeline etc, and remove others.
|
||||
|
||||
We reason that once you stray from the golden path, you should be in control,
|
||||
this may be done by forking the compendium's features.
|
||||
|
||||
It provides pipelines as actions, and implements a strict protocol for
|
||||
communication.
|
||||
|
||||
```rust
|
||||
pub struct MyGoService;
|
||||
|
||||
impl Article for MyGoService {
|
||||
|
||||
fn get_pipelines(&mut self) -> Result<Pipelines> {
|
||||
let mut go_pipelines = GoApplication::new().get_pipelines()?;
|
||||
let api_pipeline = self.get_api_pipeline()?;
|
||||
let build_pipeline = self.get_docker_pipeline(go_pipelines.extract::<BuildPipeline>()?)?;;
|
||||
|
||||
let pipelines = PipelineBuilder::new()
|
||||
.append(go_pipelines)
|
||||
.append(api_pipeline)
|
||||
.append(build_pipeline)
|
||||
.build()?
|
||||
|
||||
Ok(pipelines)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
A host app can now call these:
|
||||
|
||||
```bash
|
||||
char ls
|
||||
```
|
||||
|
||||
ls simply displays the information on what pipeline are available
|
||||
|
||||
```bash
|
||||
char run build
|
||||
```
|
||||
|
||||
run build will execute the pipeline build. It will validate input available from
|
||||
char.toml, push these keys/values through to the pipeline, which will go through
|
||||
all the steps.
|
||||
|
||||
- build
|
||||
- MyGoService
|
||||
- DockerBuildPipeline
|
||||
- (BuildPipeline)
|
||||
- DockerLibrary
|
||||
- `fn docker_build(dockerfile_contents: string)`
|
||||
- Native dependencies
|
||||
- "write dockerfile /tmp/abc/dockerfile"
|
||||
- "shell -> docker build -f /tmp/abc/dockerfile some-library-path"
|
||||
|
||||
## Common scenarios
|
||||
|
||||
### Replacing parts of a build script (dockerfile)
|
||||
|
||||
A compendium may embed/provide a dockerfile or any other resource, these are
|
||||
provided through consistent interfaces.
|
||||
|
||||
```rust
|
||||
pub struct GoDockerBuildPipeline;
|
||||
|
||||
impl GoDockerBuildPipeline {
|
||||
fn get_resources(&self) -> Result<(
|
||||
libraries::docker::DockerContents,
|
||||
libraries::docker::DockerBuildTags)> {
|
||||
return (self.contents, self.build_tags)
|
||||
}
|
||||
|
||||
fn mutate_resources(
|
||||
&mut self,
|
||||
contents: libraries::docker::DockerContents,
|
||||
build_tags: libraries::docker::DockerBuildTags,
|
||||
) -> Result<()> {
|
||||
self.contents = contents;
|
||||
self.build_tags = build_tags
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildPipeline for GoDockerBuildPipeline {
|
||||
fn execute(&mut self, config: Configuration) -> Result<()> {
|
||||
let (docker_contents, base_tags) = self.get_resources()
|
||||
libraries::docker::build(docker_contents, base_tags, config)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the article you can now replace the resources to fit your needs, that or
|
||||
building your own pipeline.
|
||||
|
||||
```rust
|
||||
pub struct MyGoService;
|
||||
|
||||
impl Article for MyGoService {
|
||||
|
||||
fn get_pipelines(&mut self) -> Result<Pipelines> {
|
||||
let go_app = GoApplication::new();
|
||||
let go_pipelines = go_app.get_pipelines();
|
||||
|
||||
let mut go_build_pipeline = go_pipelines.get_pipeline::<GoDockerBuildPipeline>()?;
|
||||
let go_resources = go_build_pipeline.get_resources()?;
|
||||
let go_resources = self.mutate_go_resources(&go_resources)?;
|
||||
go_build_pipeline.mutate_resources(go_resources)?;
|
||||
go_pipelines.replace::<GoDockerBuildPipeline>(go_build_pipeline)?;
|
||||
|
||||
let pipelines = PipelineBuilder::new()
|
||||
.append(.get_pipelines())
|
||||
.build()?
|
||||
|
||||
Ok(pipelines)
|
||||
}
|
||||
}
|
||||
```
|
55
examples/service/char.toml
Normal file
55
examples/service/char.toml
Normal file
@@ -0,0 +1,55 @@
|
||||
[char]
|
||||
plan = "plans/base/"
|
||||
dependencies = ["plans/extension"]
|
||||
|
||||
[char.overrides]
|
||||
org = "overrides/org"
|
||||
|
||||
[application]
|
||||
name = "service"
|
||||
|
||||
[config]
|
||||
# provides both local and k8s by default can also be set using:
|
||||
# config.k8s.rabbitmq = true
|
||||
# config.docker-compose.rabbitmq = true
|
||||
rabbitmq = true
|
||||
postgres = true
|
||||
|
||||
[config.org]
|
||||
squad = "kjuulh"
|
||||
domain = "tooling"
|
||||
|
||||
[config.pipeline]
|
||||
path = "char/ci/" # most of these are default, showing them here as a showcase
|
||||
|
||||
[config.actions]
|
||||
path = "char/actions"
|
||||
|
||||
[config.releaser]
|
||||
type = "rust-releaser"
|
||||
|
||||
[config.cargo]
|
||||
crates = ["crates/service_core", "crates/service_util"]
|
||||
|
||||
[config.rust_bin]
|
||||
name = "service"
|
||||
logging = { pretty = true }
|
||||
|
||||
[config.environments.local]
|
||||
type = "docker-compose" # technically default
|
||||
|
||||
[config.environments.local.env]
|
||||
"env" = "local"
|
||||
"db.hostname" = "postgres"
|
||||
"db.secret" = "postgres"
|
||||
|
||||
[config.k8s]
|
||||
monitoring = true
|
||||
|
||||
[config.environments.dev]
|
||||
type = "k8s"
|
||||
|
||||
[config.environments.local.dev]
|
||||
"env" = "local"
|
||||
"db.hostname" = "service-db"
|
||||
"db.secret" = { type = "secret" }
|
8
examples/service/char/actions/Cargo.toml
Normal file
8
examples/service/char/actions/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "actions"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
3
examples/service/char/actions/src/main.rs
Normal file
3
examples/service/char/actions/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
7
examples/service/char/overrides/org/Cargo.lock
generated
Normal file
7
examples/service/char/overrides/org/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "org"
|
||||
version = "0.1.0"
|
8
examples/service/char/overrides/org/Cargo.toml
Normal file
8
examples/service/char/overrides/org/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "org"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
0
examples/service/char/overrides/org/char.toml
Normal file
0
examples/service/char/overrides/org/char.toml
Normal file
3
examples/service/char/overrides/org/src/main.rs
Normal file
3
examples/service/char/overrides/org/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
@@ -0,0 +1 @@
|
||||
{"rustc_fingerprint":13769919407148446586,"outputs":{"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/kah/.rustup/toolchains/stable-aarch64-apple-darwin\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"vh\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.66.0 (69f9c33d7 2022-12-12)\nbinary: rustc\ncommit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943\ncommit-date: 2022-12-12\nhost: aarch64-apple-darwin\nrelease: 1.66.0\nLLVM version: 15.0.2\n","stderr":""}},"successes":{}}
|
3
examples/service/char/overrides/org/target/CACHEDIR.TAG
Normal file
3
examples/service/char/overrides/org/target/CACHEDIR.TAG
Normal file
@@ -0,0 +1,3 @@
|
||||
Signature: 8a477f597d28d172789f06886806bc55
|
||||
# This file is a cache directory tag created by cargo.
|
||||
# For information about cache directory tags see https://bford.info/cachedir/
|
@@ -0,0 +1 @@
|
||||
baa57697ce65b314
|
@@ -0,0 +1 @@
|
||||
{"rustc":15520539443732555526,"features":"[]","target":10808372008975436347,"profile":11736316127369858332,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/org-2413d5d1cd4f3ae1/dep-bin-org"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
Binary file not shown.
@@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
BIN
examples/service/char/overrides/org/target/debug/deps/org-2413d5d1cd4f3ae1
Executable file
BIN
examples/service/char/overrides/org/target/debug/deps/org-2413d5d1cd4f3ae1
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
/Users/kah/git/git.front.kjuulh.io/kjuulh/char/examples/service/char/overrides/org/target/debug/deps/org-2413d5d1cd4f3ae1: src/main.rs
|
||||
|
||||
/Users/kah/git/git.front.kjuulh.io/kjuulh/char/examples/service/char/overrides/org/target/debug/deps/org-2413d5d1cd4f3ae1.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
examples/service/char/overrides/org/target/debug/org
Executable file
BIN
examples/service/char/overrides/org/target/debug/org
Executable file
Binary file not shown.
1
examples/service/char/overrides/org/target/debug/org.d
Normal file
1
examples/service/char/overrides/org/target/debug/org.d
Normal file
@@ -0,0 +1 @@
|
||||
/Users/kah/git/git.front.kjuulh.io/kjuulh/char/examples/service/char/overrides/org/target/debug/org: /Users/kah/git/git.front.kjuulh.io/kjuulh/char/examples/service/char/overrides/org/src/main.rs
|
5
examples/service/plans/base/char.toml
Normal file
5
examples/service/plans/base/char.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
[char]
|
||||
|
||||
[plan]
|
||||
|
||||
name = "base"
|
Reference in New Issue
Block a user