From d3a23736cca5aecd3d6f49f5137ccf08b0e61b0d Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Sat, 11 Jul 2020 22:47:30 -0400 Subject: [PATCH] Add Dockerfile and Docker Hub publishing (#9) Adds docker image publishing with example usage in the README. --- .dockerignore | 5 + .github/workflows/docker.yml | 27 ++++ Cargo.lock | 240 ----------------------------------- Cargo.toml | 2 +- Dockerfile | 34 +++++ README.md | 28 +++- examples/config.toml | 2 +- src/mail.rs | 4 +- src/main.rs | 2 +- src/rfd.rs | 6 +- 10 files changed, 99 insertions(+), 251 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9b6ec4d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* +!src +!Cargo.toml +!Cargo.lock +!examples diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..174b1a3 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,27 @@ +name: Publish Docker image +on: + push: + tags: + - v* +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Publish version to Registry + uses: elgohr/Publish-Docker-Github-Action@master + with: + name: davegallant/npm-groovy-lint-test + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + tag_semver: true + - name: Publish latest to Registry + uses: elgohr/Publish-Docker-Github-Action@master + with: + name: davegallant/rfd-notify + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + tags: "latest" + diff --git a/Cargo.lock b/Cargo.lock index 8be3175..190f4e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,22 +135,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "core-foundation" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" - [[package]] name = "crc32fast" version = "1.2.0" @@ -248,21 +232,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "fs2" version = "0.4.3" @@ -376,17 +345,6 @@ version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" -[[package]] -name = "getrandom" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "gimli" version = "0.21.0" @@ -497,19 +455,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "hyper-tls" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-tls", -] - [[package]] name = "idna" version = "0.2.0" @@ -701,24 +646,6 @@ dependencies = [ "winapi 0.3.8", ] -[[package]] -name = "native-tls" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "net2" version = "0.2.34" @@ -752,39 +679,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" -[[package]] -name = "openssl" -version = "0.10.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "lazy_static", - "libc", - "openssl-sys", -] - -[[package]] -name = "openssl-probe" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" - -[[package]] -name = "openssl-sys" -version = "0.9.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.10.2" @@ -847,18 +741,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" - -[[package]] -name = "ppv-lite86" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" - [[package]] name = "pretty_env_logger" version = "0.4.0" @@ -928,29 +810,6 @@ dependencies = [ "winapi 0.3.8", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom", - "libc", - "rand_chacha", - "rand_core 0.5.1", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", -] - [[package]] name = "rand_core" version = "0.3.1" @@ -966,24 +825,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - [[package]] name = "rdrand" version = "0.4.0" @@ -1017,15 +858,6 @@ version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.8", -] - [[package]] name = "reqwest" version = "0.10.6" @@ -1041,13 +873,11 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", - "hyper-tls", "js-sys", "lazy_static", "log", "mime", "mime_guess", - "native-tls", "percent-encoding", "pin-project-lite", "rustls", @@ -1056,7 +886,6 @@ dependencies = [ "serde_urlencoded", "tokio", "tokio-rustls", - "tokio-tls", "url", "wasm-bindgen", "wasm-bindgen-futures", @@ -1143,16 +972,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi 0.3.8", -] - [[package]] name = "scopeguard" version = "1.1.0" @@ -1169,29 +988,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "sendgrid" version = "0.11.3" @@ -1334,20 +1130,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tempfile" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -dependencies = [ - "cfg-if", - "libc", - "rand 0.7.3", - "redox_syscall", - "remove_dir_all", - "winapi 0.3.8", -] - [[package]] name = "termcolor" version = "1.1.0" @@ -1432,16 +1214,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "tokio-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-util" version = "0.3.1" @@ -1533,12 +1305,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "vcpkg" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" - [[package]] name = "vec_map" version = "0.8.2" @@ -1561,12 +1327,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasm-bindgen" version = "0.2.63" diff --git a/Cargo.toml b/Cargo.toml index 6293c2c..25269c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ sendgrid = { version = "0.11.3", features = ["rustls"] } toml = "0.5.6" serde_derive = "1.0.112" serde = "1.0.114" -reqwest = { version = "0.10", features = ["json"] } +reqwest = { version = "0.10", default-features = false, features = ["json", "rustls-tls"] } tokio = { version = "0.2", features = ["full"] } serde_json = "1.0.56" log = "0.4" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..41854bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM rust@sha256:b2fd2fcc9d28c1a6dc59c3b0b37913fd9a326c8e457e50617e1156fc1ad51e34 as build + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && \ + apt-get -y install \ + ca-certificates \ + libssl-dev \ + musl-tools + +RUN rustup target add x86_64-unknown-linux-musl + +WORKDIR /usr/src/rfd-notify + +COPY Cargo.toml Cargo.toml +COPY src src + +ENV PKG_CONFIG_ALLOW_CROSS=1 + +RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl + +RUN mkdir /examples +COPY examples /examples + +FROM scratch + +COPY --from=build /examples /examples + +COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=build /usr/src/rfd-notify/target/x86_64-unknown-linux-musl/release/rfd-notify . + +ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt +ENV SSL_CERT_DIR=/etc/ssl/certs + +ENTRYPOINT ["/rfd-notify"] diff --git a/README.md b/README.md index d165374..a0762b3 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,37 @@ This tool looks for regular expressions from [RedFlagDeals.com forums](https://f ## use -Declare a configuration. An example can found in [config.toml](./examples/config.toml) +```shell +USAGE: + rfd-notify [OPTIONS] --config + +FLAGS: + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + -c, --config Specify path to config + -d, --dbpath Specify path to where the embedded database is stored [default: ./deals_db] +``` + +### docker ```shell -rfd-notify --config ./examples/config.toml +# Run the docker image using an example config: +docker run -e RUST_LOG=INFO davegallant/rfd-notify -c /examples/config.toml +``` + +Provide a custom configuration. An example can found in [config.toml](./examples/config.toml) + +```shell +# Provide a custom-config.toml that is in the current directory +# ensuring the correct user is mapped to the working directory +docker run -u "$(id -u):$(id -g)" -w=/tmp -e RUST_LOG=INFO -v "$PWD":/tmp davegallant/rfd-notify -c /tmp/custom-config.toml ``` ## cross compile -I had motivations to run this on a Raspberry Pi Zero: +I had motivations to run this on a Raspberry Pi Zero (without needing docker on the pi): ```shell alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:arm-musleabihf' diff --git a/examples/config.toml b/examples/config.toml index 3647b2d..8bc96f0 100644 --- a/examples/config.toml +++ b/examples/config.toml @@ -8,4 +8,4 @@ expressions = [ [sendgrid] api_key = "" mail_to = "@gmail.com" -mail_from = "Notify " +mail_from = "Notify " diff --git a/src/mail.rs b/src/mail.rs index 3800984..84cbe6b 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -49,7 +49,7 @@ pub fn send(topic: &Topic, posts: &Posts, expression: &str, config: &Config) { .add_html(&html_message); match sg.send(mail_info) { - Err(err) => println!("Error: {}", err), - Ok(body) => println!("Response: {}", body), + Err(err) => println!("SendGrid failed to send mail. Error: {}", err), + Ok(body) => println!("SendGrid Response: {}", body), }; } diff --git a/src/main.rs b/src/main.rs index 8b0bfd1..2630f4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ fn main() { let config = matches.value_of("config").unwrap(); let parsed_config = config::parse(config); - debug!("{:?}\n", parsed_config); + info!("{:?}\n", parsed_config); let hot_deals = rfd::get_hot_deals().map_err(|err| error!("{:?}", err)).ok(); let parsed_deals = rfd::parse_hot_deals(&hot_deals.unwrap()); rfd::match_deals( diff --git a/src/rfd.rs b/src/rfd.rs index 7b5cd53..d81bf6f 100644 --- a/src/rfd.rs +++ b/src/rfd.rs @@ -83,7 +83,7 @@ pub fn match_deals(deals: Deals, config: Config, dbpath: &str) { .unwrap_or_else(|e| panic!("Invalid regex: {}. {}", expression, e)); if re.is_match(&topic.title) { found_match = true; - debug!( + info!( "Expression '{}' matched title: {}", expression, &topic.title ) @@ -91,7 +91,7 @@ pub fn match_deals(deals: Deals, config: Config, dbpath: &str) { let dealer_name = topic.offer.dealer_name.as_ref().unwrap(); if re.is_match(&dealer_name) { found_match = true; - debug!( + info!( "Expression '{}' matched dealer: {}", expression, &topic.title ) @@ -102,7 +102,7 @@ pub fn match_deals(deals: Deals, config: Config, dbpath: &str) { } let deal_hash = hash_deal(topic); if db::hash_exists(&deal_hash, db::get_config(dbpath)) { - debug!("deal hash '{}' already exists", &deal_hash); + info!("deal hash '{}' already exists", &deal_hash); } else { let posts = parse_posts( get_topic(topic.id)