From 14fabff4cd2858db36f44e5aa6a3cf7c9137ec6d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 May 2026 22:20:15 +0000 Subject: [PATCH] feat: add Dockerfile and docker-compose files for gomailtest serve command Agent-Logs-Url: https://github.com/ziembor/gomailtesttool/sessions/84c03bf8-de1c-453f-8724-9fc6d9ff601d Co-authored-by: ziembor <1870879+ziembor@users.noreply.github.com> --- .env.example | 35 ++++++++++++++++++++++++++++++ Dockerfile | 21 ++++++++++++++++++ docker-compose.msgraph.yml | 31 +++++++++++++++++++++++++++ docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 docker-compose.msgraph.yml create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cc5f1c4 --- /dev/null +++ b/.env.example @@ -0,0 +1,35 @@ +# .env.example — copy to .env and fill in values before running docker compose +# +# See docker-compose.yml and docker-compose.msgraph.yml for usage. + +# ── HTTP Server ────────────────────────────────────────────────────────────── +# Required: API key checked via X-API-Key header on all non-health endpoints. +SERVE_API_KEY=change-me + +# Optional: host port to publish (default 8080). +# SERVE_PORT=8080 + +# ── SMTP ───────────────────────────────────────────────────────────────────── +# Required for POST /smtp/sendmail to be available. +SMTPHOST=smtp.example.com +SMTPPORT=587 +SMTPUSERNAME=user@example.com +SMTPPASSWORD=secret +SMTPFROM=user@example.com +SMTPSTARTTLS=true +# SMTPSMTPS=false +# SMTPSKIPVERIFY=false +# SMTPTLSVERSION=1.2 +# SMTPAUTHMETHOD=auto + +# ── Microsoft Graph ────────────────────────────────────────────────────────── +# Required for POST /msgraph/sendmail to be available +# (used with docker-compose.msgraph.yml). +MSGRAPHTENANTID=00000000-0000-0000-0000-000000000000 +MSGRAPHCLIENTID=00000000-0000-0000-0000-000000000000 +MSGRAPHSECRET=your-client-secret +# MSGRAPHPFX= +# MSGRAPHPFXPASS= +# MSGRAPHBEARERTOKEN= +# MSGRAPHMAILBOX=mailbox@example.com +# MSGRAPHPROXY= diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e0daab6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.24-alpine AS builder + +WORKDIR /src + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN go build -ldflags="-s -w" -o /gomailtest ./cmd/gomailtest + + +FROM alpine:3.21 + +RUN apk add --no-cache ca-certificates tzdata + +COPY --from=builder /gomailtest /usr/local/bin/gomailtest + +EXPOSE 8080 + +ENTRYPOINT ["gomailtest"] +CMD ["serve"] diff --git a/docker-compose.msgraph.yml b/docker-compose.msgraph.yml new file mode 100644 index 0000000..7edd364 --- /dev/null +++ b/docker-compose.msgraph.yml @@ -0,0 +1,31 @@ +# docker-compose.msgraph.yml — gomailtest serve (Microsoft Graph backend) +# +# Use this override file together with docker-compose.yml to enable the +# MS Graph sendmail endpoint in addition to (or instead of) SMTP: +# +# docker compose -f docker-compose.yml -f docker-compose.msgraph.yml up +# +# Required MS Graph environment variables: +# MSGRAPHTENANTID — Azure AD Tenant ID (GUID) +# MSGRAPHCLIENTID — Application (Client) ID (GUID) +# +# Authentication — set exactly one of: +# MSGRAPHSECRET — Client Secret +# MSGRAPHPFX — Path to .pfx certificate file (mount the file into the container) +# MSGRAPHPFXPASS — Password for the .pfx file (if using MSGRAPHPFX) +# MSGRAPHBEARERTOKEN — Pre-obtained Bearer token +# +# Optional MS Graph variables: +# MSGRAPHMAILBOX, MSGRAPHPROXY + +services: + gomailtest-serve: + environment: + MSGRAPHTENANTID: "${MSGRAPHTENANTID}" + MSGRAPHCLIENTID: "${MSGRAPHCLIENTID}" + MSGRAPHSECRET: "${MSGRAPHSECRET:-}" + MSGRAPHPFX: "${MSGRAPHPFX:-}" + MSGRAPHPFXPASS: "${MSGRAPHPFXPASS:-}" + MSGRAPHBEARERTOKEN: "${MSGRAPHBEARERTOKEN:-}" + MSGRAPHMAILBOX: "${MSGRAPHMAILBOX:-}" + MSGRAPHPROXY: "${MSGRAPHPROXY:-}" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cbbb4e7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +# docker-compose.yml — gomailtest serve (SMTP backend) +# +# Copy .env.example to .env and fill in values before running: +# docker compose up +# +# Required environment variables: +# SERVE_API_KEY — X-API-Key header value required by all non-health endpoints +# SMTPHOST — SMTP server hostname +# +# Optional SMTP variables (see docs/protocols/smtp.md for the full list): +# SMTPPORT, SMTPUSERNAME, SMTPPASSWORD, SMTPFROM, +# SMTPSTARTTLS, SMTPSMTPS, SMTPSKIPVERIFY, SMTPTLSVERSION, +# SMTPAUTHMETHOD, SMTPTIMEOUT + +services: + gomailtest-serve: + build: + context: . + dockerfile: Dockerfile + image: gomailtest:latest + command: ["serve"] + ports: + - "${SERVE_PORT:-8080}:8080" + environment: + SERVE_API_KEY: "${SERVE_API_KEY}" + SERVE_PORT: "8080" + SMTPHOST: "${SMTPHOST}" + SMTPPORT: "${SMTPPORT:-25}" + SMTPUSERNAME: "${SMTPUSERNAME:-}" + SMTPPASSWORD: "${SMTPPASSWORD:-}" + SMTPFROM: "${SMTPFROM:-}" + SMTPSTARTTLS: "${SMTPSTARTTLS:-false}" + SMTPSMTPS: "${SMTPSMTPS:-false}" + SMTPSKIPVERIFY: "${SMTPSKIPVERIFY:-false}" + SMTPTLSVERSION: "${SMTPTLSVERSION:-1.2}" + SMTPAUTHMETHOD: "${SMTPAUTHMETHOD:-auto}" + SMTPTIMEOUT: "${SMTPTIMEOUT:-}" + restart: unless-stopped + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://localhost:8080/health || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 5s