This commit is contained in:
parent
16268f51cc
commit
e5a40d941c
5 changed files with 99 additions and 22 deletions
|
@ -2,7 +2,7 @@ pipeline:
|
|||
publish:
|
||||
image: plugins/docker
|
||||
registry: registry.nulo.in
|
||||
repo: registry.nulo.in/sutty/ruby
|
||||
repo: registry.nulo.in/sutty/rails
|
||||
tags:
|
||||
- ${ALPINE_VERSION}-${RUBY_VERSION}.${RUBY_PATCH}
|
||||
- latest
|
||||
|
@ -10,11 +10,11 @@ pipeline:
|
|||
- RUBY_VERSION=${RUBY_VERSION}
|
||||
- RUBY_PATCH=${RUBY_PATCH}
|
||||
- ALPINE_VERSION=${ALPINE_VERSION}
|
||||
- BASE_IMAGE=registry.nulo.in/sutty/monit
|
||||
- BASE_IMAGE=registry.nulo.in/sutty/ruby
|
||||
username: sutty
|
||||
secrets:
|
||||
- docker_password
|
||||
cache_from: registry.nulo.in/sutty/ruby:${ALPINE_VERSION}-${RUBY_VERSION}.${RUBY_PATCH}
|
||||
cache_from: registry.nulo.in/sutty/rails:${ALPINE_VERSION}-${RUBY_VERSION}.${RUBY_PATCH}
|
||||
when:
|
||||
branch: antifascista
|
||||
event: push
|
||||
|
|
37
Dockerfile
37
Dockerfile
|
@ -1,24 +1,23 @@
|
|||
ARG BASE_IMAGE=registry.nulo.in/sutty/ruby
|
||||
ARG ALPINE_VERSION=3.13.6
|
||||
ARG BASE_IMAGE=alpine
|
||||
ARG EMAIL=monit@sutty.nl
|
||||
FROM ${BASE_IMAGE}:${ALPINE_VERSION} as build
|
||||
ARG RUBY_VERSION=2.7
|
||||
ARG RUBY_PATCH=5
|
||||
ENV EMAIL ${EMAIL:-monit@sutty.nl}
|
||||
|
||||
RUN apk add --no-cache ruby~${RUBY_VERSION}.${RUBY_PATCH} patch
|
||||
|
||||
# Patch rubygems to install x86_64-linux-musl gems
|
||||
COPY ./rubygems-platform-musl.patch /tmp/
|
||||
RUN cd /usr/lib/ruby/${RUBY_VERSION}.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch || true
|
||||
|
||||
FROM ${BASE_IMAGE}:${ALPINE_VERSION}
|
||||
ARG EMAIL=monit@sutty.nl
|
||||
FROM ${BASE_IMAGE}:${ALPINE_VERSION}-${RUBY_VERSION}.${RUBY_PATCH}
|
||||
ARG ALPINE_VERSION
|
||||
MAINTAINER "f <f@sutty.nl>"
|
||||
ARG RUBY_VERSION
|
||||
ARG RUBY_PATCH
|
||||
MAINTAINER f <f@sutty.nl>
|
||||
ENV RAILS_ENV production
|
||||
|
||||
# Install ruby and extracted gems and copy patched rubygems
|
||||
RUN apk add --no-cache tzdata ruby~${RUBY_VERSION}.${RUBY_PATCH} && rm /usr/lib/ruby/${RUBY_VERSION}.0/rubygems.rb
|
||||
RUN apk add --no-cache ruby-json ruby-bigdecimal ruby-rake ruby-bundler ruby-irb ruby-io-console ruby-etc
|
||||
COPY --from=build /usr/lib/ruby/${RUBY_VERSION}.0/rubygems.rb /usr/lib/ruby/${RUBY_VERSION}.0/
|
||||
RUN addgroup -g 82 -S www-data
|
||||
RUN adduser -s /bin/sh -G www-data -h /srv -D rails
|
||||
RUN install -dm 750 -o rails -g www-data /srv
|
||||
|
||||
RUN apk add --no-cache jemalloc daemonize
|
||||
|
||||
COPY ./monit.conf /etc/monit.d/rails.conf
|
||||
COPY ./Procfile /etc/Procfile
|
||||
COPY ./entrypoint.sh /usr/local/bin/rails
|
||||
|
||||
VOLUME /srv
|
||||
EXPOSE 3000
|
||||
EXPOSE 9394
|
||||
|
|
8
Procfile
Normal file
8
Procfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
install: bundle install --path ./vendor --without="test development" --no-cache --clean
|
||||
migrate: bundle exec rake db:prepare db:seed
|
||||
rails: bundle exec puma config.ru
|
||||
blazer_5m: bundle exec rake blazer:run_checks SCHEDULE="5 minutes"
|
||||
blazer_1h: bundle exec rake blazer:run_checks SCHEDULE="1 hour"
|
||||
blazer_1d: bundle exec rake blazer:run_checks SCHEDULE="1 day"
|
||||
blazer: bundle exec rake blazer:send_failing_checks
|
||||
prometheus: bundle exec prometheus_exporter -b 0.0.0.0 --prefix "lunar_"
|
40
entrypoint.sh
Executable file
40
entrypoint.sh
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
case $1 in
|
||||
start)
|
||||
su app -c "cd /srv && foreman run -f /etc/Procfile install"
|
||||
su app -c "cd /srv && foreman run -f /etc/Procfile migrate"
|
||||
daemonize -c /srv -u app /usr/bin/foreman start -f /etc/Procfile rails
|
||||
|
||||
;;
|
||||
stop)
|
||||
cat /srv/tmp/puma.pid | xargs -r kill
|
||||
|
||||
;;
|
||||
reload)
|
||||
su app -c "cd /srv && foreman run -f /etc/Procfile install"
|
||||
cat /srv/tmp/puma.pid | xargs -r kill -USR2
|
||||
|
||||
;;
|
||||
prometheus)
|
||||
rm -f /tmp/prometheus.pid
|
||||
|
||||
daemonize -c /srv \
|
||||
-p /tmp/prometheus.pid \
|
||||
-l /tmp/prometheus.pid \
|
||||
-u app \
|
||||
/usr/bin/foreman start -f /etc/Procfile prometheus
|
||||
;;
|
||||
|
||||
prometheus-stop)
|
||||
cat /tmp/prometheus.pid | xargs -r kill
|
||||
|
||||
;;
|
||||
|
||||
blazer)
|
||||
test -z "$2" || schedule="_${2}"
|
||||
su app -c "cd /srv && foreman run -f /etc/Procfile blazer${schedule}"
|
||||
|
||||
;;
|
||||
esac
|
30
monit.conf
Normal file
30
monit.conf
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Rails
|
||||
check process rails with pidfile /srv/tmp/puma.pid
|
||||
start program = "/usr/local/bin/rails start"
|
||||
stop program = "/usr/local/bin/rails stop"
|
||||
|
||||
# Prometheus
|
||||
check process prometheus with pidfile /tmp/prometheus.pid
|
||||
start program = "/usr/local/bin/rails prometheus"
|
||||
stop program = "/usr/local/bin/rails prometheus-stop"
|
||||
|
||||
# Blazer checks
|
||||
check program blazer_5m
|
||||
with path "/usr/local/bin/rails blazer 5m"
|
||||
every 5 cycles
|
||||
if status != 0 then alert
|
||||
|
||||
check program blazer_1h
|
||||
with path "/usr/local/bin/rails blazer 1h"
|
||||
every 60 cycles
|
||||
if status != 0 then alert
|
||||
|
||||
check program blazer_1d
|
||||
with path "/usr/local/bin/rails blazer 1d"
|
||||
every 1440 cycles
|
||||
if status != 0 then alert
|
||||
|
||||
check program blazer
|
||||
with path "/usr/local/bin/rails blazer"
|
||||
every 61 cycles
|
||||
if status != 0 then alert
|
Loading…
Reference in a new issue