Add Docker to the main repo, fixes #469

This commit is contained in:
nh-99
2017-06-02 10:54:57 -04:00
parent 157a1b0c27
commit 61284d49d9
10 changed files with 189 additions and 2 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
certs
postgres

4
.gitignore vendored
View File

@@ -27,3 +27,7 @@ public/uploads
/.ruby-version
/.ruby-gemset
/.rvmrc
# Docker stuff
.env
certs

43
Dockerfile Normal file
View File

@@ -0,0 +1,43 @@
FROM ruby:2.4
ENV HELPY_VERSION=master \
RAILS_ENV=production \
HELPY_HOME=/helpy \
HELPY_USER=helpyuser \
HELPY_SLACK_INTEGRATION_ENABLED=true
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y nodejs postgresql-client imagemagick --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --no-create-home $HELPY_USER \
&& mkdir -p $HELPY_HOME \
&& chown -R $HELPY_USER:$HELPY_USER $HELPY_HOME /usr/local/lib/ruby /usr/local/bundle
WORKDIR $HELPY_HOME
USER $HELPY_USER
RUN git clone --branch $HELPY_VERSION --depth=1 https://github.com/helpyio/helpy.git .
# add the slack integration gem to the Gemfile if the HELPY_SLACK_INTEGRATION_ENABLED is true
# use `test` for sh compatibility, also use only one `=`. also for sh compatibility
RUN test "$HELPY_SLACK_INTEGRATION_ENABLED" = "true" && sed -i '128i\gem "helpy_slack", git: "https://github.com/helpyio/helpy_slack.git", branch: "master"' $HELPY_HOME/Gemfile
RUN bundle install
RUN touch /helpy/log/production.log && chmod 0664 /helpy/log/production.log
# Due to a weird issue with one of the gems, execute this permissions change:
RUN chmod +r /usr/local/bundle/gems/griddler-mandrill-1.1.3/lib/griddler/mandrill/adapter.rb
# manually create the /helpy/public/assets folder and give the helpy user rights to it
# this ensures that helpy can write precompiled assets to it
RUN mkdir -p $HELPY_HOME/public/assets && chown $HELPY_USER $HELPY_HOME/public/assets
VOLUME $HELPY_HOME/public
COPY docker/database.yml $HELPY_HOME/config/database.yml
COPY docker/run.sh $HELPY_HOME/run.sh
CMD ["./run.sh"]

View File

@@ -128,8 +128,6 @@ gem 'rails-timeago'
gem 'devise_invitable', '~> 1.6'
gem 'breadcrumbs_on_rails'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

View File

@@ -62,6 +62,15 @@ Although not required, installing locally is highly recommended and will make it
`git clone https://github.com/helpyio/helpy.git`
**Install Helpy via Docker**
1) Install [Docker](https://get.docker.com/) and docker-compose
2) Edit the `docker/.env` file with the neccessary information and passwords
3) Edit `docker/Caddyfile` to include your URL or turn on SSL
4) Run `docker-compose up -d` to start all of the services
_Other notes_
You can modify `docker/run.sh` and set `DO_NOT_PREPARE` to true, which will skip compiling the assets when the docker container loads. While this makes the container start faster, it is not reccommended because this is also the step where database migrations are run. If there's an update and the migrations don't run it could lead to issues with the website throwing a lot of errors.
**Configure Basic Settings**
There is a settings option in the admin panel to set up things like i18n, system names, colors, the embeddable widget, etc. There is a full guide to getting set up at: [Configuring Your Helpy Settings](http://support.helpy.io/en/knowledgebase/11-Installing-Helpy/docs/22-Configuring-your-Helpy-Settings)

49
docker-compose.yml Normal file
View File

@@ -0,0 +1,49 @@
version: '2'
services:
frontend:
image: webwurst/caddy
volumes:
- ./docker/Caddyfile:/etc/caddy/Caddyfile
- ./certs:/etc/caddy/certs
volumes_from:
- helpy:ro
ports:
- "80:80"
- "443:443"
networks:
- front
restart: always
depends_on:
- helpy
helpy:
build: .
restart: always
networks:
- front
- back
volumes:
- rails-assets:/helpy/public
env_file: .env
#environment:
# - DO_NOT_PREPARE=true
depends_on:
- postgres
postgres:
image: postgres:9.4
restart: always
networks:
- back
env_file: .env
volumes:
- ./postgres:/var/lib/postgresql/data
volumes:
rails-assets:
driver: local
networks:
front:
driver: bridge
back:
driver: bridge

4
docker/.env.sample Normal file
View File

@@ -0,0 +1,4 @@
POSTGRES_DB=helpy_production
POSTGRES_USER=helpy
POSTGRES_PASSWORD=some_secure_pg_password_change_in_production
SECRET_KEY_BASE=some_secret_key_base_change_in_production

21
docker/Caddyfile Normal file
View File

@@ -0,0 +1,21 @@
0.0.0.0:80 {
tls off
root /helpy/public
header /assets {
gzip
Expires "Thu, 31 Dec 2037 23:55:55 GMT"
Cache-Control public
}
header /uploads
proxy / helpy:8080/ {
except /assets
except /uploads
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-Proto {scheme}
}
log stdout
}

23
docker/database.yml Normal file
View File

@@ -0,0 +1,23 @@
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: helpy_development
port: 5432
host: localhost
test:
<<: *default
database: helpy_test
production:
<<: *default
host: postgres
database: <%= ENV['POSTGRES_DB'] %>
username: <%= ENV['POSTGRES_USER'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>

34
docker/run.sh Normal file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
SLEEPSECONDS=5
echo "waiting $SLEEPSECONDS seconds for postgres.."
# sleep while postgres is initializing
sleep $SLEEPSECONDS
pg_isready -q -h postgres
ISREADY=$?
while [[ "$ISREADY" != 0 ]]; do
pg_isready -q -h postgres
let ISREADY=$?
echo "waiting $SLEEPSECONDS seconds for postgres.."
sleep $SLEEPSECONDS
done
echo "postgres is now avaliable"
RUN_PREPARE=${DO_NOT_PREPARE:-false}
if [[ "$RUN_PREPARE" = "false" ]]
then
echo "DO_NOT_PREPARE is not set or is false, preparing.."
bundle exec rake assets:precompile
bundle exec rake db:migrate
bundle exec rake db:seed || echo "db is already seeded"
fi
echo "starting unicorn"
exec bundle exec unicorn -E production -c config/unicorn.rb