From 9993a6b7d9acb6e7dbedecd7d0e2f38f45727458 Mon Sep 17 00:00:00 2001 From: radex Date: Tue, 30 Jan 2024 20:20:21 +0100 Subject: [PATCH] dockerify --- Dockerfile | 18 ++++++++++++++++++ README.md | 1 + main.rb | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2b5c213 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ruby:2.7 + +RUN apt-get update && \ + apt-get install -y cups-ipp-utils && \ + rm -rf /var/lib/apt/lists/* + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 +RUN gem install bundler:1.17.2 + +WORKDIR /usr/src/app + +COPY Gemfile Gemfile.lock ./ +RUN bundle install + +COPY . . + +CMD bundle exec ruby main.rb diff --git a/README.md b/README.md index f348816..44536ff 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,4 @@ to test without spejstore running locally, pass: LABELMAKER_DEBUG_JSON='{"short_id":"abcdef","name":"Some long test item","owner":"testowner"}' bundle exec ruby main.rb ``` +Make sure to pass either `LABELMAKER_LOCAL_PRINTER_NAME` or `LABELMAKER_IPP_PRINTER_URL`. See top of `main.rb` for all env variables available. diff --git a/main.rb b/main.rb index 6b50b88..b2b13fc 100644 --- a/main.rb +++ b/main.rb @@ -98,9 +98,9 @@ post '/api/1/print/:id' do temp.close if not LOCAL_PRINTER_NAME.empty? - system("lpr -P #{LOCAL_PRINTER_NAME.shellescape} #{temp.path.shellescape}") + system("lpr -P #{LOCAL_PRINTER_NAME.shellescape} #{temp.path.shellescape}", exception: true) elsif not IPP_PRINTER_URL.empty? - system("ipptool -v -tf #{temp.path.shellescape} -d filetype=application/octet-stream -I #{IPP_PRINTER_URL.shellescape} ipptool-print-job.test") + system("ipptool -v -tf #{temp.path.shellescape} -d filetype=application/octet-stream -I #{IPP_PRINTER_URL.shellescape} ipptool-print-job.test", exception: true) else status 404 return "No printer configured"