From b223d6c7eefd246b3df03c8975ea988579ea9f08 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Wed, 28 Sep 2022 18:02:56 +0000 Subject: [PATCH] CI/CD (#1) Reviewed-on: https://git.5sigma.io/mailspy/mailspy/pulls/1 --- .drone.yml | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- Dockerfile | 6 ++++ README.org | 24 ++++++++----- src/http.rs | 2 +- src/smtp.rs | 2 +- 6 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 .drone.yml create mode 100644 Dockerfile diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..5da00a6 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,101 @@ +kind: pipeline +name: default + +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 + +- name: build-ui + image: node:18.9.1-slim + volumes: + - name: temp + path: /app + commands: + - apt-get update + - apt-get -y install libssl-dev + - cd ui + - npm install + - npm run build + - cp -R ./build /app/ui + when: + event: + - promote + target: + - staging + - production + +- name: binary-deploy + image: rust:latest + depends_on: [ build-ui, test ] + volumes: + - name: temp + path: /app + commands: + - 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 + - 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 + +- name: build-musl + image: rust + depends_on: [ build-ui, test ] + 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 libssl-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 + when: + event: + - promote + target: + - staging + - production + +- name: stage-deploy + image: plugins/docker + privileged: true + depends_on: [ build-musl, test ] + 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 + when: + event: + - promote + target: + - staging + - production + + +volumes: +- name: temp + temp: {} diff --git a/Cargo.toml b/Cargo.toml index f13274d..090deb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ 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"] } rust-embed = "6.4.1" tracing = "0.1.36" @@ -19,5 +18,7 @@ tracing-subscriber = "0.3.15" mailparse = "0.13.8" clap = { version = "3.2.22", features = ["derive"] } +[dev-dependencies] +lettre = "0.10.1" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..583ffbc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:latest +COPY mailspy /app/mailspy +WORKDIR app +EXPOSE 7777 +EXPOSE 7778 +CMD ./mailspy diff --git a/README.org b/README.org index ab1a16e..6150384 100644 --- a/README.org +++ b/README.org @@ -7,10 +7,10 @@ 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 +* Binary usage Execute the mailspy binary: @@ -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: @@ -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. 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 {