Run server in docker container, added log file

This commit is contained in:
Tyler Hallada 2020-11-09 02:00:14 -05:00
parent 5413fba309
commit e44aa9ddfc
6 changed files with 29 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
/target /target
**/*.rs.bk **/*.rs.bk
.env .env
.env.docker
Session.vim Session.vim
src/db/refinery.toml src/db/refinery.toml
tags tags

12
Cargo.lock generated
View File

@ -146,6 +146,7 @@ dependencies = [
"sqlx", "sqlx",
"tokio", "tokio",
"tracing", "tracing",
"tracing-appender",
"tracing-futures", "tracing-futures",
"tracing-subscriber", "tracing-subscriber",
"url", "url",
@ -1937,6 +1938,17 @@ dependencies = [
"tracing-core", "tracing-core",
] ]
[[package]]
name = "tracing-appender"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7aa52d56cc0d79ab604e8a022a1cebc4de33cf09dc9933c94353bea2e00d6e88"
dependencies = [
"chrono",
"crossbeam-channel",
"tracing-subscriber",
]
[[package]] [[package]]
name = "tracing-attributes" name = "tracing-attributes"
version = "0.1.9" version = "0.1.9"

View File

@ -28,6 +28,7 @@ url = "2.1"
async-trait = "0.1" async-trait = "0.1"
seahash = "4.0" seahash = "4.0"
tracing = "0.1" tracing = "0.1"
tracing-appender = "0.1"
tracing-subscriber = "0.2" tracing-subscriber = "0.2"
tracing-futures = "0.2" tracing-futures = "0.2"
lru = "0.5" lru = "0.5"

View File

@ -10,6 +10,7 @@ FROM ${BASE_IMAGE} AS builder
# Add our source code. # Add our source code.
ADD --chown=rust:rust . ./ ADD --chown=rust:rust . ./
ENV SQLX_OFFLINE true
# Build our application. # Build our application.
RUN cargo build --release RUN cargo build --release
@ -19,4 +20,8 @@ RUN apk --no-cache add ca-certificates
COPY --from=builder \ COPY --from=builder \
/home/rust/src/target/x86_64-unknown-linux-musl/release/bazaar_realm_api \ /home/rust/src/target/x86_64-unknown-linux-musl/release/bazaar_realm_api \
/usr/local/bin/ /usr/local/bin/
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/bazaarrealm.log
CMD /usr/local/bin/bazaar_realm_api CMD /usr/local/bin/bazaar_realm_api

View File

@ -6,6 +6,10 @@ services:
volumes: volumes:
- cargo:/home/rust/.cargo - cargo:/home/rust/.cargo
- target:/home/rust/src/target - target:/home/rust/src/target
env_file:
- .env.docker
ports:
- "3030:3030"
volumes: volumes:
cargo: {} cargo: {}

View File

@ -68,9 +68,15 @@ async fn main() -> Result<()> {
dotenv().ok(); dotenv().ok();
let env_log_filter = let env_log_filter =
env::var("RUST_LOG").unwrap_or_else(|_| "warp=info,bazaar_realm_api=info".to_owned()); env::var("RUST_LOG").unwrap_or_else(|_| "warp=info,bazaar_realm_api=info".to_owned());
let file_appender = tracing_appender::rolling::hourly(
env::var("LOG_DIR").unwrap_or_else(|_| ".".to_owned()),
"bazaarrealm.log",
);
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_env_filter(env_log_filter) .with_env_filter(env_log_filter)
.with_span_events(FmtSpan::CLOSE) .with_span_events(FmtSpan::CLOSE)
.with_writer(non_blocking)
.init(); .init();
let host = env::var("HOST").expect("`HOST` environment variable not defined"); let host = env::var("HOST").expect("`HOST` environment variable not defined");