Merge pull request #105 from houdiniproject/docker-improvement-latest
Updated Docker implementation, including for CI
This commit is contained in:
commit
5f2c3b4324
28 changed files with 280 additions and 58 deletions
|
@ -3,4 +3,7 @@
|
|||
!Gemfile.lock
|
||||
!package.json
|
||||
!package-lock.json
|
||||
!script/debian_setup.sh
|
||||
!script/build/debian/*.sh
|
||||
!Rakefile
|
||||
!config/*
|
||||
!db/*
|
32
.env.test
Normal file
32
.env.test
Normal file
|
@ -0,0 +1,32 @@
|
|||
export DEVISE_SECRET_KEY='0696452e54b14758b8534437d8cf418ea920ff23bb9c3a061a9ab2827bab4685710e89b899ebd4457df600cb5f2e04adb6a0fdef09a6a45558ecae1d6906f4a6' #bundle exec rake secret
|
||||
export SECRET_TOKEN='0696452e54b14758b8534437d8cf418ea920ff23bb9c3a061a9ab2827bab4685710e89b899ebd4457df600cb5f2e04adb6a0fdef09a6a45558ecae1d6906f4a6' #bundle exec rake secret
|
||||
|
||||
export STRIPE_API_KEY='REPLACE' # use your test private key from your stripe account
|
||||
export STRIPE_API_PUBLIC='REPLACE' # use your test public key from your stripe account
|
||||
export S3_BUCKET_NAME='REPLACE'
|
||||
export AWS_ACCESS_KEY='REPLACE'
|
||||
export AWS_SECRET_ACCESS_KEY='REPLACE'
|
||||
|
||||
### optional below
|
||||
export ORG_NAME="default_organization"
|
||||
|
||||
export GOOGLE_API_KEY='REPLACE'
|
||||
export TWITTER_API_SECRET='REPLACE'
|
||||
export FACEBOOK_API_SECRET='REPLACE'
|
||||
|
||||
export MAILCHIMP_API_KEY='REPLACE'
|
||||
export FULL_CONTACT_KEY='REPLACE'
|
||||
|
||||
export LOG_TO_FILES=true
|
||||
|
||||
export MAILCHIMP_OAUTH_CLIENT_ID='REPLACE'
|
||||
export MAILCHIMP_OAUTH_CLIENT_SECRET='REPLACE'
|
||||
export MAILCHIMP_REDIRECT_URL='REPLACE'
|
||||
export FACEBOOK_APP_ID="REPLACE"
|
||||
|
||||
|
||||
export CYPHER_KEY="REPLACE" # used for mailchimp integration
|
||||
|
||||
|
||||
|
||||
export CIVIC_CRM_RABBITMQ_PASSWORD=""
|
|
@ -1 +1 @@
|
|||
2.3.6
|
||||
2.3.7
|
||||
|
|
13
.travis.yml
Normal file
13
.travis.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
sudo: required
|
||||
|
||||
language: minimal
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
- docker-compose -f docker/build/docker-compose.yml build
|
||||
- cp .env.test .env
|
||||
|
||||
script:
|
||||
- docker-compose -f docker/build/docker-compose.yml run -e RACK_ENV=ci -e RAILS_ENV=ci -e BUILD_DATABASE_URL=postgres://admin:password@db/commitchange_development build script/test.sh
|
22
Dockerfile
22
Dockerfile
|
@ -1,22 +0,0 @@
|
|||
FROM ruby:2.3
|
||||
ARG USER
|
||||
RUN mkdir /myapp
|
||||
COPY Gemfile /myapp/Gemfile
|
||||
COPY Gemfile.lock /myapp/Gemfile.lock
|
||||
COPY package.json /myapp/package.json
|
||||
COPY package-lock.json /myapp/package-lock.json
|
||||
COPY script/debian_setup.sh /myapp/script/debian_setup.sh
|
||||
WORKDIR /myapp
|
||||
RUN script/debian_setup.sh
|
||||
RUN groupadd -r -g 1000 $USER
|
||||
RUN useradd -r -m -g $USER -u 1000 $USER
|
||||
RUN chown -R $USER /usr/local/bundle
|
||||
RUN chgrp -R $USER /usr/local/bundle
|
||||
RUN chown -R $USER /myapp
|
||||
RUN chgrp -R $USER /myapp
|
||||
RUN chown -R $USER /usr/lib/node_modules
|
||||
RUN chgrp -R $USER /usr/lib/node_modules
|
||||
USER $USER
|
||||
RUN bundle install
|
||||
EXPOSE 5000
|
||||
CMD foreman start
|
6
Gemfile
6
Gemfile
|
@ -1,6 +1,6 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
ruby '~> 2.3.6'
|
||||
ruby '2.3.7'
|
||||
gem 'rake'
|
||||
gem 'rails', '3.2.22.5'
|
||||
gem 'rails_12factor'
|
||||
|
@ -109,13 +109,13 @@ gem 'i18n-js'
|
|||
gem 'countries'
|
||||
|
||||
|
||||
group :development do
|
||||
group :development, :ci do
|
||||
gem 'traceroute'
|
||||
gem 'debase'
|
||||
gem 'ruby-debug-ide'
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
group :development, :ci, :test do
|
||||
gem 'timecop'
|
||||
gem 'pry'
|
||||
#gem 'pry-byebug'
|
||||
|
|
|
@ -526,7 +526,7 @@ DEPENDENCIES
|
|||
webmock
|
||||
|
||||
RUBY VERSION
|
||||
ruby 2.3.6p384
|
||||
ruby 2.3.7p456
|
||||
|
||||
BUNDLED WITH
|
||||
1.16.1
|
||||
1.16.4
|
||||
|
|
|
@ -56,6 +56,7 @@ You will likely need to logout and log back in again.
|
|||
#### Build your docker-container and start it up for initial set up.
|
||||
We'll keep this running in the console we'll call **console 1**
|
||||
```
|
||||
cd docker/debug
|
||||
docker-compose build
|
||||
docker-compose up
|
||||
```
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'rails/all'
|
|||
|
||||
Bundler.require *Rails.groups(:assets) if defined?(Bundler)
|
||||
|
||||
require File.expand_path('lib/htp') # Hamster Table Print
|
||||
#require File.expand_path('lib/htp') # Hamster Table Print
|
||||
|
||||
module Commitchange
|
||||
class Application < Rails::Application
|
||||
|
|
|
@ -30,6 +30,16 @@ test:
|
|||
username: admin
|
||||
password: password
|
||||
host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
|
||||
ci:
|
||||
adapter: postgresql
|
||||
encoding: unicode
|
||||
database: commitchange_development
|
||||
pool: 5
|
||||
username: admin
|
||||
password: password
|
||||
host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
|
||||
|
||||
|
||||
|
||||
# Connect on a TCP socket. Omitted by default since the client uses a
|
||||
# domain socket that doesn't need configuration. Windows does not have
|
||||
|
|
|
@ -5,16 +5,20 @@ require File.expand_path('../application', __FILE__)
|
|||
Encoding.default_external = Encoding::UTF_8
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
@ignore_dotenv = ENV['IGNORE_DOTENV']
|
||||
@env = Rails.env || 'development'
|
||||
unless (@ignore_dotenv)
|
||||
require 'dotenv'
|
||||
Dotenv.load ".env"
|
||||
if @env == 'test'
|
||||
if File.file?(".env.#{@env}")
|
||||
Dotenv.load ".env.#{@env}"
|
||||
end
|
||||
else
|
||||
Dotenv.load ".env"
|
||||
end
|
||||
end
|
||||
@env = Rails.env || 'development'
|
||||
|
||||
@org_name = ENV['ORG_NAME'] || 'default_organization'
|
||||
puts "config files .env .env.#{@env} ./config/settings.#{@env}.yml#{ @env != 'test' ? " ./config/#{@org_name}.yml": " "} #{ @env != 'test' ? " ./config/#{@org_name}.#{@env}.yml": " "} #{ @env == 'test' ? "./config/settings.test.yml" : ""}"
|
||||
unless @ignore_dotenv
|
||||
Dotenv.load ".env.#{@env}" if File.file?(".env.#{@env}")
|
||||
end
|
||||
if Rails.env == 'test'
|
||||
Settings.add_source!("./config/settings.test.yml")
|
||||
else
|
||||
|
|
60
config/environments/ci.rb
Executable file
60
config/environments/ci.rb
Executable file
|
@ -0,0 +1,60 @@
|
|||
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
||||
Commitchange::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb
|
||||
|
||||
# In the development environment your application's code is reloaded on
|
||||
# every request. This slows down response time but is perfect for development
|
||||
# since you don't have to restart the web server when you make code changes.
|
||||
config.cache_classes = false
|
||||
config.cache_store = Settings.default.cache_store.to_sym
|
||||
|
||||
# Log error messages when you accidentally call methods on nil.
|
||||
config.whiny_nils = true
|
||||
|
||||
# Show full error reports and disable caching
|
||||
config.consider_all_requests_local = true
|
||||
config.action_controller.perform_caching = false
|
||||
|
||||
# You can uncomment the following to test our real AWS email server on localhost:
|
||||
# config.action_mailer.delivery_method = :aws_ses
|
||||
# config.action_mailer.default_url_options = { host: 'commitchange.com' }
|
||||
config.action_mailer.delivery_method = Settings.mailer.delivery_method.to_sym
|
||||
config.action_mailer.smtp_settings = { address: Settings.mailer.address, port: Settings.mailer.port }
|
||||
config.action_mailer.smtp_settings['user_name']= Settings.mailer.username if Settings.mailer.username
|
||||
config.action_mailer.smtp_settings['password']= Settings.mailer.password if Settings.mailer.password
|
||||
|
||||
config.action_mailer.default_url_options = { host: Settings.mailer.host }
|
||||
|
||||
# Print deprecation notices to the Rails logger
|
||||
config.active_support.deprecation = :log
|
||||
|
||||
# Only use best-standards-support built into browsers
|
||||
config.action_dispatch.best_standards_support = :builtin
|
||||
|
||||
# Raise exception on mass assignment protection for Active Record models
|
||||
config.active_record.mass_assignment_sanitizer = :strict
|
||||
|
||||
# Log the query plan for queries taking more than this (works)
|
||||
# with SQLite, MySQL, and PostgreSQL)
|
||||
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
||||
|
||||
# Do not compress assets
|
||||
config.assets.compress = false
|
||||
|
||||
# Expands the lines which load the assets
|
||||
config.assets.debug = true
|
||||
|
||||
config.log_level = :debug
|
||||
|
||||
config.threadsafe!
|
||||
config.dependency_loading = true if $rails_rake_task
|
||||
# Turn this on if you want to mess with code inside /node_modules
|
||||
# config.browserify_rails.evaluate_node_modules = true
|
||||
|
||||
config.middleware.use I18n::JS::Middleware
|
||||
|
||||
config.after_initialize do
|
||||
ActiveRecord::Base.logger = nil
|
||||
end
|
||||
|
||||
end
|
|
@ -57,4 +57,5 @@ Commitchange::Application.configure do
|
|||
# config.browserify_rails.evaluate_node_modules = true
|
||||
|
||||
config.middleware.use I18n::JS::Middleware
|
||||
|
||||
end
|
||||
|
|
|
@ -38,11 +38,18 @@ Commitchange::Application.configure do
|
|||
# Expands the lines which load the assets
|
||||
config.assets.debug = true
|
||||
|
||||
config.log_level = :debug
|
||||
config.log_level = :none
|
||||
|
||||
config.action_controller.allow_forgery_protection = false
|
||||
|
||||
config.cache_store = :memory_store
|
||||
config.threadsafe!
|
||||
config.after_initialize do
|
||||
ActiveRecord::Base.logger = nil
|
||||
ActionController::Base.logger = nil
|
||||
ActionMailer::Base.logger = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
||||
Commitchange::Application.configure do
|
||||
if (Rails.env != 'test')
|
||||
|
||||
|
||||
config.lograge.enabled = true
|
||||
# add time to lograge
|
||||
config.lograge.custom_options = lambda do |event|
|
||||
|
@ -8,4 +11,5 @@ Commitchange::Application.configure do
|
|||
exception_object: event.payload[:exception_object] # the exception instance
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
17
docker/build/Dockerfile
Normal file
17
docker/build/Dockerfile
Normal file
|
@ -0,0 +1,17 @@
|
|||
FROM ruby:2.3.7-stretch
|
||||
ARG USER
|
||||
RUN mkdir /myapp
|
||||
COPY script/build/debian/prebuild.sh myapp/script/build/debian/prebuild.sh
|
||||
RUN myapp/script/build/debian/prebuild.sh
|
||||
COPY script/build/debian/node.sh myapp/script/build/debian/node.sh
|
||||
RUN myapp/script/build/debian/node.sh
|
||||
COPY script/build/debian/postgres.sh myapp/script/build/debian/postgres.sh
|
||||
RUN myapp/script/build/debian/postgres.sh
|
||||
COPY script/build/debian/java.sh myapp/script/build/debian/java.sh
|
||||
RUN myapp/script/build/debian/java.sh
|
||||
WORKDIR /myapp
|
||||
COPY Gemfile /myapp/Gemfile
|
||||
COPY Gemfile.lock /myapp/Gemfile.lock
|
||||
RUN bundle install
|
||||
CMD rake -T
|
||||
|
23
docker/build/docker-compose.yml
Normal file
23
docker/build/docker-compose.yml
Normal file
|
@ -0,0 +1,23 @@
|
|||
# License: CC0-1.0
|
||||
version: '2'
|
||||
services:
|
||||
build:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: docker/build/Dockerfile
|
||||
depends_on:
|
||||
- db
|
||||
- memcached
|
||||
environment:
|
||||
- DATABASE_HOST=db
|
||||
- MEMCACHE_SERVERS=memcached
|
||||
volumes:
|
||||
- ../../:/myapp
|
||||
db:
|
||||
image: postgres:9.6
|
||||
environment:
|
||||
POSTGRES_USER: "admin"
|
||||
POSTGRES_PASSWORD: "password"
|
||||
memcached:
|
||||
image: memcached
|
||||
|
28
docker/debug/Dockerfile
Normal file
28
docker/debug/Dockerfile
Normal file
|
@ -0,0 +1,28 @@
|
|||
FROM ruby:2.3.7-stretch
|
||||
ARG USER
|
||||
RUN mkdir /myapp
|
||||
COPY script/build/debian/prebuild.sh myapp/script/build/debian/prebuild.sh
|
||||
RUN myapp/script/build/debian/prebuild.sh
|
||||
COPY script/build/debian/node.sh myapp/script/build/debian/node.sh
|
||||
RUN myapp/script/build/debian/node.sh
|
||||
COPY script/build/debian/postgres.sh myapp/script/build/debian/postgres.sh
|
||||
RUN myapp/script/build/debian/postgres.sh
|
||||
COPY script/build/debian/java.sh myapp/script/build/debian/java.sh
|
||||
RUN myapp/script/build/debian/java.sh
|
||||
WORKDIR /myapp
|
||||
RUN groupadd -r -g 1000 $USER
|
||||
RUN useradd -r -m -g $USER -u 1000 $USER
|
||||
RUN chown -R $USER /usr/local/bundle
|
||||
RUN chgrp -R $USER /usr/local/bundle
|
||||
RUN chown -R $USER /myapp
|
||||
RUN chgrp -R $USER /myapp
|
||||
RUN chown -R $USER /usr/lib/node_modules
|
||||
RUN chgrp -R $USER /usr/lib/node_modules
|
||||
COPY Gemfile /myapp/Gemfile
|
||||
COPY Gemfile.lock /myapp/Gemfile.lock
|
||||
RUN bundle install
|
||||
RUN chown -R $USER /myapp/Gemfile
|
||||
RUN chgrp -R $USER /myapp/Gemfile.lock
|
||||
USER $USER
|
||||
EXPOSE 5000
|
||||
CMD foreman start
|
|
@ -1,29 +1,37 @@
|
|||
# License: CC0-1.0
|
||||
version: '2'
|
||||
services:
|
||||
web:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: docker/debug/Dockerfile
|
||||
args:
|
||||
- USER
|
||||
user: ${USER}
|
||||
|
||||
environment:
|
||||
- DATABASE_HOST=db
|
||||
- MEMCACHE_SERVERS=memcached
|
||||
- USER=${USER}
|
||||
|
||||
volumes:
|
||||
- ../../:/myapp
|
||||
|
||||
ports:
|
||||
- "5000:5000"
|
||||
depends_on:
|
||||
- db
|
||||
- memcached
|
||||
db:
|
||||
image: postgres:9.6
|
||||
environment:
|
||||
POSTGRES_USER: "admin"
|
||||
POSTGRES_PASSWORD: "password"
|
||||
volumes:
|
||||
- ./postgres-data:/var/lib/postgresql/data
|
||||
web:
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
- USER
|
||||
volumes:
|
||||
- .:/myapp
|
||||
ports:
|
||||
- "5000:5000"
|
||||
depends_on:
|
||||
- db
|
||||
- memcached
|
||||
user: ${USER}
|
||||
environment:
|
||||
- USER=${USER}
|
||||
- DATABASE_HOST=db
|
||||
- MEMCACHE_SERVERS=memcached
|
||||
memcached:
|
||||
image: memcached
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
"watch": "export HOUDINI_WATCH=1; script/build.sh",
|
||||
"build": "script/build.sh",
|
||||
"build-all": "npm ci && script/compile-assets.sh && npm run build",
|
||||
"test": "rake spec && npm run build && npx jest",
|
||||
"test": "rake -v spec && npm run build && npx jest",
|
||||
"export-button-config": "bundle exec rake settings:generate_json",
|
||||
"export-i18n": "bundle exec rake settings:combine_translations",
|
||||
"generate-openapi": "rake oapi:gen",
|
||||
|
|
2
run
2
run
|
@ -1,2 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
docker-compose run web $@
|
||||
docker-compose -f docker/debug/docker-compose.yml run web $@
|
||||
|
|
4
script/build/debian/java.sh
Executable file
4
script/build/debian/java.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
apt-get -yy install default-jre
|
6
script/build/debian/node.sh
Executable file
6
script/build/debian/node.sh
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
curl -sL https://deb.nodesource.com/setup_9.x | bash -
|
||||
apt-get update -qq && apt-get install -y nodejs
|
||||
npm install npm@^6 -g
|
4
script/build/debian/postgres.sh
Executable file
4
script/build/debian/postgres.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
apt-get -yy install libpq5=9.6.10-0+deb9u1 libpq-dev=9.6.10-0+deb9u1 postgresql=9.6+181+deb9u1
|
4
script/build/debian/prebuild.sh
Executable file
4
script/build/debian/prebuild.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
apt-get update -qq && apt-get install -y build-essential
|
|
@ -2,7 +2,7 @@
|
|||
set -e
|
||||
|
||||
curl -sL https://deb.nodesource.com/setup_9.x | bash -
|
||||
echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' > /etc/apt/sources.list.d/pgdg.list
|
||||
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
|
||||
apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs postgresql-9.6 default-jre
|
||||
npm install npm@^6 -g
|
2
script/test.sh
Executable file
2
script/test.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
npm ci && rake db:create db:structure:load db:migrate && RAILS_ENV=test rake db:create db:structure:load test:prepare && rake spec && npm run build-all && npx jest
|
|
@ -117,3 +117,16 @@ RSpec.configure do |config|
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9"
|
||||
module Kernel
|
||||
alias :__at_exit :at_exit
|
||||
def at_exit(&block)
|
||||
__at_exit do
|
||||
exit_status = $!.status if $!.is_a?(SystemExit)
|
||||
block.call
|
||||
exit exit_status if exit_status
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue