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

Use cross-compilation for CI, build the Docker image from source. #85

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
465 changes: 170 additions & 295 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

81 changes: 19 additions & 62 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,64 @@ on:
workflow_dispatch:
pull_request:
push:
tags:
- '*'
tags: ["v*.*.*"]
branches: ["*"]

jobs:
style:
name: Check Style
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
profile: minimal
override: true

- name: cargo fmt -- --check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Check Style
run: cargo fmt --all --check

test:
name: Test
needs: [style]
needs: style
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -yq protobuf-compiler
wget https://github.com/glauth/glauth/releases/download/v2.2.0/glauth-linux-arm64
curl -LO https://github.com/glauth/glauth/releases/download/v2.2.0/glauth-linux-arm64
chmod a+rx glauth-linux-arm64
nohup ./glauth-linux-arm64 -c tests/resources/ldap.cfg &
wget https://dl.min.io/server/minio/release/linux-amd64/archive/minio_20230629051228.0.0_amd64.deb -O minio.deb
curl -Lo minio.deb https://dl.min.io/server/minio/release/linux-amd64/archive/minio_20230629051228.0.0_amd64.deb
sudo dpkg -i minio.deb
mkdir ~/minio
nohup minio server ~/minio --console-address :9090 &
wget https://dl.min.io/client/mc/release/linux-amd64/mc
curl -LO https://dl.min.io/client/mc/release/linux-amd64/mc
chmod a+rx mc
./mc alias set myminio http://localhost:9000 minioadmin minioadmin
./mc mb tmp

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2

- name: JMAP Protocol Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=crates/jmap-proto/Cargo.toml
run: cargo test -p jmap_proto -- --nocapture

- name: IMAP Protocol Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=crates/imap-proto/Cargo.toml
run: cargo test -p imap_proto -- --nocapture

- name: Full-text search Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=crates/store/Cargo.toml

#- name: Store Tests
# uses: actions-rs/cargo@v1
# with:
# command: test
# args: --manifest-path=tests/Cargo.toml store -- --nocapture
run: cargo test -p store -- --nocapture

- name: Directory Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=tests/Cargo.toml directory -- --nocapture
run: cargo test -p tests directory -- --nocapture

- name: SMTP Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=tests/Cargo.toml smtp -- --nocapture
run: cargo test -p tests smtp -- --nocapture

- name: IMAP Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=tests/Cargo.toml imap -- --nocapture
run: cargo test -p tests imap -- --nocapture

- name: JMAP Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=tests/Cargo.toml jmap -- --nocapture
run: cargo test -p tests jmap -- --nocapture
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 39 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
FROM debian:bullseye-slim

RUN apt-get update -y && apt-get install -yq ca-certificates curl

COPY resources/docker/configure.sh /usr/local/bin/configure.sh
COPY resources/docker/entrypoint.sh /usr/local/bin/entrypoint.sh

RUN sed -i -e 's/__C__/all-in-one/g' /usr/local/bin/configure.sh && \
sed -i -e 's/__R__/mail-server/g' /usr/local/bin/configure.sh && \
sed -i -e 's/__N__/mail/g' /usr/local/bin/configure.sh && \
sed -i -e 's/__B__/stalwart-mail/g' /usr/local/bin/entrypoint.sh

RUN chmod a+rx /usr/local/bin/*.sh

RUN /usr/local/bin/configure.sh --download

RUN useradd stalwart-mail -s /sbin/nologin -M
RUN mkdir -p /opt/stalwart-mail
RUN chown stalwart-mail:stalwart-mail /opt/stalwart-mail

VOLUME [ "/opt/stalwart-mail" ]

EXPOSE 8080 25 587 465 143 993 4190

ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]
FROM --platform=$BUILDPLATFORM docker.io/lukemathwalker/cargo-chef:latest-rust-slim-bookworm AS chef
WORKDIR /build

FROM --platform=$BUILDPLATFORM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path /recipe.json

FROM --platform=$BUILDPLATFORM chef AS builder
ARG TARGETPLATFORM
RUN case "${TARGETPLATFORM}" in \
"linux/arm64") echo "aarch64-unknown-linux-gnu" > /target.txt && echo "-C linker=aarch64-linux-gnu-gcc" > /flags.txt ;; \
"linux/amd64") echo "x86_64-unknown-linux-gnu" > /target.txt && echo "-C linker=x86_64-linux-gnu-gcc" > /flags.txt ;; \
*) exit 1 ;; \
esac
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -yq build-essential libclang-16-dev \
g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
RUN rustup target add "$(cat /target.txt)"
COPY --from=planner /recipe.json /recipe.json
RUN RUSTFLAGS="$(cat /flags.txt)" cargo chef cook --target "$(cat /target.txt)" --release --recipe-path /recipe.json
COPY . .
RUN RUSTFLAGS="$(cat /flags.txt)" cargo build --target "$(cat /target.txt)" --release -p mail-server -p stalwart-cli -p stalwart-install
RUN mv "/build/target/$(cat /target.txt)/release" "/output"

FROM docker.io/debian:bookworm-slim
ENV STALWART_COMPONENT=all-in-one
WORKDIR /opt/stalwart-mail
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -yq ca-certificates
COPY --from=builder /output/stalwart-mail /usr/local/bin
COPY --from=builder /output/stalwart-cli /usr/local/bin
COPY --from=builder /output/stalwart-install /usr/local/bin
COPY ./resources/docker/entrypoint.sh /usr/local/bin
COPY ./resources/docker/configure.sh /usr/local/bin
RUN chmod -R 755 /usr/local/bin
CMD ["/usr/local/bin/stalwart-mail"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh", "/opt/stalwart-mail/etc"]
2 changes: 1 addition & 1 deletion crates/directory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tokio = { version = "1.23", features = ["net"] }
tokio-rustls = { version = "0.25.0"}
rustls = "0.22"
rustls-pki-types = { version = "1" }
ldap3 = { version = "0.11.1", default-features = false, features = ["tls-rustls"] }
ldap3 = { git = "https://github.com/33KK/ldap3.git", default-features = false, features = ["tls-rustls"] }
deadpool = { version = "0.10.0", features = ["managed", "rt_tokio_1"] }
parking_lot = "0.12"
async-trait = "0.1.68"
Expand Down
3 changes: 1 addition & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

# Stalwart Mail install script -- based on the rustup installation script.

set -e
set -u
set -eu

readonly BASE_URL="https://github.com/stalwartlabs/mail-server/releases/latest/download"

Expand Down
Loading