Creating and deploying a minimal axum app with loco
toc
create axum app with loco
loco lets you scaffold axum apps in a preditible manner.
cargo install loco-clicargo install sea-orm-cli
create a new minimal axum app:
➜ loco new✔ ❯ App name? · hello_loco✔ ❯ What would you like to build? · lightweight-service (minimal, only controllers and views)
🚂 Loco app generated successfully in:/sandbox/hello_loco
start local app:
cargo loco start
build axum app with docker
use loco to create a simple dockerfile for deployment (this will create a dockerfile and a .dockerignore file.
➜ cargo loco generate deployment Finished dev [unoptimized + debuginfo] target(s) in 0.11s Running `target/debug/hello_loco-cli generate deployment`? ❯ Choose your deployment ›❯ Docker Shuttle Nginx
build the app:
docker build . --tag hello_loco:latest
docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhello_loco latest 0d5bc1271eeb 0 minutes ago 123MB
running production container locally
if we just run our container with no args we will get the loco-cli help menu:
docker run -p 3000:3000 hello_locoThe one-person framework for Rust
Usage: hello_loco-cli [OPTIONS] <COMMAND>
Commands: start Start an app routes Describe all application endpoints task Run a custom task generate code generation creates a set of files and code templates based on a predefined set of rules version Display the app version help Print this message or the help of the given subcommand(s)
Options: -e, --environment <ENVIRONMENT> Specify the environment [default: development] -h, --help Print help -V, --version Print version
to start the app run start:
docker run -p 3000:3000 hello_loco start