build docker image

This commit is contained in:
Cadey Ratio 2020-07-03 21:03:43 -04:00
parent ecdcbab6dc
commit 2a1d80d820
7 changed files with 72 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target
/result*
.env

3
Cargo.lock generated
View File

@ -336,7 +336,8 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "furbooru"
version = "0.3.0"
source = "git+https://github.com/Xe/furbooru#8fac90975d480116851575b3d706bc48dc26a46f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ef1f8a2e91bead257f057491c9581bfee0e9d7eef219ffafd88408fd4a3c818"
dependencies = [
"anyhow",
"async-trait",

View File

@ -10,6 +10,7 @@ edition = "2018"
anyhow = "1"
async-trait = "0"
envy = "0.4"
furbooru = "0.3"
kankyo = "*"
log = "0.4"
pretty_env_logger = "0.4"
@ -20,4 +21,3 @@ tokio = { version = "0.2", features = ["macros"] }
# git deps
discord_webhook = { git = "https://github.com/Xe/withinbot", branch = "main"}
furbooru = { git = "https://github.com/Xe/furbooru" }

24
default.nix Normal file
View File

@ -0,0 +1,24 @@
{ sources ? import ./nix/sources.nix, pkgs ? import sources.nixpkgs { }
, naersk ? pkgs.callPackage sources.naersk { } }:
let
campaigns = pkgs.callPackage ./campaigns { };
tron = naersk.buildPackage {
src = builtins.filterSource
(path: type: type != "directory" || builtins.baseNameOf path != "target")
./.;
buildInputs = [ pkgs.openssl pkgs.pkg-config pkgs.sqlite ];
doCheck = false;
};
in pkgs.stdenv.mkDerivation {
inherit (tron) name version;
phases = "installPhase";
installPhase = ''
mkdir -p $out/bin
ln -s ${tron}/bin/tron $out/bin/tron
ln -s ${./regexes.dhall} $out/regexes.dhall
'';
}

22
docker.nix Normal file
View File

@ -0,0 +1,22 @@
{ system ? builtins.currentSystem }:
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { };
callPackage = pkgs.lib.callPackageWith pkgs;
tron = callPackage ./default.nix { };
dockerImage = pkg:
pkgs.dockerTools.buildLayeredImage {
name = "xena/tron";
tag = pkg.version;
contents = [ pkgs.cacert pkg ];
config = {
Cmd = [ "/bin/tron" ];
WorkingDir = "/";
};
};
in dockerImage tron

View File

@ -11,6 +11,18 @@
"url": "https://github.com/justinwoo/easy-dhall-nix/archive/288ee825c326f352a5db194a024bd3e1f2f735b2.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"naersk": {
"branch": "master",
"description": "Build rust crates in Nix. No configuration, no code generation, no IFD. Sandbox friendly.",
"homepage": "",
"owner": "nmattia",
"repo": "naersk",
"rev": "a82fd7dc31a58c462b6dfa9d9d886fa2cc75dfd4",
"sha256": "00bjwir52y6jbf0b22qy9qxramw35k5fc7kp9hymr1zgpmw9kbwg",
"type": "tarball",
"url": "https://github.com/nmattia/naersk/archive/a82fd7dc31a58c462b6dfa9d9d886fa2cc75dfd4.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",

View File

@ -47,6 +47,7 @@ impl FirehoseAdaptor for Rules {
for rule in &self.0 {
if rule.regex.is_match(&img.description.to_lowercase()) {
log::debug!("{:?} matches {}", img.description, rule.raw);
found = true;
buf.push_str(&format!("\n- match on rule `{}` ({})", rule.raw, rule.why));
}
@ -58,6 +59,7 @@ impl FirehoseAdaptor for Rules {
Body::new(format!("matches found on <{}>:{}", img.view_url, buf)),
)
.await?;
log::info!("the description of {} has naughty words", img.view_url);
}
Ok(())
@ -69,6 +71,7 @@ impl FirehoseAdaptor for Rules {
for rule in &self.0 {
if rule.regex.is_match(&cmt.body.to_lowercase()) {
log::debug!("{:?} matches {}", cmt.body, rule.raw);
found = true;
buf.push_str(&format!("\n- match on rule `{}` ({})", rule.raw, rule.why));
}
@ -83,6 +86,11 @@ impl FirehoseAdaptor for Rules {
)),
)
.await?;
log::info!(
"comment https://furbooru.org/{}#comment_{} has naughty words",
cmt.image_id,
cmt.id
);
}
Ok(())
@ -98,7 +106,7 @@ async fn main() -> Result<()> {
let mut compiled_rules: Vec<CompiledRule> = Vec::new();
for rule in rexes {
println!("{} -> {}", rule.regex, rule.why);
log::debug!("{} -> {}", rule.regex, rule.why);
compiled_rules.push(CompiledRule {
raw: rule.regex.clone(),
regex: Regex::new(rule.regex.as_str())?,
@ -110,6 +118,7 @@ async fn main() -> Result<()> {
user_agent(cfg.bot_owner_furbooru_account.clone()),
cfg.furbooru_api_key.clone(),
)?;
log::info!("listening on the firehose");
cli.firehose(Rules(compiled_rules, cfg)).await?;
Ok(())