Skip to content

Commit cfc2e47

Browse files
authored
Merge pull request #252 from mediadepot/develop
Better Docker support
2 parents 7d0085f + f5ce8eb commit cfc2e47

File tree

10 files changed

+82
-12
lines changed

10 files changed

+82
-12
lines changed

DOCKER.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
1. Run the following commands:
66

77
```
8-
docker-compose up -d database
9-
docker-compose build app
10-
docker-compose run app rake db:create db:migrate
11-
docker-compose run app rake users:create_admin
12-
docker-compose up app
8+
docker-compose up
139
open http://localhost:3000
1410
```
1511

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@ RUN bundle install
1313
COPY . /usr/src/app
1414

1515
EXPOSE 3000
16-
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
16+
17+
# install s6overlay so that we can run cron inside this container as well.
18+
ADD https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-amd64.tar.gz /tmp/
19+
RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C / \
20+
&& mkdir /config \
21+
&& apt-get update \
22+
&& apt-get install -y cron \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
COPY rootfs/ /
26+
VOLUME ["/config"]
27+
28+
ENTRYPOINT ["/init"]

config/environments/production.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# config.assets.css_compressor = :sass
3030

3131
# Do not fall back to locating/compiling missing assets.
32-
config.assets.compile = false
32+
config.assets.compile = (ENV.fetch('KLAXON_COMPILE_ASSETS', 'false').to_s.downcase == 'true')
3333

3434
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
3535
# yet still be able to expire them through the digest params.
@@ -42,7 +42,7 @@
4242
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
4343

4444
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45-
config.force_ssl = true
45+
config.force_ssl = (ENV.fetch('KLAXON_FORCE_SSL', 'true').to_s.downcase == 'true')
4646

4747
# Use the lowest log level to ensure availability of diagnostic information
4848
# when problems arise.

docker-compose.override.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
version: '2.2'
22

33
services:
4-
5-
database:
6-
image: "postgres:9.6"
7-
84
app:
95
ports: ["3000:3000"]
106
environment:

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
version: '2.2'
22

33
services:
4+
database:
5+
image: "postgres:9.6"
6+
healthcheck:
7+
test: ["CMD-SHELL", "pg_isready -U postgres"]
8+
interval: 10s
9+
timeout: 5s
10+
retries: 5
411

512
app:
13+
links:
14+
- database
15+
depends_on:
16+
database:
17+
condition: service_healthy
618
build: .
719
environment:
820
RACK_ENV:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# run klaxon startup commands
4+
cd /usr/src/app
5+
bundle exec rake db:create db:migrate || true
6+
bundle exec rake users:create_admin || true
7+
8+
9+
10+
# Setup cron to run klaxon every 15 mins.
11+
mkdir -p /config
12+
13+
if [[ ! -f /config/klaxon-cron ]]; then
14+
15+
cat > /config/klaxon-cron <<DELIM
16+
#!/usr/bin/with-contenv bash
17+
18+
echo "running klaxon check.."
19+
20+
cd /usr/src/app
21+
bundle exec rake check:all
22+
DELIM
23+
24+
chmod +x /config/klaxon-cron
25+
26+
fi
27+
28+
if [[ ! -f /config/klaxon-crontab ]]; then
29+
30+
echo "*/15 * * * * root /config/klaxon-cron > /proc/1/fd/1 2>&1" > /etc/cron.d/klaxon-crontab
31+
ln -s /config/klaxon-crontab /etc/cron.d/klaxon-crontab
32+
33+
fi

rootfs/etc/services.d/cron/finish

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/execlineb -S0
2+
3+
echo "crond exiting"
4+
s6-svscanctl -t /var/run/s6/services

rootfs/etc/services.d/cron/run

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
echo "starting cron"
4+
5+
#fix link-count, as cron is being a pain, and docker is making hardlink count >0 (very high)
6+
touch /etc/crontab /etc/cron.*/*
7+
8+
exec cron -L 8 -f
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/execlineb -S0
2+
3+
echo "klaxon exiting"
4+
s6-svscanctl -t /var/run/s6/services

rootfs/etc/services.d/klaxon/run

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
echo "starting klaxon"
4+
cd /usr/src/app
5+
bundle exec puma -C "config/puma.rb"

0 commit comments

Comments
 (0)