Rust is a multi-paradigm, general-purpose programming language that emphasizes performance, type safety, and concurrency. It enforces memory safety—ensuring that all references point to valid memory—without requiring the use of a garbage collector or reference counting present in other memory-safe languages. To simultaneously enforce memory safety and prevent concurrent data races, its "borrow checker" tracks the object lifetime of all references in a program during compilation. Rust is popularized for systems programming but also has high-level features including some functional programming constructs.
wikipedia.org/wiki/Rust_(programming_language)
Create a Makejail in your Rust app project.
INCLUDE options/network.makejail
INCLUDE gh+AppJail-makejails/rust
WORKDIR /app
COPY app/
RUN rustc hello.rs
STAGE cmd
WORKDIR /app
RUN ./hello
Where options/network.makejail are the options that suit your environment, for example:
ARG network
ARG interface=rustapp
OPTION virtualnet=${network}:${interface} default
OPTION nat
Open a shell and run appjail makejail:
appjail makejail -j rustapp -- --network developmentTo run the application we can use appjail run:
# appjail run rustapp
Hello, world!If we get the size of the previous jail
# appjail stop rustapp
...
# appjail cmd local rustapp du -sh
789M .we have a very large jail to run a simple binary. For compiled programming languages we could use Makejail builders to reduce the size of the jail.
Makejail:
OPTION start
OPTION overwrite
EXEC --name rustapp-builder --file build.makejail --arg network=development --arg interface=rstappb
WORKDIR /app
COPY --jail rustapp-builder /app/hello
DESTROY --force rustapp-builder
STAGE cmd
WORKDIR /app
RUN ./hello
build.makejail:
INCLUDE options/network.makejail
INCLUDE gh+AppJail-makejails/rust
WORKDIR /app
COPY app/
RUN rustc hello.rs
For simplicity, Makejail does not use more options than necessary, but you can use as many as you want without affecting build.makejail.
Open a shell and run appjail makejail:
appjail makejail -j rustappNow our jail with the application we want to run has a very reduced size.
# appjail stop rustapp
...
# appjail cmd local rustapp du -sh
13M .Much of the size overhead if for jail, but for big applications this is not harmful.
rust_from(default:ghcr.io/appjail-makejails/rust): Location of OCI image. See also OCI Configuration.rust_tag(default:latest): OCI image tag. See also OCI Configuration.
build:
variants:
- tag: 15.0
containerfile: Containerfile.pkg
aliases: ["latest"]
default: true
args:
FREEBSD_RELEASE: "15.0"