From 99c032ec2c1f2b6e3545e5400d9d3b2323abfe4d Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 09:52:06 -0400 Subject: [PATCH 01/13] Added CI foundation --- .drone.yml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..d3fd619 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,43 @@ +kind: pipeline +name: default + +steps: +- name: build-ui + image: node:16.13-slim + volumes: + - name: temp + path: /app + commands: + - apt-get update + - apt-get -y install libssl-dev + - npm install + - npm run build + - cp -R ./ui/build /app/dist + + +- name: test + image: rust:latest + commands: + - rustup component add clippy + - cargo clippy + - cargo test --all + +- name: binary-deploy + image: rust:latest + commands: + - cargo build --release + - tar cvzf mailspy.tar.gz -C target/release mailspy + - wget https://dl.min.io/client/mc/release/linux-amd64/mc + - chmod +x mc + - ./mc alias set fivesigma https://objects.5sigma.io $MINIOID $MINIOSECRET + - ./mc cp mailspy.tar.gz fivesigma/public/mailspy.tar.gz + # when: + # event: + # - promote + # target: + # - staging + # - production + +volumes: +- name: temp + temp: {} -- 2.40.1 From 7f4ed43e2efc506a5c9eab5e474386a6d9c0c14f Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 09:58:02 -0400 Subject: [PATCH 02/13] Added dir change in ui build --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index d3fd619..f8543e4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,6 +10,7 @@ steps: commands: - apt-get update - apt-get -y install libssl-dev + - cd ui - npm install - npm run build - cp -R ./ui/build /app/dist -- 2.40.1 From e91feda7c69f6a312cbcc377cd387bc785b9c743 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 09:59:06 -0400 Subject: [PATCH 03/13] Switched node image to node-latest --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index f8543e4..ef1282d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,7 +3,7 @@ name: default steps: - name: build-ui - image: node:16.13-slim + image: node:latest-slim volumes: - name: temp path: /app -- 2.40.1 From c17a21f8688089f47983ea65bbf12e21387b4a88 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 10:00:09 -0400 Subject: [PATCH 04/13] switched node to 18.9.1 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index ef1282d..a8cc9c6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,7 +3,7 @@ name: default steps: - name: build-ui - image: node:latest-slim + image: node:18.9.1-slim volumes: - name: temp path: /app -- 2.40.1 From fefb6c3e5a3d8c3345cf8641a3dcd42f4b3401fd Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 10:01:42 -0400 Subject: [PATCH 05/13] Changed cp command dir --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index a8cc9c6..8454938 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ steps: - cd ui - npm install - npm run build - - cp -R ./ui/build /app/dist + - cp -R ./build /app/dist - name: test -- 2.40.1 From fc3dd1435e7767f859cd1b5fe39d3711d03b3f60 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 10:10:46 -0400 Subject: [PATCH 06/13] Added ui copy, updated readme --- .drone.yml | 1 + README.org | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.drone.yml b/.drone.yml index 8454938..cd6125e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,6 +26,7 @@ steps: - name: binary-deploy image: rust:latest commands: + - cp -R /app/dist ./ui/build - cargo build --release - tar cvzf mailspy.tar.gz -C target/release mailspy - wget https://dl.min.io/client/mc/release/linux-amd64/mc diff --git a/README.org b/README.org index ab1a16e..7f93074 100644 --- a/README.org +++ b/README.org @@ -7,7 +7,7 @@ Mailspy is a mock SMTP server for used during development of applications that s Mailspy is available in binary distribution for 64-bit linux systems. #+begin_src sh -curl https://objects.5sigma.io/public/conductor.tar.gz | tar -xz +curl https://objects.5sigma.io/public/mailspy.tar.gz | tar -xz #+end_src * Usage @@ -20,12 +20,12 @@ Execute the mailspy binary: Then set your application to use the following smtp settings: -*SMTP Server*: localhost -*Port*: 7778 -*Username*: Any value -*Password*: Any value -*TLS*: None/Unsecured -*Authorization Type*: Basic Auth +*- SMTP Server*: localhost +*- Port*: 7778 +*- Username*: Any value +*- Password*: Any value +*- TLS*: None/Unsecured +*- Authorization Type*: Basic Auth View emails in the web interface served at: -- 2.40.1 From 1c0e3826935fab7f06dddbad5354302962fbe3bf Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 10:25:53 -0400 Subject: [PATCH 07/13] Added docker stage --- .drone.yml | 40 ++++++++++++++++++++++++++++++++++++++-- Dockerfile | 7 +++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/.drone.yml b/.drone.yml index cd6125e..eb79656 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ steps: - cd ui - npm install - npm run build - - cp -R ./build /app/dist + - cp -R ./build /app/ui - name: test @@ -23,10 +23,14 @@ steps: - cargo clippy - cargo test --all + - name: binary-deploy image: rust:latest + volumes: + - name: temp + path: /app commands: - - cp -R /app/dist ./ui/build + - cp -R /app/ui ./ui/build - cargo build --release - tar cvzf mailspy.tar.gz -C target/release mailspy - wget https://dl.min.io/client/mc/release/linux-amd64/mc @@ -40,6 +44,38 @@ steps: # - staging # - production +- name: build-musl + image: rust + volumes: + - name: temp + path: /app + commands: + - cp -R /app/ui ./ui/build + - rustup target add x86_64-unknown-linux-musl + - apt update && apt install -y musl-tools musl-dev + - update-ca-certificates + - cargo build --target x86_64-unknown-linux-musl --release + - mkdir /app/build + - cp target/x86_64-unknown-linux-musl/release/mailspy /app/build/mailspy + +- name: stage-deploy + image: plugins/docker + privileged: true + volumes: + - name: temp + path: /app + settings: + username: + from_secret: CONTAINER_USER + password: + from_secret: CONTAINER_PASSWORD + registry: git.5sigma.io + context: /app/build + repo: git.5sigma.io/mailspy/mailspy + tags: latest + + + volumes: - name: temp temp: {} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1dca783 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:latest +COPY mailspy /app/mailspy +EXPOSE 8089 +WORKDIR app +EXPOSE 7777 +EXPOSE 7778 +CMD ./mailspy -- 2.40.1 From 1e28b2546af720b9e8e83db7a3cad0797b7fa645 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 12:50:46 -0400 Subject: [PATCH 08/13] Added openssl to musl build --- .drone.yml | 2 +- Cargo.lock | 11 +++++++++++ Cargo.toml | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index eb79656..9da0a0d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -52,7 +52,7 @@ steps: commands: - cp -R /app/ui ./ui/build - rustup target add x86_64-unknown-linux-musl - - apt update && apt install -y musl-tools musl-dev + - apt update && apt install -y musl-tools musl-dev libssl-dev - update-ca-certificates - cargo build --target x86_64-unknown-linux-musl --release - mkdir /app/build diff --git a/Cargo.lock b/Cargo.lock index e9ec9c0..a9ca3fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -893,6 +893,7 @@ dependencies = [ "smallvec", "thiserror", "tokio", + "tokio-native-tls", "tokio-stream", "tokio-util", "tracing", @@ -1331,6 +1332,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.10" diff --git a/Cargo.toml b/Cargo.toml index f13274d..8af7f98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ serde_json = "1.0.85" tokio = { version = "1.21.1", features = ["full"] } bytes = "1.2.1" lettre = "0.10.1" -poem = { version = "1.3.44", features = ["compression", "embed"] } +poem = { version = "1.3.44", features = ["compression", "embed", "native-tls"] } rust-embed = "6.4.1" tracing = "0.1.36" tracing-subscriber = "0.3.15" -- 2.40.1 From 573794708a58c5cac6be56594bcb7422b52bd74e Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 13:10:12 -0400 Subject: [PATCH 09/13] Moved lettr to dev dependencies --- .drone.yml | 3 +++ Cargo.lock | 11 ----------- Cargo.toml | 5 +++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/.drone.yml b/.drone.yml index 9da0a0d..5568e02 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,6 +26,7 @@ steps: - name: binary-deploy image: rust:latest + depends_on: [ build-ui ] volumes: - name: temp path: /app @@ -46,6 +47,7 @@ steps: - name: build-musl image: rust + depends_on: [ build-ui ] volumes: - name: temp path: /app @@ -61,6 +63,7 @@ steps: - name: stage-deploy image: plugins/docker privileged: true + depends_on: [ build-musl ] volumes: - name: temp path: /app diff --git a/Cargo.lock b/Cargo.lock index a9ca3fb..e9ec9c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -893,7 +893,6 @@ dependencies = [ "smallvec", "thiserror", "tokio", - "tokio-native-tls", "tokio-stream", "tokio-util", "tracing", @@ -1332,16 +1331,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-stream" version = "0.1.10" diff --git a/Cargo.toml b/Cargo.toml index 8af7f98..090deb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,14 @@ serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.85" tokio = { version = "1.21.1", features = ["full"] } bytes = "1.2.1" -lettre = "0.10.1" -poem = { version = "1.3.44", features = ["compression", "embed", "native-tls"] } +poem = { version = "1.3.44", features = ["compression", "embed"] } rust-embed = "6.4.1" tracing = "0.1.36" tracing-subscriber = "0.3.15" mailparse = "0.13.8" clap = { version = "3.2.22", features = ["derive"] } +[dev-dependencies] +lettre = "0.10.1" -- 2.40.1 From f4403b68780ffdb2cc0c401df6170b5ebcf7f64e Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 13:25:13 -0400 Subject: [PATCH 10/13] Set host adapter to 0.0.0.0 for http and smtp --- .drone.yml | 6 +++--- src/http.rs | 2 +- src/smtp.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5568e02..57f69ec 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,7 +26,7 @@ steps: - name: binary-deploy image: rust:latest - depends_on: [ build-ui ] + depends_on: [ build-ui, test ] volumes: - name: temp path: /app @@ -47,7 +47,7 @@ steps: - name: build-musl image: rust - depends_on: [ build-ui ] + depends_on: [ build-ui, test ] volumes: - name: temp path: /app @@ -63,7 +63,7 @@ steps: - name: stage-deploy image: plugins/docker privileged: true - depends_on: [ build-musl ] + depends_on: [ build-musl, test ] volumes: - name: temp path: /app diff --git a/src/http.rs b/src/http.rs index 911b2ad..8a5bbb7 100644 --- a/src/http.rs +++ b/src/http.rs @@ -31,7 +31,7 @@ pub async fn server(mailbox: Mailbox, port: u16) -> anyhow::Result<()> { .at("/", EmbeddedFileEndpoint::::new("index.html")) .nest("/", EmbeddedFilesEndpoint::::new()) .with(AddData::new(mailbox)); - if let Err(e) = Server::new(TcpListener::bind(format!("localhost:{}", port))) + if let Err(e) = Server::new(TcpListener::bind(format!("0.0.0.0:{}", port))) .run(app) .await { diff --git a/src/smtp.rs b/src/smtp.rs index 170e3f5..85979f6 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -142,7 +142,7 @@ impl Connection { } pub async fn server(mailbox: Mailbox, port: u16) -> anyhow::Result<()> { - let addr = format!("127.0.0.1:{}", port); + let addr = format!("0.0.0.0:{}", port); let listener = TcpListener::bind(&addr).await?; tracing::info!(port =? port, "SMTP Server running"); tokio::spawn(async move { -- 2.40.1 From 6e678779f9ba191b0b06c20a5f880f2599932d44 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 13:39:07 -0400 Subject: [PATCH 11/13] Updated readme and docker port --- Dockerfile | 1 - README.org | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1dca783..583ffbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ FROM alpine:latest COPY mailspy /app/mailspy -EXPOSE 8089 WORKDIR app EXPOSE 7777 EXPOSE 7778 diff --git a/README.org b/README.org index 7f93074..6150384 100644 --- a/README.org +++ b/README.org @@ -10,7 +10,7 @@ Mailspy is available in binary distribution for 64-bit linux systems. curl https://objects.5sigma.io/public/mailspy.tar.gz | tar -xz #+end_src -* Usage +* Binary usage Execute the mailspy binary: @@ -37,6 +37,14 @@ http://localhost:7777 - The HTTP port for the web interface can be configured with -h +* Docker + +Mailspy is avialable as a Docker image. To run it as a temporary container use: + +#+begin_src sh +docker run --rm -p 7777:7777 -p 7778:7778 git.5sigma.io/mailspy/mailspy:latest +#+end_src + * Development The core application Rust application is located in /src folder. This contains both the SMTP and HTTP servers. The web interface is located in /ui and is a Svelte application. -- 2.40.1 From e2fa2d0a6c35f0bced6889cb40812ecdf4118c90 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 13:40:33 -0400 Subject: [PATCH 12/13] Added promotion requirement for builds --- .drone.yml | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/.drone.yml b/.drone.yml index 57f69ec..32b4956 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,6 +2,13 @@ kind: pipeline name: default steps: +- name: test + image: rust:latest + commands: + - rustup component add clippy + - cargo clippy + - cargo test --all + - name: build-ui image: node:18.9.1-slim volumes: @@ -14,15 +21,12 @@ steps: - npm install - npm run build - cp -R ./build /app/ui - - -- name: test - image: rust:latest - commands: - - rustup component add clippy - - cargo clippy - - cargo test --all - + when: + event: + - promote + target: + - staging + - production - name: binary-deploy image: rust:latest @@ -38,12 +42,12 @@ steps: - chmod +x mc - ./mc alias set fivesigma https://objects.5sigma.io $MINIOID $MINIOSECRET - ./mc cp mailspy.tar.gz fivesigma/public/mailspy.tar.gz - # when: - # event: - # - promote - # target: - # - staging - # - production + when: + event: + - promote + target: + - staging + - production - name: build-musl image: rust @@ -59,6 +63,12 @@ steps: - cargo build --target x86_64-unknown-linux-musl --release - mkdir /app/build - cp target/x86_64-unknown-linux-musl/release/mailspy /app/build/mailspy + when: + event: + - promote + target: + - staging + - production - name: stage-deploy image: plugins/docker @@ -76,7 +86,12 @@ steps: context: /app/build repo: git.5sigma.io/mailspy/mailspy tags: latest - + when: + event: + - promote + target: + - staging + - production volumes: -- 2.40.1 From a2c93442f56b3c54b0c3dfda6853fbf19218bcc9 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 13:45:34 -0400 Subject: [PATCH 13/13] Added dummy index.html for test runs --- .drone.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.drone.yml b/.drone.yml index 32b4956..5da00a6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,6 +5,8 @@ steps: - name: test image: rust:latest commands: + - mkdir -p ui/build + - touch ui/build/index.html - rustup component add clippy - cargo clippy - cargo test --all -- 2.40.1