Skip to content

Commit

Permalink
Fixed cache regeneration for changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
lamka02sk committed Jul 5, 2024
1 parent 2a61acb commit cb1d432
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 8 deletions.
6 changes: 5 additions & 1 deletion docker/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ COPY --from=build /lib/x86_64-linux-gnu /lib/x86_64-linux-gnu
COPY --from=build /lib/aarch64-linux-gnu /lib/aarch64-linux-gnu
COPY --from=build /usr/lib/libreoffice /usr/lib/libreoffice
COPY --from=build /usr/share/libreoffice /usr/share/libreoffice
COPY --from=build /etc /etc
COPY --from=build /usr/share/liblangtag /usr/share/liblangtag
COPY --from=build /usr/share/color /usr/share/color
COPY --from=build /usr/share/ghostscript /usr/share/ghostscript
COPY --from=build /usr/share/poppler /usr/share/poppler
COPY --from=build /usr/share/mime /usr/share/mime
COPY --from=build /etc /etc

ENV PATH="/usr/lib/libreoffice/program:${PATH}"
1 change: 1 addition & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ fi

echo "Building picturium v$version"
docker buildx build -t "lamka02sk/picturium:$version" -t lamka02sk/picturium:latest -f build.yml --push --platform=linux/amd64,linux/arm64 --progress=plain --build-context root=./../ .
# docker buildx build -t "lamka02sk/picturium:$version" -t lamka02sk/picturium:latest -f build.yml --load --platform=linux/amd64 --progress=plain --build-context root=./../ .
12 changes: 10 additions & 2 deletions docker/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ COPY --from=lamka02sk/picturium-base:8.15.1 /lib/x86_64-linux-gnu /lib/x86_64-li
COPY --from=lamka02sk/picturium-base:8.15.1 /lib/aarch64-linux-gnu /lib/aarch64-linux-gnu
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/lib/libreoffice /usr/lib/libreoffice
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/libreoffice /usr/share/libreoffice
COPY --from=lamka02sk/picturium-base:8.15.1 /etc /etc
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/liblangtag /usr/share/liblangtag
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/color /usr/share/color
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/ghostscript /usr/share/ghostscript
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/poppler /usr/share/poppler
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/mime /usr/share/mime
COPY --from=lamka02sk/picturium-base:8.15.1 /etc /etc

RUN apt update -y && apt install -y curl gcc && apt autoremove && apt-get clean && rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -39,8 +43,12 @@ COPY --from=build /lib/x86_64-linux-gnu /lib/x86_64-linux-gnu
COPY --from=build /lib/aarch64-linux-gnu /lib/aarch64-linux-gnu
COPY --from=build /usr/lib/libreoffice /usr/lib/libreoffice
COPY --from=build /usr/share/libreoffice /usr/share/libreoffice
COPY --from=build /etc /etc
COPY --from=build /usr/share/liblangtag /usr/share/liblangtag
COPY --from=build /usr/share/color /usr/share/color
COPY --from=build /usr/share/ghostscript /usr/share/ghostscript
COPY --from=build /usr/share/poppler /usr/share/poppler
COPY --from=build /usr/share/mime /usr/share/mime
COPY --from=build /etc /etc
COPY --from=build /home/picturium/picturium/target/release/picturium /usr/local/bin/picturium

RUN ldconfig
Expand Down
1 change: 1 addition & 0 deletions docker/dev.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash

docker buildx build -t lamka02sk/picturium-dev:8.15.1 -f dev.yml --push --platform=linux/amd64 --progress=plain .
#docker buildx build -t lamka02sk/picturium-dev:8.15.1 -f dev.yml --load --platform=linux/amd64 --progress=plain .
6 changes: 5 additions & 1 deletion docker/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ COPY --from=lamka02sk/picturium-base:8.15.1 /lib/x86_64-linux-gnu /lib/x86_64-li
COPY --from=lamka02sk/picturium-base:8.15.1 /lib/aarch64-linux-gnu /lib/aarch64-linux-gnu
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/lib/libreoffice /usr/lib/libreoffice
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/libreoffice /usr/share/libreoffice
COPY --from=lamka02sk/picturium-base:8.15.1 /etc /etc
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/liblangtag /usr/share/liblangtag
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/color /usr/share/color
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/ghostscript /usr/share/ghostscript
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/poppler /usr/share/poppler
COPY --from=lamka02sk/picturium-base:8.15.1 /usr/share/mime /usr/share/mime
COPY --from=lamka02sk/picturium-base:8.15.1 /etc /etc

RUN apt update -y && apt install -y curl gcc && apt autoremove && apt-get clean && rm -rf /var/lib/apt/lists/*

Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use actix_cors::Cors;
use actix_web::{App, HttpServer};
use actix_web::middleware::Logger;
use dotenv::dotenv;
use libvips::VipsApp;
use log::LevelFilter;
use simplelog::{ColorChoice, CombinedLogger, Config, TerminalMode, TermLogger, WriteLogger};

Expand Down Expand Up @@ -40,6 +41,11 @@ async fn main() -> std::io::Result<()> {

let _scheduler_handle = services::scheduler::schedule();

let app = VipsApp::new("vips", false).unwrap();
app.cache_set_max(0);
app.cache_set_max_files(0);
app.cache_set_max_mem(0);

HttpServer::new(|| {

let mut cors = Cors::default()
Expand Down
8 changes: 4 additions & 4 deletions src/pipeline/thumbnail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use std::process::Command;

use libvips::{ops, VipsImage};
use libvips::ops::{Access, Intent, Interesting, ThumbnailOptions};
use libvips::ops::{Intent, Interesting, ThumbnailOptions};

use crate::cache;
use crate::cache::{get_document_path_from_url_parameters, index};
Expand All @@ -16,7 +16,7 @@ use crate::services::vips::get_error_message;
pub(crate) async fn run(working_file: &Path, url_parameters: &UrlParameters<'_>) -> PipelineResult<VipsImage> {

if !is_thumbnail_format(url_parameters.path) {
return match VipsImage::new_from_file_access(&working_file.to_string_lossy(), Access::Sequential, true) {
return match VipsImage::new_from_file(&working_file.to_string_lossy()) {
Ok(image) => Ok(image),
Err(error) => return Err(PipelineError(format!("Failed to open image: {}", error)))
};
Expand All @@ -37,10 +37,10 @@ pub(crate) async fn run(working_file: &Path, url_parameters: &UrlParameters<'_>)

fn generate_pdf_thumbnail(working_file: &Path, url_parameters: &UrlParameters<'_>) -> PipelineResult<VipsImage> {

let pdf = VipsImage::new_from_file_access(&working_file.to_string_lossy(), Access::Sequential, true).unwrap();
let pdf = VipsImage::new_from_file(&working_file.to_string_lossy()).unwrap();
let page_parameter = format!("[page={}]", (url_parameters.thumbnail.page - 1).min(pdf.get_n_pages() as u32 - 1));

let pdf = VipsImage::new_from_file_access(&(working_file.to_string_lossy() + &page_parameter[..]), Access::Sequential, true).unwrap();
let pdf = VipsImage::new_from_file(&(working_file.to_string_lossy() + &page_parameter[..])).unwrap();
let (width, height) = get_rasterize_dimensions(&pdf, url_parameters);

match ops::thumbnail_with_opts(&(working_file.to_string_lossy() + &page_parameter[..]), width, &ThumbnailOptions {
Expand Down

0 comments on commit cb1d432

Please sign in to comment.