Skip to content

Commit

Permalink
add nested
Browse files Browse the repository at this point in the history
fix dockerfile
  • Loading branch information
TOwInOK committed Oct 26, 2024
1 parent a9b1865 commit c1d70af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ ENV CARGO_HTTP_MULTIPLEXING=false
# Первый этап - Подготовка рецепта
FROM base AS planner
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
# Создаем пустую main.rs чтобы cargo chef мог проанализировать зависимости
# Копируем только Cargo.toml
COPY Cargo.toml ./
# Создаем пустую структуру проекта
RUN mkdir src && \
echo "fn main() {}" > src/main.rs
RUN cargo chef prepare --recipe-path recipe.json
echo "fn main() {}" > src/main.rs && \
# Создаем Cargo.lock
cargo generate-lockfile && \
# Подготавливаем рецепт
cargo chef prepare --recipe-path recipe.json

# Второй этап - Сборка зависимостей
FROM base AS cacher
WORKDIR /app
COPY --from=planner /app/recipe.json recipe.json
# Собираем только зависимости
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
cargo chef cook --release --recipe-path recipe.json

# Третий этап - Финальная сборка
Expand All @@ -33,12 +36,10 @@ WORKDIR /app
# Копируем собранные зависимости
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo/registry /usr/local/cargo/registry
COPY --from=cacher /usr/local/cargo/git /usr/local/cargo/git
# Копируем исходный код
COPY . .
# Собираем только наш код
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
cargo build --release --offline

# Финальный образ
Expand Down
10 changes: 7 additions & 3 deletions src/waifu/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,23 @@ pub async fn generate(
categorie: &Categories,
ctx: &Context<'_>,
) -> Result<Vec<CreateEmbed>, anime_grubber::error::Error> {
let categorie_str = std::convert::Into::<&str>::into(categorie);
let categorie_str = format!(
"{}: {}",
std::convert::Into::<&str>::into(categorie),
categorie.deepest_str()
);
let user = ctx.author().name.as_str();
let user_avatar = ctx.author().avatar_url().unwrap_or_default();
if !many {
let image = fetch(categorie).await?;
Ok(vec![
generate_post(&image, user, &user_avatar, categorie_str).await?,
generate_post(&image, user, &user_avatar, &categorie_str).await?,
])
} else {
let mut vec = vec![];
let images = fetch_many(categorie.clone()).await?;
for url in images.iter().take(3) {
vec.push(generate_post(url, user, &user_avatar, categorie_str).await?)
vec.push(generate_post(url, user, &user_avatar, &categorie_str).await?)
}
Ok(vec)
}
Expand Down

0 comments on commit c1d70af

Please sign in to comment.