Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerized relayer, imap, and smtp #88

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
51 changes: 51 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
RELAYER_ENDPOINT=http://host.docker.internal:4500/api/receiveEmail

IMAP_LOGIN_ID= # IMAP login id - usually your email address.
IMAP_DOMAIN_NAME=imap.gmail.com
IMAP_PORT=993
AUTH_TYPE=password

IMAP_LOGIN_PASSWORD= # IMAP password - usually your email password.
# OR
IMAP_CLIENT_ID=
IMAP_CLIENT_SECRET=
IMAP_AUTH_URL=
IMAP_TOKEN_URL=
IMAP_REDIRECT_URL=

JSON_LOGGER=false

SERVER_HOST=0.0.0.0
SERVER_PORT=3000
SMTP_DOMAIN_NAME=smtp.gmail.com
SMTP_LOGIN_ID= # IMAP login id - usually your email address.
SMTP_LOGIN_PASSWORD= # IMAP password - usually your email password.
MESSAGE_ID_DOMAIN=mail.gmail.com

EMAIL_ACCOUNT_RECOVERY_VERSION_ID=1
PRIVATE_KEY=

CHAIN_RPC_PROVIDER=https://sepolia.era.zksync.dev
CHAIN_RPC_EXPLORER=https://sepolia-era.zksync.network
CHAIN_ID=300

SMTP_SERVER=http://host.docker.internal:3000/api/sendEmail

PROVER_ADDRESS="https://zkemail--email-auth-prover-v1-5-4-flask-app.modal.run"

DATABASE_URL="postgres://test@localhost/emailauth_test"
RELAYER_EMAIL_ADDR=
WEB_SERVER_ADDRESS=0.0.0.0:4500
EMAIL_TEMPLATES_PATH=/eml_templates
REGEX_JSON_DIR_PATH=/regex_json

DKIM_CANISTER_ID="fxmww-qiaaa-aaaaj-azu7a-cai"
WALLET_CANISTER_ID=
PEM_PATH="./.ic.pem"
IC_REPLICA_URL="https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=fxmww-qiaaa-aaaaj-azu7a-cai"

CIRCUITS_DIR_PATH=../circuits

ERROR_EMAIL_ADDR="[email protected]"

IC_PEM_CONTENT= # Set the base64-encoded content of ic.pem
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
members = ["packages/relayer"]
exclude = ["node_modules/*", "packages/relayer/src/abis"]
resolver = "2"

[profile.release]
lto = true
44 changes: 32 additions & 12 deletions IMAP.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
# Use the official Rust image as a base image
FROM rust:latest
# Use the official Rust image as the base image for building
FROM rust:1.73 AS builder

# Set the working directory inside the container
WORKDIR /app
# Install necessary dependencies
RUN apt-get update && apt-get install -y \
git \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Clone the GitHub repository
RUN git clone https://github.com/zkemail/relayer-imap.git
# Set the working directory in the container
WORKDIR /usr/src/relayer-imap

# Change to the directory of the cloned repository
WORKDIR /app/relayer-imap
# Clone the repository
RUN git clone https://github.com/zkemail/relayer-imap.git .

# Build the Rust package
RUN cargo build
# Build the application
RUN cargo build --release

# Specify the command to run when the container starts
CMD ["cargo", "run", "--bin", "relayer-imap"]
# Use a minimal base image for the final stage
FROM debian:bookworm-slim

# Install necessary runtime dependencies including ca-certificates
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Copy the built binary from the builder stage
COPY --from=builder /usr/src/relayer-imap/target/release/relayer-imap /usr/local/bin/relayer-imap

# Expose the port the app runs on
EXPOSE 8080

# Set the default command to run the application
CMD ["/usr/local/bin/relayer-imap"]
82 changes: 73 additions & 9 deletions Relayer.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,81 @@
# Use the base image
FROM bisht13/relayer-base
# Stage 1: Build Stage
# Use the official Rust image to build the project
FROM rust:latest AS builder

# Copy the project files
COPY packages/relayer /relayer/packages/relayer
# Use bash as the shell
SHELL ["/bin/bash", "-c"]

# Set the working directory for the Rust project
# Install build-essential and other dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install NVM, Node.js, and Yarn
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash \
&& . $HOME/.nvm/nvm.sh \
&& nvm install 18 \
&& nvm alias default 18 \
&& nvm use default \
&& npm install -g yarn

# Set the working directory
WORKDIR /relayer

# Configure Git to avoid common issues and increase clone verbosity
RUN git config --global advice.detachedHead false \
&& git config --global core.compression 0 \
&& git config --global protocol.version 2 \
&& git config --global http.postBuffer 1048576000 \
&& git config --global fetch.verbose true

# Copy the project files to the build stage
COPY . .

# Install Yarn dependencies with a retry mechanism
RUN . $HOME/.nvm/nvm.sh && nvm use default && yarn || \
(sleep 5 && yarn) || \
(sleep 10 && yarn)

# Install Foundry and add forge to PATH
RUN curl -L https://foundry.paradigm.xyz | bash \
&& . $HOME/.bashrc \
&& foundryup \
&& ln -s $HOME/.foundry/bin/forge /usr/local/bin/forge \
&& forge --version

# Build the contracts
WORKDIR /relayer/packages/contracts
RUN source $HOME/.nvm/nvm.sh && nvm use default && yarn && forge build

# Set the working directory for the Rust project and build it
WORKDIR /relayer/packages/relayer

# Build the Rust project with caching
RUN cargo build
RUN cargo build --release

# Stage 2: Final Stage with Minimal Image
# Use a slim Debian image to keep the final image small
FROM debian:bookworm-slim

# Install necessary runtime dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libssl-dev \
curl \
&& rm -rf /var/lib/apt/lists/*

# Copy the built binary from the builder stage
COPY --from=builder /relayer/target/release/relayer /usr/local/bin/relayer

# Copy eml_templates directory from builder stage to root directory
COPY --from=builder /relayer/packages/relayer/eml_templates /eml_templates

# Copy regex_json directory from builder stage to root directory
COPY --from=builder /relayer/packages/relayer/src/regex_json /regex_json

# Expose port
# Expose the required port
EXPOSE 4500

# Set the default command
CMD ["cargo", "run"]
# Set the default command to run the application
CMD ["/usr/local/bin/relayer"]
45 changes: 31 additions & 14 deletions SMTP.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
# Use the official Rust image as a base image
FROM rust:latest
# Use the official Rust image as the base image for building
FROM rust:1.73 AS builder

# Set the working directory inside the container
WORKDIR /app
# Install necessary dependencies
RUN apt-get update && apt-get install -y \
git \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Clone the GitHub repository
RUN git clone https://github.com/zkemail/relayer-smtp.git
# Set the working directory in the container
WORKDIR /usr/src/relayer-smtp

# Change to the directory of the cloned repository
WORKDIR /app/relayer-smtp
# Clone the repository
RUN git clone https://github.com/zkfriendly/relayer-smtp.git .

# Build the Rust package
RUN cargo build
# Build the application
RUN cargo build --release

# Expose port
EXPOSE 3000
# Use a minimal base image for the final stage
FROM debian:bookworm-slim

# Specify the command to run when the container starts
CMD ["cargo", "run", "--bin", "relayer-smtp"]
# Install necessary runtime dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Copy the built binary from the builder stage
COPY --from=builder /usr/src/relayer-smtp/target/release/relayer-smtp /usr/local/bin/relayer-smtp

# Expose the port the app runs on
EXPOSE 8080

# Set the default command to run the application
CMD ["/usr/local/bin/relayer-smtp"]
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'

services:
relayer-smtp:
image: wshino/relayer-smtp:latest
container_name: relayer-smtp
ports:
- "3000:3000"
env_file:
- .env
extra_hosts:
- "host.docker.internal:host-gateway"

relayer-imap:
image: wshino/relayer-imap:latest
container_name: relayer-imap
env_file:
- .env
extra_hosts:
- "host.docker.internal:host-gateway"

relayer:
image: wshino/relayer:latest
container_name: relayer
ports:
- "4500:4500"
env_file:
- .env
entrypoint: >
/bin/sh -c "echo \"$IC_PEM_CONTENT\" | base64 -d > /.ic.pem && exec /usr/local/bin/relayer"
extra_hosts:
- "host.docker.internal:host-gateway"