diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..100ec3c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM library/ruby:2.4.1-slim +MAINTAINER Michael Dungan + +RUN gem update bundler && \ + apt-get update && \ + apt-get install -y \ + build-essential \ + git \ + libmagickcore-dev \ + libmagickwand-dev \ + wget && \ + wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 && \ + chmod +x /usr/local/bin/dumb-init && \ + mkdir /srv/fakeimage + +COPY Gemfile /srv/fakeimage +COPY Gemfile.lock /srv/fakeimage +WORKDIR /srv/fakeimage +RUN bundle config github.https true && \ + bundle install && \ + apt-get clean && \ + apt-get remove -y build-essential git && \ + apt-get purge && \ + apt-get autoremove -y + +COPY . /srv/fakeimage + +EXPOSE 4567 + +CMD ["dumb-init", "ruby", "fakeimage.rb", "-o", "0.0.0.0"] diff --git a/README.md b/README.md index 3d0fb19..baa26ba 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ bundle ruby fakeimage.rb (or your rack-app-handler of choice) ``` +A `Dockerfile` and `docker-compose.yml` are included in the distribution if preferred. Getting up and running +locally should require nothing more than `docker-compose up` in that case. + ## Use In a browser, hit `http://localhost:4567/300x200` for example, or change bg and text colors by passing them as GET params: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1270bf6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3' +services: + fakeimage: + image: xxx/fakeimage + build: + context: . + ports: + - "4567:4567" + restart: always diff --git a/fakeimage.rb b/fakeimage.rb index 4f7ae7a..5a8704a 100644 --- a/fakeimage.rb +++ b/fakeimage.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'logger' require 'sinatra' require 'rmagick' require 'rvg/rvg' @@ -10,6 +11,8 @@ 'jpg' => 'jpeg' }.freeze +LOGGER = Logger.new(STDOUT) + get '/' do "

Welcome to fakeimage.

Please see the README (specifically the 'Use' section) at http://github.com/xxx/fakeimage for usage info so I don't have a chance to let one of the copies get out of date.

Example:

Code: <img src='http://fakeimage.heroku.com/243x350.gif?color=darkorchid2&textcolor=!B9AF55' />" end @@ -44,6 +47,8 @@ content_type "image/#{format}" img.to_blob rescue Exception => e + LOGGER.error("#{e}: #{e.backtrace}") + "

Something broke. You can try this simple test. If this error occurs there as well, you are probably missing app dependencies. Make sure RMagick is installed correctly. If the test works, you are probably passing bad params in the url.

Use this thing like http://host:port/200x300, or add color and textcolor params to decide color.

Error is: [#{e}]

" end end @@ -52,10 +57,6 @@ def color_convert(original) return unless original - - if original.index('!').zero? - original.tr('!', '#') - else - original - end + return original.tr('!', '#') if original.index('!') == 0 + original end diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..2574514 Binary files /dev/null and b/public/favicon.ico differ