Skip to content

Commit

Permalink
Merge pull request #39 from perpetualcacophony/docker_entrypoint_fix
Browse files Browse the repository at this point in the history
fixing docker entrypoint
  • Loading branch information
perpetualcacophony authored Aug 28, 2024
2 parents d57b700 + d4a52ff commit b0af3ab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ FROM alpine AS runtime
EXPOSE 443

# copy binary from builder
COPY --from=builder --link /build/target/x86_64-unknown-linux-musl/release/slimebot /usr/local/bin/slimebot
COPY --from=builder --link /build/target/x86_64-unknown-linux-musl/release/slimebot /usr/local/bin/

ENV GID=8040
RUN mkdir /etc/slimebot
RUN mkdir /etc/slimebot/secrets

COPY Dockerfile.entrypoint.sh .
COPY Dockerfile.entrypoint.sh /usr/local/bin/

ENTRYPOINT /Dockerfile.entrypoint.sh
ENV GID=8040
ENTRYPOINT Dockerfile.entrypoint.sh
12 changes: 5 additions & 7 deletions Dockerfile.entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
addgroup --system slimebot --gid $GID
adduser --system slimebot --ingroup slimebot

# create secrets directory
mkdir /etc/slimebot
mkdir /etc/slimebot/secrets

# copy docker secrets to new secrets dir
cp /run/secrets/* /etc/slimebot/secrets/

# make secrets readable
chmod -R o+r /etc/slimebot/secrets
# copy slimebot.toml
cp /slimebot.toml /etc/slimebot/

# make config directory readable
chown -R slimebot:slimebot /etc/slimebot/

# run app as slimebot user
su -s /bin/sh slimebot -c slimebot
19 changes: 11 additions & 8 deletions src/framework/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,29 @@ impl Config {
tracing::trace!(
var = "SLIMEBOT_SECRETS_DIR",
value = env,
"using value from environemtn"
"using value from environment"
);

if cfg!(feature = "docker") && env.as_str() != "/run/secrets" {
tracing::warn!("running in docker, but not using docker default secrets directory. are you sure whatever you're doing is worth it?");
if cfg!(feature = "docker") && env.as_str() != "/etc/slimebot/secrets" {
tracing::warn!("running in docker, but not using the expected secrets directory. are you sure whatever you're doing is worth it?");
}

PathBuf::from(env).into()
} else if let Some(ref config) = self.secrets_dir {
tracing::trace!(value = ?config, "using value from config");

if cfg!(feature = "docker") && config != Path::new("/run/secrets") {
tracing::warn!("running in docker, but not using docker default secrets directory. are you sure whatever you're doing is worth it?");
if cfg!(feature = "docker") && config != Path::new("/etc/slimebot/secrets") {
tracing::warn!("running in docker, but not using the expected secrets directory. are you sure whatever you're doing is worth it?");
}

config.into()
} else if cfg!(feature = "docker") {
tracing::trace!(value = "/run/secrets", "using docker default value");
tracing::trace!(
value = "/etc/slimebot/secrets",
"using docker default value"
);

Path::new("/run/secrets").into()
Path::new("/etc/slimebot/secrets").into()
} else {
tracing::error!("no secrets directory specified in config or environment");

Expand Down Expand Up @@ -225,7 +228,7 @@ impl DbConfig {
pub fn url(&self) -> Cow<str> {
#[cfg(feature = "docker")]
if let Ok(db_url) = std::env::var("SLIMEBOT_DB_URL") {
info!(db_url, "using db url override from environment");
tracing::trace!(db_url, "using db url override from environment");
return db_url.into();
}

Expand Down
4 changes: 2 additions & 2 deletions src/framework/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::commands::wordle::core::WordleData;
use mongodb::Database;

use chrono::Utc;
use tracing::{info, trace, warn};
use tracing::{info, warn};
use tracing_unwrap::ResultExt;

use super::Secrets;
Expand Down Expand Up @@ -59,7 +59,7 @@ impl PoiseData {
.try_deserialize()
.expect_or_log("configuration could not be parsed");

trace!("config loaded");
info!("config loaded");

let secrets = Secrets::secret_files(&config.secrets_dir()).await?;

Expand Down

0 comments on commit b0af3ab

Please sign in to comment.