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 development
To 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 rustapp
Now 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_tag
(default:13.4
): see #tags.rust_ajspec
(default:gh+AppJail-makejails/rust
): Entry point where theappjail-ajspec(5)
file is located.
Tag | Arch | Version | Type |
---|---|---|---|
13.4 |
amd64 |
13.4-RELEASE |
thin |
14.2 |
amd64 |
14.2-RELEASE |
thin |