diff options
Diffstat (limited to 'module/acme/src')
5 files changed, 104 insertions, 0 deletions
diff --git a/module/acme/src/main/java/io/trygvis/acme/AcmeMyApp.java b/module/acme/src/main/java/io/trygvis/acme/AcmeMyApp.java new file mode 100644 index 0000000..dfe374b --- /dev/null +++ b/module/acme/src/main/java/io/trygvis/acme/AcmeMyApp.java @@ -0,0 +1,6 @@ +package io.trygvis.acme; + +public class AcmeMyApp { + public String environment; + public String dockerTag; +} diff --git a/module/acme/src/main/java/io/trygvis/acme/AcmeOps.java b/module/acme/src/main/java/io/trygvis/acme/AcmeOps.java new file mode 100644 index 0000000..844c7f0 --- /dev/null +++ b/module/acme/src/main/java/io/trygvis/acme/AcmeOps.java @@ -0,0 +1,4 @@ +package io.trygvis.acme; + +public class AcmeOps { +} diff --git a/module/acme/src/main/java/io/trygvis/acme/VpnMain.java b/module/acme/src/main/java/io/trygvis/acme/VpnMain.java new file mode 100644 index 0000000..d5f986d --- /dev/null +++ b/module/acme/src/main/java/io/trygvis/acme/VpnMain.java @@ -0,0 +1,25 @@ +package io.trygvis.acme; + +import io.trygvis.rules.dns.DnsEntry; +import io.trygvis.rules.engine.Engine; +import io.trygvis.rules.machine.Machine; +import io.trygvis.rules.network.Ipv4Address; +import io.trygvis.rules.network.Ipv4Cidr; + +import java.io.IOException; + +public class VpnMain { + public static void main(String[] args) throws IOException { + try (var engine = new Engine("acme.yaml")) { + engine.io.dump("phase-1", engine.session.getFactHandles()); + + engine.io.dump("vpn0", engine.session.getFactHandles(), (Object o) -> + o.getClass().getName().contains("Wg") + || o instanceof Machine + || o instanceof DnsEntry + || o instanceof Ipv4Cidr + || o instanceof Ipv4Address + ); + } + } +} diff --git a/module/acme/src/main/resources/META-INF/kmodule.xml b/module/acme/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 0000000..351a25e --- /dev/null +++ b/module/acme/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.acme" default="true" + includes="engine,wireguard"> + <ksession name="Default" default="true"> + </ksession> + </kbase> +</kmodule> diff --git a/module/acme/src/main/resources/io/trygvis/acme/acme.drl b/module/acme/src/main/resources/io/trygvis/acme/acme.drl new file mode 100644 index 0000000..d978579 --- /dev/null +++ b/module/acme/src/main/resources/io/trygvis/acme/acme.drl @@ -0,0 +1,58 @@ +package io.trygvis.acme; + +import io.trygvis.rules.machine.Machine; +import io.trygvis.rules.dba.Cluster; +import io.trygvis.rules.dba.Container; + +dialect "mvel" + +declare AcmeServer + name : String + machine : Machine +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 + $s.machine.fqdn = "%s.machine.acme.com".formatted($s.machine.name); + update($s.machine) +end |