Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dockerize
  • Loading branch information
mpd committed Jul 30, 2017
1 parent 728cd2a commit 6f8f907
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
30 changes: 30 additions & 0 deletions Dockerfile
@@ -0,0 +1,30 @@
FROM library/ruby:2.4.1-slim
MAINTAINER Michael Dungan <mpd@jesters-court.net>

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"]
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,9 @@
version: '3'
services:
fakeimage:
image: xxx/fakeimage
build:
context: .
ports:
- "4567:4567"
restart: always
13 changes: 7 additions & 6 deletions fakeimage.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'logger'
require 'sinatra'
require 'rmagick'
require 'rvg/rvg'
Expand All @@ -10,6 +11,8 @@
'jpg' => 'jpeg'
}.freeze

LOGGER = Logger.new(STDOUT)

get '/' do
"<p>Welcome to fakeimage.</p><p>Please see the README (specifically the 'Use' section) at <a href='http://github.com/xxx/fakeimage'>http://github.com/xxx/fakeimage</a> for usage info so I don't have a chance to let one of the copies get out of date.</p><p>Example: <img src='/243x350.gif?color=darkorchid2&textcolor=!B9AF55' /></p><p>Code: <code>&lt;img src='http://fakeimage.heroku.com/243x350.gif?color=darkorchid2&textcolor=!B9AF55' /&gt;</code>"
end
Expand Down Expand Up @@ -44,6 +47,8 @@
content_type "image/#{format}"
img.to_blob
rescue Exception => e
LOGGER.error("#{e}: #{e.backtrace}")

"<p>Something broke. You can try <a href='/200x200'>this simple test</a>. 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.</p><p>Use this thing like http://host:port/200x300, or add color and textcolor params to decide color.</p><p>Error is: [<code>#{e}</code>]</p>"
end
end
Expand All @@ -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
Binary file added public/favicon.ico
Binary file not shown.

0 comments on commit 6f8f907

Please sign in to comment.