From 0fb0cdd2fdc39b68491230ce36f2795bdf324f46 Mon Sep 17 00:00:00 2001 From: guochao Date: Thu, 4 Aug 2022 19:02:33 +0800 Subject: [PATCH] add README and build scripts --- .dockerignore | 1 + README.md | 56 ++++++++++++++++++++++++++++++++++++++ build/Dockerfile | 16 +++++++++++ scripts/build-container.sh | 18 ++++++++++++ 4 files changed, 91 insertions(+) create mode 120000 .dockerignore create mode 100644 README.md create mode 100644 build/Dockerfile create mode 100644 scripts/build-container.sh diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac54843 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# Rust Template Project for Development with Actix-Web and SeaORM + +## A lot of Thanks to these projects + +This project template is made of: + +- Rust +- [actix-web](https://actix.rs): Async web framework for rust +- [SeaORM](https://www.sea-ql.org/SeaORM/): async ORM for integrating a Rust code base with relational databases + +And I won't reach this without the help of: +- sqlx +- askama +- clap +- clap_complete +- serde +- env_logger +- log + +## Project strucutre + +- [src](src) + - [main.rs](src/main.rs): entrypoint + - [completion.rs](src/completion.rs): shell completion + - [migrations](src/migrations): migration scripts + - [web](src/web/): web apis + - [urls.rs](src/web/urls.rs): routes + - [model](src/web/model/): models generated by sea-orm-cli + - [view.rs](src/web/view.rs): url handlers + - [controller.rs](src/web/controller.rs): logics +- [README](README.md) +- [build](build): build tools +- [scripts](scripts): automation scripts + +## Start from here + +### Run the server + +Simply use cargo to run the project + +### Package into container + +The template provides a simple [Dockerfile](build/Dockerfile) and [script](scripts/build-container.sh) to build container image. + +## Development + +### Define a new model + +> TODO + +## Roadmap + +- [x] Web +- [x] ORM +- [x] Packaging +- [ ] React \ No newline at end of file diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..013997e --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,16 @@ +ARG RUST_VERSION="1.62" +ARG ALPINE_VERSION="3.16" + +FROM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} +ARG APK_MIRROR="" +ARG CRATES_MIRROR="" + +RUN [ ! -z "${APK_MIRROR}" ] && sed -i "s/dl-cdn.alpinelinux.org/${APK_MIRROR}/g" /etc/apk/repositories; apk update; apk add gcc sqlite +RUN [ ! -z "${CRATES_MIRROR}" ] && printf '[source.crates-io]\nreplace-with = "mirror"\n\n[source.mirror]\nregistry = "%s"\n' "${CRATES_MIRROR}" > $CARGO_HOME/config; true +ADD . /src +WORKDIR /src +RUN cargo build --release + +FROM alpine:${ALPINE_VERSION}} +COPY --from=0 /src/target/release/rust-template /bin/rust-template +ENTRYPOINT [ "/bin/rust-template" ] \ No newline at end of file diff --git a/scripts/build-container.sh b/scripts/build-container.sh new file mode 100644 index 0000000..42e6ef6 --- /dev/null +++ b/scripts/build-container.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +IMAGE=${IMAGE:-demo-server:$(date +%F)} + +SCRIPTDIR=$(dirname $0) +BASEDIR=$(dirname $SCRIPTDIR) + +ARGS=() + +if [ ! -z "$APK_MIRROR" ]; then + ARGS+=(--build-args APK_MIRROR=${APK_MIRROR}) +fi + +if [ ! -z "$CRATES_MIRROR" ]; then + ARGS+=(--build-args CRATES_MIRROR=${CRATES_MIRROR}) +fi + +docker build -t $IMAGE -f ${BASEDIR}/build/Dockerfile "${ARGS[@]}" ${BASEDIR}