Skip to content

Commit

Permalink
updated dockerfile, docker integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
perpetualcacophony committed Aug 22, 2024
1 parent 713f190 commit 0ebfcad
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
!/src
!/static
!/.cargo
!/Cargo.toml
!/rust-toolchain.toml
!/build.rs
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ built = { version = "0.7.4", features = ["git2"] }
git2 = { version = "0.19", features = ["vendored-libgit2"] }

[features]
default = ["wordle", "nortverse"]
default = []
wordle = ["dep:kwordle"]
nortverse = []
docker = ["wordle", "nortverse"]
59 changes: 48 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
FROM clux/muslrust:nightly AS chef
USER root
RUN cargo install cargo-chef
WORKDIR /app
# rust with musl development utilities & cargo chef preinstalled
FROM ghcr.io/perpetualcacophony/muslrust-chef:nightly AS chef
WORKDIR /build



FROM chef AS planner
COPY . .

# cargo chef prepare wants these files
COPY Cargo.toml .
COPY src/main.rs src/

# create the cargo chef recipe file
RUN cargo +nightly chef prepare --recipe-path recipe.json



FROM chef AS builder
COPY --link --from=planner /app/recipe.json recipe.json
RUN cargo +nightly chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json

# copy recipe file to builder
COPY --link --from=planner /build/recipe.json .

# cargo chef cook to cache dependencies from recipe file
RUN cargo +nightly chef cook \
--release \
--target x86_64-unknown-linux-musl \
--recipe-path recipe.json \
--features docker

# copy the rest of the source code to builder
COPY . .
RUN touch /app/build.rs
RUN cargo +nightly build --release --target x86_64-unknown-linux-musl

# touch the build script to ensure cargo runs it
RUN touch build.rs

# build binary
RUN cargo +nightly build \
--release \
--target x86_64-unknown-linux-musl \
--features docker



# using alpine for small final image
FROM alpine AS runtime
COPY --link --from=builder /app/target/x86_64-unknown-linux-musl/release/slimebot /usr/local/bin/slimebot

# add slimebot user & group
RUN addgroup --system slimebot && \
adduser --system slimebot --ingroup slimebot

EXPOSE 443

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

USER slimebot:slimebot
ENTRYPOINT ["slimebot"]

ENTRYPOINT slimebot
12 changes: 10 additions & 2 deletions src/framework/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use poise::serenity_prelude::{ActivityData, ChannelId, GuildId, RoleId};
use rand::seq::IteratorRandom;
use serde::Deserialize;
Expand Down Expand Up @@ -190,8 +192,14 @@ pub struct DbConfig {
}

impl DbConfig {
pub fn url(&self) -> &str {
&self.url
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");
return db_url.into();
}

(&self.url).into()
}

pub fn username(&self) -> &str {
Expand Down
10 changes: 8 additions & 2 deletions src/framework/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ impl PoiseData {
info!(path, "looking for config file with SLIMEBOT_TOML...");
path
} else {
warn!("SLIMEBOT_TOML env unset, using default path /usr/share/slimebot/slimebot.toml");
"/usr/share/slimebot/slimebot.toml".to_owned()
#[cfg(not(feature = "docker"))]
let path = "./slimebot.toml".to_owned();

#[cfg(feature = "docker")]
let path = "/slimebot.toml".to_owned();

warn!(path, "SLIMEBOT_TOML env unset, using default path");
path
};

let config: super::config::Config = ::config::Config::builder()
Expand Down

0 comments on commit 0ebfcad

Please sign in to comment.