Skip to content

Commit 0fa6cd2

Browse files
committed
Add Dockerfile
This commit adds a Dockerfile so Stringer can easily be ran in Docker. For convenience there's a single container running both Unicorn as well as cronjobs. This goes a little against the Docker mantra of running only a single process per container, but hey :-)
1 parent 268dd6b commit 0fa6cd2

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Dockerfile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM ruby:2.3.3
2+
3+
ENV RACK_ENV=production
4+
ENV PORT=8080
5+
6+
EXPOSE 8080
7+
8+
WORKDIR /app
9+
ADD Gemfile Gemfile.lock /app/
10+
RUN bundle install --deployment
11+
12+
RUN apt-get update \
13+
&& apt-get install -y --no-install-recommends \
14+
supervisor locales nodejs \
15+
&& apt-get clean \
16+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
17+
18+
RUN DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales \
19+
&& locale-gen C.UTF-8 \
20+
&& /usr/sbin/update-locale LANG=C.UTF-8
21+
22+
ENV LC_ALL C.UTF-8
23+
24+
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.3/supercronic-linux-amd64 \
25+
SUPERCRONIC=supercronic-linux-amd64 \
26+
SUPERCRONIC_SHA1SUM=96960ba3207756bb01e6892c978264e5362e117e
27+
28+
RUN curl -fsSLO "$SUPERCRONIC_URL" \
29+
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
30+
&& chmod +x "$SUPERCRONIC" \
31+
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
32+
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
33+
34+
ADD docker/supervisord.conf /etc/supervisord.conf
35+
ADD docker/start.sh /app/
36+
ADD . /app
37+
38+
RUN useradd -m stringer
39+
RUN chown -R stringer:stringer /app
40+
USER stringer
41+
42+
CMD /app/start.sh

docker/start.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
: ${FETCH_FEEDS_CRON:='*/5 * * * *'}
3+
: ${CLEANUP_CRON:='0 0 * * *'}
4+
5+
cat <<EOF > /app/crontab
6+
$FETCH_FEEDS_CRON cd /app && bundle exec rake fetch_feeds
7+
$CLEANUP_CRON cd /app && bundle exec rake cleanup_old_stories
8+
EOF
9+
10+
exec /usr/bin/supervisord -c /etc/supervisord.conf

docker/supervisord.conf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[supervisord]
2+
nodaemon=true
3+
loglevel=debug
4+
5+
[program:unicorn]
6+
command=bash -c 'bundle exec rake db:migrate && bundle exec unicorn -p $PORT -c ./config/unicorn.rb'
7+
directory=/app
8+
autostart=true
9+
autorestart=true
10+
redirect_stderr=true
11+
stopsignal = QUIT
12+
13+
[program:cron]
14+
command = /usr/local/bin/supercronic /app/crontab
15+
autostart=true
16+
autorestart=true

0 commit comments

Comments
 (0)