add README and build scripts

This commit is contained in:
guochao 2022-08-04 19:02:33 +08:00
parent 79296a634a
commit 0fb0cdd2fd
Signed by: guochao
GPG Key ID: 79F7306D2AA32FC3
4 changed files with 91 additions and 0 deletions

1
.dockerignore Symbolic link
View File

@ -0,0 +1 @@
.gitignore

56
README.md Normal file
View File

@ -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

16
build/Dockerfile Normal file
View File

@ -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" ]

View File

@ -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}