Skip to content

Commit

Permalink
Add Dockerfile (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
atsheehan authored Feb 16, 2018
1 parent f6a7588 commit 49560e1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.bundle
.env
.envrc
.idea
.git
coverage
log
spec
tmp
vendor
**/node_modules
**/bower_components
deployment
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Upgrade to Rails 5.1.
- Allow default compatibility level to be set via environment variable and
change the default for non-production environments.
- Include Dockerfile.

## v0.11.0
- Change the default fingerprint version to '2'. Set `FINGERPRINT_VERSION=1`
Expand Down
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# To build run: docker build -t avro-schema-registry .

FROM ruby:2.4.2

RUN mkdir /app
WORKDIR /app

# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler --no-document && bundle install --jobs 20 --retry 5

COPY . /app

# Run the app as a non-root user. The source code will be read-only,
# but the process will complain if it can't write to tmp or log (even
# though we're writing the logs to STDOUT).
RUN mkdir /app/tmp /app/log
RUN groupadd --system avro && \
useradd --no-log-init --system --create-home --gid avro avro && \
chown -R avro:avro /app/tmp /app/log
USER avro

ENV RACK_ENV=production
ENV RAILS_ENV=production
ENV RAILS_LOG_TO_STDOUT=true
ENV PORT=5000

EXPOSE 5000

# Start puma
CMD bundle exec puma -C config/puma.rb
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,50 @@ anyone can experiment with, just please don't rely on it for production!

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

### Docker

A Dockerfile is provided to run the application within a container. To
build the image, navigate to the root of the repo and run `docker build`:

```bash
docker build . -t avro-schema-registry
```

The container is built for the `production` environment, so you'll
need to pass in a few environment flags to run it:

```bash
docker run -p 5000:5000 -d \
-e DATABASE_URL=postgresql://user:pass@host/dbname \
-e FORCE_SSL=false \
-e SECRET_KEY_BASE=supersecret \
-e SCHEMA_REGISTRY_PASSWORD=avro \
avro-schema-registry
```

If you also want to run PostgreSQL in a container, you can link the two containers:

```bash
docker run --name avro-postgres -d \
-e POSTGRES_PASSWORD=avro \
-e POSTGRES_USER=avro \
postgres:9.6

docker run --name avro-schema-registry --link avro-postgres:postgres -p 5000:5000 -d \
-e DATABASE_URL=postgresql://avro:avro@postgres/avro \
-e FORCE_SSL=false \
-e SECRET_KEY_BASE=supersecret \
-e SCHEMA_REGISTRY_PASSWORD=avro \
avro-schema-registry
```

To setup the database the first time you run the app, you can call
`rails db:setup` from within the container:

```bash
docker exec avro-schema-registry bundle exec rails db:setup
```

## Security

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

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

9 changes: 5 additions & 4 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ default: &default
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
pool: <%= ENV.fetch('DB_POOL', 5) %>
variables:
lock_timeout: <%= ENV.fetch('DB_LOCK_TIMEOUT', 0) %>
statement_timeout: <%= ENV.fetch('DB_STATEMENT_TIMEOUT', 0) %>

development:
<<: *default
Expand Down Expand Up @@ -80,6 +83,4 @@ test:
#
production:
<<: *default
database: avro-schema-registry_production
username: avro-schema-registry
password: <%= ENV['AVRO-SCHEMA-REGISTRY_DATABASE_PASSWORD'] %>
url: <%= ENV['DATABASE_URL'] %>
4 changes: 2 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

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

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

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

0 comments on commit 49560e1

Please sign in to comment.