Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ gem 'capistrano'
gem 'capistrano-ext'
gem 'pg'
gem 'haml'
gem 'insales_api', github: "insales/insales_api", branch: "master"
gem 'sqlite3'
gem 'insales_api', git: "https://github.com/insales/insales_api.git", branch: "master"
gem 'actionpack-xml_parser'


21 changes: 11 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: git://github.com/insales/insales_api.git
revision: 3418b313349c576e90c5f787177bad8e2bdcdc8d
remote: https://github.com/insales/insales_api.git
revision: 69f98a8f74f5399a8c1f7d41c97b7cb42b351cd5
branch: master
specs:
insales_api (0.1.0)
insales_api (0.1.3)
activeresource (>= 3.0.0)
activesupport (>= 3.0.0)

Expand Down Expand Up @@ -41,10 +41,10 @@ GEM
activemodel (= 4.2.1)
activesupport (= 4.2.1)
arel (~> 6.0)
activeresource (4.0.0)
activeresource (4.1.0)
activemodel (~> 4.0)
activesupport (~> 4.0)
rails-observers (~> 0.1.1)
rails-observers (~> 0.1.2)
activesupport (4.2.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
Expand All @@ -71,7 +71,7 @@ GEM
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.2)
json (1.8.6)
loofah (2.0.2)
nokogiri (>= 1.5.9)
mail (2.6.3)
Expand Down Expand Up @@ -107,8 +107,8 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
rails-observers (0.1.2)
activemodel (~> 4.0)
rails-observers (0.1.5)
activemodel (>= 4.0)
railties (4.2.1)
actionpack (= 4.2.1)
activesupport (= 4.2.1)
Expand Down Expand Up @@ -142,7 +142,6 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10)
sshkit (1.7.1)
colorize (>= 0.7.0)
net-scp (>= 1.1.2)
Expand All @@ -168,4 +167,6 @@ DEPENDENCIES
rails (= 4.2.1)
rspec
rspec-rails
sqlite3

BUNDLED WITH
1.15.4
22 changes: 14 additions & 8 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
* Удаление
* Прозрачный логин из InSales

Настройка сервера
Разработка
----------------------

* git clone git@github.com:insales/insales_app.git
* cd insales_app
* bundle install
* cp config/database.yml.example config/database.yml
* bundle exec rake db:migrate
* cp config/initializers/insales_api.rb.example config/initializers/insales_api.rb
* bundle exec rails s
Для быстрой развёртки приложения нужно установить [docker](https://www.docker.com/community-edition) и [docker-compose](https://docs.docker.com/compose/install/).

* `git clone git@github.com:insales/insales_app.git`
* `cd insales_app`
* `docker-compose up --build`

После этого приложение будет доступно по адресу http://localhost:3000, проверить его статус и увидеть логи запуска можно по адресу http://localhost:9001.

### Самостоятельный запуск приложения
* Остановить rails-приложение на http://localhost:9001
* `cd insales_app`
* `docker-compose exec app sudo -u rails -i`
* `cd webapp`
* `bundle exec rails server -b 0.0.0.0`

Добавление приложения на стороне InSales
-----------------------------------------
Expand Down
20 changes: 9 additions & 11 deletions config/database.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
development: &default
adapter: postgresql
host: postgres
username: postgres
database: app_dev
pool: 5
timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
<<: *default
database: app_test

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
<<: *default
database: app
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

version: '2'
services:
app:
build: docker
volumes:
- .:/home/rails/webapp:cached
- bundle_data:/bundle
depends_on:
- postgres
ports:
- 3000:3000
- 9001:9001
# for pry
tty: true
stdin_open: true

postgres:
image: postgres:9.6
volumes:
- postgres_data:/var/lib/postgresql
logging:
driver: none

volumes:
bundle_data:
driver: local
postgres_data:
driver: local
34 changes: 34 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ruby:2.3
MAINTAINER admin@insales.ru

RUN \
groupadd rails && \
useradd rails -m -g rails -s /bin/bash && \
usermod -a -G sudo,adm rails

RUN \
apt-get update -qq \
&& apt-get install -y \
supervisor \
sudo \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN \
echo 'rails ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/rails_without_password && \
chmod 600 /etc/sudoers.d/rails_without_password

# Do not copy gem package documentation
RUN echo "gem: --no-ri --no-rdoc" > /home/rails/.gemrc

RUN gem install bundler \
&& gem cleanup

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY run-webapp.sh /home/rails/run-webapp.sh
COPY profile /home/rails/.profile

RUN \
chown rails:rails /home/rails/.gemrc \
/home/rails/run-webapp.sh

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
17 changes: 17 additions & 0 deletions docker/profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

GEM_HOME=/bundle
BUNDLE_PATH=/bundle
BUNDLE_APP_CONFIG=/bundle
PATH="$BUNDLE_APP_CONFIG/bin:$PATH"

RAILS_ENV=development
16 changes: 16 additions & 0 deletions docker/run-webapp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
source ~/.profile
set -e

sudo chown rails:rails $GEM_HOME $HOME/webapp

cd /home/rails/webapp

if [ ! -f config/database.yml ]; then
cp config/database.yml.example config/database.yml
fi

bundle check || bundle install --jobs=$(nproc)
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rails s --binding=0.0.0.0
20 changes: 20 additions & 0 deletions docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[supervisord]
user=root
nodaemon=true

[inet_http_server]
port=0.0.0.0:9001

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[program:rails]
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=/usr/bin/sudo -u rails "/home/rails/run-webapp.sh"