diff --git a/Dockerfile b/Dockerfile index 59c5898..cf4b84c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,33 @@ -FROM sutty/monit:latest +FROM sutty/sdk-ruby:latest AS build MAINTAINER "f " + +RUN install -dm 2750 -o app -g www-data /srv/http + +USER app +WORKDIR /srv/http +COPY --chown=app:www-data ./Gemfile . +COPY --chown=app:www-data ./config.ru . +RUN bundle install --path=./vendor +RUN find ./vendor -name '*.so' | xargs -r strip --strip-unneeded + +FROM sutty/daemonize:latest AS daemonize + +RUN echo /home/builder/packages/home > /etc/apk/repositories +RUN apk add --no-cache daemonize + +FROM sutty/monit +ENV RACK_ENV=production + +RUN addgroup -g 82 -S www-data +RUN adduser -s /bin/sh -G www-data -h /srv/http -D app + +RUN apk add --no-cache ruby ruby-bundler ruby-json +COPY --from=daemonize /usr/sbin/daemonize /usr/sbin/daemonize +COPY ./monit.conf /etc/monit.d/geminabox.conf +COPY ./geminabox.sh /usr/local/bin/geminabox +COPY --from=build /srv/http /srv/http +RUN install -dm 2750 -o app -g www-data /srv/http/geminabox +RUN chmod 755 /usr/local/bin/geminabox + +EXPOSE 9292 +VOLUME /srv/http/geminabox diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..5236acc --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gem 'redis-rack' +gem 'hiredis' +gem 'redis', require: %w[redis redis/connection/hiredis] +gem 'geminabox' +gem 'puma' diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..4173e31 --- /dev/null +++ b/config.ru @@ -0,0 +1,11 @@ +require 'geminabox' +require 'rack/session/redis' + +Geminabox.data = '/srv/http' +Geminabox.rubygems_proxy = true +Geminabox.allow_remote_failure = true + +use Rack::Session::Redis, redis_server: 'redis://redis:6379/2' +use Rack::Protection + +run Geminabox::Server diff --git a/geminabox.sh b/geminabox.sh new file mode 100644 index 0000000..5807572 --- /dev/null +++ b/geminabox.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +dir=/srv/http/geminabox +pid=/tmp/geminabox.pid + +chown -R app:www-data /srv/http +cd ${dir} + +for link in Gemfile Gemfile.lock .bundle config.ru vendor; do + test -e ${link} && continue + ln -s ../${link} . +done + +rm -f ${pid} +daemonize -p ${pid} -l ${pid} -o ${dir}/access.log -e ${dir}/error.log \ + -c ${dir} -a -u app \ + `which bundle` exec rackup diff --git a/monit.conf b/monit.conf new file mode 100644 index 0000000..91829f1 --- /dev/null +++ b/monit.conf @@ -0,0 +1,4 @@ +check process geminabox with pidfile /tmp/geminabox.pid + start program = "/usr/local/bin/geminabox" + stop program = "/bin/sh -c 'cat /tmp/geminabox.pid | xargs kill'" + if failed port 9292 protocol http for 3 times within 5 cycles then restart