Skip to content

Commit

Permalink
feat: minimized docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
aalimsahin committed Nov 6, 2024
1 parent 1784ac0 commit 7f4c814
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 55 deletions.
47 changes: 47 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
RELAYER_ENDPOINT=http://localhost:4500/api/receiveEmail

IMAP_LOGIN_ID=
IMAP_DOMAIN_NAME=imap.gmail.com
IMAP_PORT=993
AUTH_TYPE=password

IMAP_LOGIN_PASSWORD=
# OR
IMAP_CLIENT_ID=
IMAP_CLIENT_SECRET=
IMAP_AUTH_URL=
IMAP_TOKEN_URL=
IMAP_REDIRECT_URL=

JSON_LOGGER=false

SERVER_HOST=localhost
SERVER_PORT=3000
SMTP_DOMAIN_NAME=smtp.gmail.com
SMTP_LOGIN_ID=
SMTP_LOGIN_PASSWORD=

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://localhost:3000/api/sendEmail"

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

DATABASE_URL="postgres://test@localhost/emailauth_test"
RELAYER_EMAIL_ADDR=
WEB_SERVER_ADDRESS="127.0.0.1:4500"
EMAIL_TEMPLATES_PATH=./eml_templates
REGEX_JSON_DIR_PATH="./src/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]"
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"]
62 changes: 33 additions & 29 deletions Relayer.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Use the latest official Rust image as the base
FROM rust:latest
# Stage 1: Build Stage
# Use the official Rust image to build the project
FROM rust:latest AS builder

# Use bash as the shell
SHELL ["/bin/bash", "-c"]
Expand All @@ -15,55 +16,58 @@ RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | b
# Set the working directory
WORKDIR /relayer

# Pre-configure Git to avoid common issues and increase clone verbosity
# 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 project files
# Copy the project files to the build stage
COPY . .

# Remove the packages/relayer directory
RUN rm -rf packages/relayer

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

# Install Foundry
# Install Foundry and add forge to PATH
RUN curl -L https://foundry.paradigm.xyz | bash \
&& source $HOME/.bashrc \
&& foundryup

# Verify Foundry installation
RUN source $HOME/.bashrc && forge --version
&& . $HOME/.bashrc \
&& foundryup \
&& ln -s $HOME/.foundry/bin/forge /usr/local/bin/forge \
&& forge --version

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

# Install Yarn dependencies for contracts
RUN source $HOME/.nvm/nvm.sh && nvm use default && yarn

# Build the contracts using Foundry
RUN source $HOME/.bashrc && forge build

# Copy the project files
COPY packages/relayer /relayer/packages/relayer

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

# Copy the IC PEM file
COPY packages/relayer/.ic.pem /relayer/.ic.pem

# 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 \
libssl-dev \
&& 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 the IC PEM file
COPY --from=builder /relayer/.ic.pem /relayer/.ic.pem

# 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"]
44 changes: 30 additions & 14 deletions SMTP.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
# 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/zkemail/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 \
&& 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"]

0 comments on commit 7f4c814

Please sign in to comment.