Skip to content

Commit 397332a

Browse files
author
pbmolini
committed
Made whenever and cron work in Docker
1 parent dbe78b8 commit 397332a

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
77
&& curl -sL https://deb.nodesource.com/setup_9.x | bash - \
88
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
99
&& apt-get update \
10-
&& apt-get install -qq -y --no-install-recommends build-essential nodejs yarn \
10+
&& apt-get install -qq -y --no-install-recommends build-essential nodejs yarn cron \
1111
&& rm -rf /var/lib/apt/lists/* \
1212
&& cp /usr/share/zoneinfo/Europe/Rome /etc/localtime
1313

@@ -45,4 +45,5 @@ COPY ./docker-entrypoint.sh /
4545
RUN chmod +x /docker-entrypoint.sh
4646
ENTRYPOINT ["/docker-entrypoint.sh"]
4747

48-
CMD bundle exec puma
48+
RUN bundle exec whenever --update-crontab --set environment=development
49+
CMD cron && bundle exec puma

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ gem 'browser'
131131
# Graphs (using a forked version)
132132
gem 'gexf', '~> 0.0.7', git: 'https://github.com/Commonfare-net/gexf.rb.git', require: false
133133

134+
# Easy cron jobs
135+
gem 'whenever'
136+
134137
group :development, :test do
135138
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
136139
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

Gemfile.lock

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ GEM
120120
mime-types (>= 1.16)
121121
childprocess (0.7.1)
122122
ffi (~> 1.0, >= 1.0.11)
123+
chronic (0.10.2)
123124
chunky_png (1.3.10)
124125
cocoon (1.2.11)
125126
coderay (1.1.1)
@@ -401,6 +402,8 @@ GEM
401402
websocket-driver (0.6.5)
402403
websocket-extensions (>= 0.1.0)
403404
websocket-extensions (0.1.2)
405+
whenever (0.10.0)
406+
chronic (>= 0.6.3)
404407
xml-simple (1.1.5)
405408
xpath (2.1.0)
406409
nokogiri (~> 1.3)
@@ -474,6 +477,7 @@ DEPENDENCIES
474477
web-console (>= 3.3.0)
475478
webpacker
476479
webpacker-react
480+
whenever
477481

478482
BUNDLED WITH
479483
1.16.1

config/schedule.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this file to easily define all of your cron jobs.
2+
#
3+
# It's helpful, but not entirely necessary to understand cron before proceeding.
4+
# http://en.wikipedia.org/wiki/Cron
5+
set :chronic_options, hours24: true
6+
# clone the environment
7+
ENV.each { |k, v| env(k, v) }
8+
set :output, '/host_tmp/cron_log.log'
9+
every :monday, at: '1:00' do
10+
rake 'nda:commoners_objects_graph'
11+
end
12+
13+
# Example:
14+
#
15+
# set :output, "/path/to/my/cron_log.log"
16+
#
17+
# every 2.hours do
18+
# command "/usr/bin/some_great_command"
19+
# runner "MyModel.some_method"
20+
# rake "some:great:rake:task"
21+
# end
22+
#
23+
# every 4.days do
24+
# runner "AnotherModel.prune_old_records"
25+
# end
26+
27+
# Learn more: http://github.com/javan/whenever

docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ services:
88
command: >
99
bash -c "
1010
rm -f /app/tmp/pids/development.pid;
11-
rails server -p 3000 -b 0.0.0.0 --pid /app/tmp/pids/development.pid
11+
bundle exec whenever --update-crontab --set environment=development;
12+
cron && rails server -p 3000 -b 0.0.0.0 --pid /app/tmp/pids/development.pid
1213
"
1314
volumes:
1415
- ~/tmp:/host_tmp

0 commit comments

Comments
 (0)