From 9c8d426184013a9a6e89923c5bfabead70881e15 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Tue, 13 Apr 2021 22:31:41 +0100 Subject: Add dockerfile (#32) --- .dockerignore | 1 + Dockerfile | 12 ++++++++++++ src/settings.rs | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..9fe342cb --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +./target diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4ef5f15f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# no point in tagging the rust version, currently using nightly +FROM rust:slim-buster + +RUN apt update && apt -y install libssl-dev libpq-dev pkg-config make +RUN rustup default nightly + +WORKDIR /atuin +COPY . /atuin + +RUN cargo build --release + +ENTRYPOINT ["/atuin/target/release/atuin"] diff --git a/src/settings.rs b/src/settings.rs index dcf69a7c..5d19699b 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use chrono::prelude::*; use chrono::Utc; -use config::{Config, File as ConfigFile}; +use config::{Config, Environment, File as ConfigFile}; use directories::ProjectDirs; use eyre::{eyre, Result}; use parse_duration::parse; @@ -94,10 +94,14 @@ impl Settings { create_dir_all(config_dir)?; - let mut config_file = PathBuf::new(); - config_file.push(config_dir); - config_file.push("config.toml"); - let config_file = config_file.as_path(); + let config_file = if let Ok(p) = std::env::var("ATUIN_CONFIG") { + PathBuf::from(p) + } else { + let mut config_file = PathBuf::new(); + config_file.push(config_dir); + config_file.push("config.toml"); + config_file + }; // create the config file if it does not exist @@ -129,7 +133,7 @@ impl Settings { s.set_default("server.host", "127.0.0.1")?; s.set_default("server.port", 8888)?; s.set_default("server.open_registration", false)?; - s.set_default("server.db_uri", "please set a postgres url")?; + s.set_default("server.db_uri", "DEFAULT POSTGRES URI, PLEASE CHANGE")?; if config_file.exists() { s.merge(ConfigFile::with_name(config_file.to_str().unwrap()))?; @@ -139,6 +143,8 @@ impl Settings { file.write_all(example_config)?; } + s.merge(Environment::with_prefix("atuin").separator("_"))?; + // all paths should be expanded let db_path = s.get_str("local.db_path")?; let db_path = shellexpand::full(db_path.as_str())?; -- cgit v1.2.3