diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +target diff --git a/.env b/.env index 70274a8..b3d1b2c 100644 --- a/.env +++ b/.env @@ -1,3 +1,8 @@ DATABASE_URL=sqlite://db/db.db + +# PROTOCOL and BASE_URL are used to build links in application PROTOCOL=http -BASE_URL=localhost:8080 \ No newline at end of file +BASE_URL=localhost:8080 + +# HOST tells the app which address to bind to (do not change for docker) default is 0.0.0.0:8080 +# HOST=localhost:8080 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..43dd05d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM rust:1.54 as builder +RUN apt-get update && apt-get install -y sqlite3 && rm -rf /var/lib/apt/lists/* +WORKDIR /usr/src/ics-proxy +COPY . . +RUN cd db && ./create_db.sh +RUN cargo install --path . + +FROM debian:buster-slim +RUN apt-get update && apt-get install -y sqlite3 openssl && rm -rf /var/lib/apt/lists/* +WORKDIR app +COPY --from=builder /usr/local/cargo/bin/ics-proxy ./ics-proxy +COPY --from=builder /usr/src/ics-proxy/db db +COPY templates ./templates +CMD ["./ics-proxy"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..dc2a6cd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3' +services: + ics-proxy: + container_name: ics-proxy + build: . + env_file: .env + ports: + - "8080:8080" + volumes: + - database:/app/db +volumes: + database: diff --git a/src/main.rs b/src/main.rs index fdaa1b6..dfe74ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,6 @@ use uuid::Uuid; extern crate dotenv; use dotenv::dotenv; -use std::env; mod model; use model::Link; @@ -279,6 +278,11 @@ async fn main() -> std::io::Result<()> { let base_url = std::env::var("BASE_URL").expect("BASE_URL environemt variable error, make sure it is set"); + let host = match std::env::var("HOST") { + Ok(host) => host, + Err(_e) => "0.0.0.0:8080".to_string(), + }; + let conf = Config { root: format!("{}://{}", protocol, base_url), }; @@ -287,9 +291,12 @@ async fn main() -> std::io::Result<()> { .await .expect("could not create db pool"); - println!("Listening on: 127.0.0.1:8080, open browser and visit have a try!"); + println!( + "Listening on: {}://{}, open browser and visit have a try!", + protocol, base_url + ); HttpServer::new(move || { - let tera = Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")).unwrap(); + let tera = Tera::new("templates/**/*.html").unwrap(); App::new() .data(db_pool.clone()) // pass database pool to application so we can access it inside handlers @@ -301,9 +308,7 @@ async fn main() -> std::io::Result<()> { .service(web::resource("/index_process").route(web::get().to(index_process))) .service(web::resource("/edit_process").route(web::get().to(edit_process))) }) - .bind("127.0.0.1:8080")? + .bind(host)? .run() .await - - //.route("/{id}/events.ics", web::get().to(make_ics_request)) }