Skip to content

Commit 49560e1

Browse files
authored
Add Dockerfile (#60)
1 parent f6a7588 commit 49560e1

File tree

6 files changed

+99
-7
lines changed

6 files changed

+99
-7
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.bundle
2+
.env
3+
.envrc
4+
.idea
5+
.git
6+
coverage
7+
log
8+
spec
9+
tmp
10+
vendor
11+
**/node_modules
12+
**/bower_components
13+
deployment

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Upgrade to Rails 5.1.
66
- Allow default compatibility level to be set via environment variable and
77
change the default for non-production environments.
8+
- Include Dockerfile.
89

910
## v0.11.0
1011
- Change the default fingerprint version to '2'. Set `FINGERPRINT_VERSION=1`

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# To build run: docker build -t avro-schema-registry .
2+
3+
FROM ruby:2.4.2
4+
5+
RUN mkdir /app
6+
WORKDIR /app
7+
8+
# Copy the Gemfile as well as the Gemfile.lock and install
9+
# the RubyGems. This is a separate step so the dependencies
10+
# will be cached unless changes to one of those two files
11+
# are made.
12+
COPY Gemfile Gemfile.lock ./
13+
RUN gem install bundler --no-document && bundle install --jobs 20 --retry 5
14+
15+
COPY . /app
16+
17+
# Run the app as a non-root user. The source code will be read-only,
18+
# but the process will complain if it can't write to tmp or log (even
19+
# though we're writing the logs to STDOUT).
20+
RUN mkdir /app/tmp /app/log
21+
RUN groupadd --system avro && \
22+
useradd --no-log-init --system --create-home --gid avro avro && \
23+
chown -R avro:avro /app/tmp /app/log
24+
USER avro
25+
26+
ENV RACK_ENV=production
27+
ENV RAILS_ENV=production
28+
ENV RAILS_LOG_TO_STDOUT=true
29+
ENV PORT=5000
30+
31+
EXPOSE 5000
32+
33+
# Start puma
34+
CMD bundle exec puma -C config/puma.rb

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,50 @@ anyone can experiment with, just please don't rely on it for production!
167167

168168
There is also a button above to easily deploy your own copy of the application to Heroku.
169169

170+
### Docker
171+
172+
A Dockerfile is provided to run the application within a container. To
173+
build the image, navigate to the root of the repo and run `docker build`:
174+
175+
```bash
176+
docker build . -t avro-schema-registry
177+
```
178+
179+
The container is built for the `production` environment, so you'll
180+
need to pass in a few environment flags to run it:
181+
182+
```bash
183+
docker run -p 5000:5000 -d \
184+
-e DATABASE_URL=postgresql://user:pass@host/dbname \
185+
-e FORCE_SSL=false \
186+
-e SECRET_KEY_BASE=supersecret \
187+
-e SCHEMA_REGISTRY_PASSWORD=avro \
188+
avro-schema-registry
189+
```
190+
191+
If you also want to run PostgreSQL in a container, you can link the two containers:
192+
193+
```bash
194+
docker run --name avro-postgres -d \
195+
-e POSTGRES_PASSWORD=avro \
196+
-e POSTGRES_USER=avro \
197+
postgres:9.6
198+
199+
docker run --name avro-schema-registry --link avro-postgres:postgres -p 5000:5000 -d \
200+
-e DATABASE_URL=postgresql://avro:avro@postgres/avro \
201+
-e FORCE_SSL=false \
202+
-e SECRET_KEY_BASE=supersecret \
203+
-e SCHEMA_REGISTRY_PASSWORD=avro \
204+
avro-schema-registry
205+
```
206+
207+
To setup the database the first time you run the app, you can call
208+
`rails db:setup` from within the container:
209+
210+
```bash
211+
docker exec avro-schema-registry bundle exec rails db:setup
212+
```
213+
170214
## Security
171215

172216
The service is secured using HTTP Basic authentication and should be used with
@@ -241,4 +285,3 @@ This code is available as open source under the terms of the
241285

242286
Bug reports and pull requests are welcome on GitHub at
243287
https://github.com/salsify/avro-schema-registry.
244-

config/database.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ default: &default
1919
encoding: unicode
2020
# For details on connection pooling, see rails configuration guide
2121
# http://guides.rubyonrails.org/configuring.html#database-pooling
22-
pool: 5
22+
pool: <%= ENV.fetch('DB_POOL', 5) %>
23+
variables:
24+
lock_timeout: <%= ENV.fetch('DB_LOCK_TIMEOUT', 0) %>
25+
statement_timeout: <%= ENV.fetch('DB_STATEMENT_TIMEOUT', 0) %>
2326

2427
development:
2528
<<: *default
@@ -80,6 +83,4 @@ test:
8083
#
8184
production:
8285
<<: *default
83-
database: avro-schema-registry_production
84-
username: avro-schema-registry
85-
password: <%= ENV['AVRO-SCHEMA-REGISTRY_DATABASE_PASSWORD'] %>
86+
url: <%= ENV['DATABASE_URL'] %>

config/environments/production.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
3737

3838
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
39-
config.force_ssl = true
39+
config.force_ssl = ActiveRecord::Type::Boolean.new.cast(ENV.fetch('FORCE_SSL', true))
4040

4141
# Use the lowest log level to ensure availability of diagnostic information
4242
# when problems arise.
43-
config.log_level = :info
43+
config.log_level = ENV.fetch('LOG_LEVEL', :info).to_sym
4444

4545
# Prepend all log lines with the following tags.
4646
# config.log_tags = [:request_id]

0 commit comments

Comments
 (0)