Skip to content

Commit

Permalink
Add initial docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
mawise committed Jul 4, 2022
1 parent f452bcd commit cf21e12
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tmp
node_modules
*.log
/log
/vendor
.git
.github
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ruby:2.7.6-slim-buster

RUN apt-get update -yqq && \
apt-get install -yqq \
autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev git libgdbm6 libreadline-dev \
nginx nodejs dirmngr gnupg apt-transport-https ca-certificates npm imagemagick \
postgresql postgresql-contrib libpq-dev && \
npm install --global yarn && \
gem install bundler -v 1.17.3 --no-document

ADD Gemfile Gemfile.lock Rakefile config.ru .ruby-version ./

# Setting MALLOC_ARENA_MAX to 2 can greatly reduce memory usage
ENV MALLOC_ARENA_MAX='2'
ENV HAVEN_DEPLOY="local"
ENV RAILS_ENV=production
ENV RAILS_SERVE_STATIC_FILES=true

RUN bundle update --bundler && \
bundle config build.bcrypt --use-system-libraries && \
bundle install --deployment --without development test

ADD . .
RUN bin/rails assets:precompile

EXPOSE 3000

CMD ["bash", "./bin/docker-start"]
9 changes: 9 additions & 0 deletions bin/docker-start
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

bin/rails db:create db:migrate
bin/rails assets:precompile

bin/rails r ./deploymentscripts/lib/ruby/create_user.rb "[email protected]" ChangeMeN0W

bin/rails s -e production -p 3000
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default: &default
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
encoding: unicode
host: <%= ENV['HAVEN_DB_HOST'] {'localhost'} %>

development:
<<: *default
Expand Down
2 changes: 1 addition & 1 deletion config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ amazon:
# access_key_id: <%= ENV['AWS_KEY'] %>
# secret_access_key: <%= ENV['AWS_SECRET'] %>
region: us-west-2
bucket: <%= ENV['AWS_BUCKET'] %>
bucket: <%= ENV['AWS_BUCKET'] %>

# Remember not to checkin your GCS keyfile to a repository
# google:
Expand Down
44 changes: 44 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3.7'
services:
haven:
build:
dockerfile: Dockerfile
depends_on:
- postgresql
ports:
- "3000:3000"
volumes:
- haven_storage:/storage
environment:
- RAILS_ENV=production
- HAVEN_DB_HOST=postgresql
- HAVEN_DB_NAME=haven
- HAVEN_DB_ROLE=haven
- HAVEN_DB_PASSWORD=supersecretrandomstring

postgresql:
image: postgres:13.2-alpine
ports:
- "5432:5432"
# https://www.postgresql.org/docs/current/static/non-durability.html
command: [
"postgres",
"-c", "max_connections=1000",
"-c", "synchronous_commit=off",
"-c", "fsync=off",
"-c", "full_page_writes=off",
"-c", "max_wal_size=4GB",
"-c", "checkpoint_timeout=30min",
"-c", "wal_level=logical"
]
environment:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_USER: haven
volumes:
- postgresqldata:/var/lib/postgresql/data

volumes:
postgresqldata:
external: false
haven_storage:
external: false

0 comments on commit cf21e12

Please sign in to comment.