Add initial Dockerfile and script

This commit is contained in:
Christopher Williams 2024-10-04 14:03:01 -04:00
parent 47e2bd6364
commit ca4a157505
5 changed files with 55 additions and 6 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
target/
test/
*.db
*.txt

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM rust as builder
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install lua5.4 liblua5.4-dev -y
RUN cargo build --release
FROM debian:bookworm-slim as runtime
WORKDIR /app
COPY --from=builder /app/target/release/rsslair .
COPY ./run.bash .
RUN apt-get update && apt-get install liblua5.4-0 libssl3 sqlite3 -y
CMD ["./run.bash"]

26
run.bash Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Set the PORT, NO_SCHEDULER and CRON_SCHEDULE environment variables if not set
# RUST_LOG: The log level for the server
# PORT: The port to run the server on
# NO_SCHEDULER: If set to true, the scheduler will not run
# CRON_SCHEDULE: The cron schedule to run the scheduler on
RUST_LOG=${RUST_LOG:-'info'}
PORT=${PORT:-8080}
REDIS_HOST=${REDIS_HOST:-'redis'}
REDIS_PORT=${REDIS_PORT:-6379}
NO_SCHEDULER=${NO_SCHEDULER:-false}
CRON_SCHEDULE=${CRON_SCHEDULE:-'* 1 * * * *'}
NO_ARG_VALUE_ARGS=""
if [ "$NO_SCHEDULER" = "true" ]; then
NO_ARG_VALUE_ARGS+=(" --no-scheduler")
fi
set -x
export RUST_LOG=$RUST_LOG
exec /app/rsslair --port $PORT --cron "$CRON_SCHEDULE" $NO_ARG_VALUE_ARGS

View File

@ -18,6 +18,12 @@ struct Cli {
#[arg(short, long, default_value = "8000")]
port: u16,
#[arg(long, default_value = "127.0.0.1")]
redis_url: String,
#[arg(short, long, default_value = "6379")]
redis_port: u16,
#[arg(short, long)]
no_scheduler: bool,

View File

@ -18,7 +18,6 @@ pub struct Router {
//TODO: Redis to cache the route response
routes: HashMap<String, String>,
port: u16,
redis_conn: redis::Connection,
}
impl fmt::Debug for Router {
@ -31,13 +30,9 @@ impl Router {
pub fn new(routes: HashMap<String, String>, port: u16) -> Router {
debug!("Creating new router with routes: {:?}", routes);
let redis_client = redis::Client::open("redis://127.0.0.1");
let redis_conn = redis_client.unwrap().get_connection().unwrap();
Router {
routes,
port,
redis_conn,
}
}
@ -86,7 +81,7 @@ impl Router {
async move { dyn_reply(word, &s).await }
}
});
warp::serve(routes).run(([0, 0, 0, 0], 3030)).await;
warp::serve(routes).run(([0, 0, 0, 0], self.port)).await;
}
}