diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-06 12:05:23 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-06 12:05:23 +0100 |
commit | b8699860653e593271e50c8ba1b73f66fcb6287c (patch) | |
tree | a7029ee71f1539d269fda241a3f345255783dcf1 /module/ri-engine/src/main/resources | |
parent | 9eac79348242b5dc33f4cccdd86beda2a4ed4746 (diff) | |
download | rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.tar.gz rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.tar.bz2 rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.tar.xz rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.zip |
Starting on splitting up into different modules.
Diffstat (limited to 'module/ri-engine/src/main/resources')
6 files changed, 155 insertions, 0 deletions
diff --git a/module/ri-engine/src/main/resources/META-INF/kmodule.xml b/module/ri-engine/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 0000000..7a46b1a --- /dev/null +++ b/module/ri-engine/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://www.drools.org/xsd/kmodule" + xsi:schemaLocation="http://www.drools.org/xsd/kmodule https://www.drools.org/xsd/kmodule_7_1.xsd"> + + <kbase packages="io.trygvis.rules,io.trygvis.rules.acme,io.trygvis.rules.dba,io.trygvis.rules.engine,io.trygvis.rules.machine,io.trygvis.rules.terraform" + default="true" includes="wireguard"> + <ksession name="Default" default="true"> + </ksession> + </kbase> +</kmodule> diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/acme/acme.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/acme/acme.drl new file mode 100644 index 0000000..0465343 --- /dev/null +++ b/module/ri-engine/src/main/resources/io/trygvis/rules/acme/acme.drl @@ -0,0 +1,62 @@ +package io.trygvis.rules.acme; + +import io.trygvis.rules.machine.Machine; +import io.trygvis.rules.dba.Cluster; +import io.trygvis.rules.dba.Container; + +declare AcmeServer + name : String + machine : Machine +end + +//declare MachinePublicName +// machine : Machine +// fqdn : String +//end + +rule "Ops" +when + $ops: AcmeOps() +then + var cluster = new Cluster("acme-ops"); + insert(cluster); + insert(new Container(cluster, "app", "pdb", "postgresql", "11")); + insert(new Container(cluster, "app", "n8n", "n8n", "0.84.1")); +end + +rule "MyApp" +when + $app: AcmeMyApp() +then + var cluster = new Cluster("acme-" + $app.environment); + insert(cluster); + + var tag = $app.dockerTag; + insert(new Container(cluster, "app", "statera", "statera", tag)); + insert(new Container(cluster, "app", "statera-console", "statera-console", tag)); + insert(new Container(cluster, "app", "4tune-web", "4tune-web", tag)); + insert(new Container(cluster, "app", "4tune-api", "4tune-api", tag)); + insert(new Container(cluster, "db", "pdb", "postgresql", "13")); + insert(new Container(cluster, "db", "mdb", "mongodb", "3.2")); +end + +rule "Create Acme servers" +when + $m : Machine(name.startsWith("acme-")) + not(AcmeServer(name == $m.name)) +then + var s = new AcmeServer(); + s.name = $m.name; + s.machine = $m; + insert(s); +end + +rule "Set public domain for ACME servers" +when + $m : Machine(fqdn == null) + $s : AcmeServer(machine == $m) +then + var fqdn = "%s.machine.acme.com".formatted($s.machine.name); + $s.machine.fqdn = fqdn; + update($s.machine) +end diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl new file mode 100644 index 0000000..7beceef --- /dev/null +++ b/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl @@ -0,0 +1 @@ +package io.trygvis.rules.dba; diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl new file mode 100644 index 0000000..090fddf --- /dev/null +++ b/module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl @@ -0,0 +1,15 @@ +package io.trygvis.rules.engine; +import java.util.Map +import org.apache.commons.io.FileSystem +import org.apache.commons.io.FileUtils +import java.io.File + +rule "Clean directories" + agenda-group "init" +when + not(KeyValue(key == "rm-gen")); +then + System.out.println("Cleaning gen!"); + FileUtils.deleteDirectory(new File("gen")); + insert(new KeyValue("rm-gen", null)); +end diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/machine/machine.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/machine/machine.drl new file mode 100644 index 0000000..a9a379f --- /dev/null +++ b/module/ri-engine/src/main/resources/io/trygvis/rules/machine/machine.drl @@ -0,0 +1,6 @@ +package io.trygvis.rules.machine; + +import io.trygvis.rules.dba.Cluster; +import io.trygvis.rules.dba.Container; +import io.trygvis.rules.machine.Machine; +import io.trygvis.rules.dns.DnsEntry; diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/terraform/terraform.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/terraform/terraform.drl new file mode 100644 index 0000000..40b9f7c --- /dev/null +++ b/module/ri-engine/src/main/resources/io/trygvis/rules/terraform/terraform.drl @@ -0,0 +1,60 @@ +package io.trygvis.rules.terraform + +import io.trygvis.rules.dba.Cluster +import io.trygvis.rules.dba.Container +import io.trygvis.rules.machine.Machine +import io.trygvis.rules.dns.DnsEntry +import io.trygvis.rules.dns.DnsEntryTerraformExpression +import java.util.Map; + +global io.trygvis.rules.engine.TemplateEngine te; + +declare ScalewayMachine + machine : Machine + key : String +end + +rule "Terraform for Machine" +when + $machine: Machine() +then + ScalewayMachine scw = new ScalewayMachine(); + + scw.setKey($machine.name); + scw.setMachine($machine); + + insert(scw); +end + +rule "Create DNS entry for Terraform Machine" +when + $machine : Machine(fqdn != null) + not(DnsEntry(fqdn == $machine.fqdn)) +then + var a = DnsEntry.a($machine.fqdn); + insert(a); + + var ipv4 = "scaleway_instance_ip.%s.address".formatted($machine.name); + insert(new DnsEntryTerraformExpression(a, $machine.name, ipv4)); +end + +rule "TF for TerraformMachine" +when + $m: Machine() + $scw: ScalewayMachine(machine == $m) +then + var path = "platform/terraform/%s.tf".formatted($scw.getKey()); + te.template("terraform-machine", path, Map.of("m", $m, "scw", $scw)); +end + +rule "Terraform for DNS" +when + $entry: DnsEntry() + $tf : DnsEntryTerraformExpression(entry == $entry) +then + var path = "dns/%s.tf".formatted($tf.key); + te.template("terraform-record-set", path, Map.of( + "entry", $entry, + "tf", $tf) + ); +end |