Skip to content

Commit f322189

Browse files
author
Vidas P
committed
Containerise deployment
Use only container stack for Heroku deployment. Use heroku.yml manifest for image building. Create image to run all processes in one dyno. Remove sqlite as development option (CircleCI and other things use postgres now). Alter some environment options to match defaults.
1 parent bb9085f commit f322189

File tree

25 files changed

+126
-231
lines changed

25 files changed

+126
-231
lines changed

.circleci/config.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ jobs:
77
build:
88
docker:
99
# specify the version you desire here
10-
- image: circleci/ruby:2.6.3-node-browsers
10+
- image: circleci/ruby:2.6.6-node-browsers
11+
environment:
12+
RAILS_ENV: test
13+
RACK_ENV: test
1114

1215
# Specify service dependencies here if necessary
1316
# CircleCI maintains a library of pre-built images
1417
# documented at https://circleci.com/docs/2.0/circleci-images/
15-
# - image: circleci/postgres:9.4
18+
- image: circleci/postgres:9.6-alpine
19+
environment:
20+
POSTGRES_USER: aw
21+
POSTGRES_DB: aw_test
1622

1723
working_directory: ~/repo
1824

25+
environment:
26+
DATABASE_URL: "postgres://aw@localhost:5432/aw_test"
27+
1928
steps:
2029
- checkout
2130

@@ -37,8 +46,11 @@ jobs:
3746
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
3847

3948
# Database setup
40-
- run: bundle exec rake db:create
41-
- run: bundle exec rake db:schema:load
49+
- run:
50+
name: create database
51+
command: |
52+
bundle exec rake db:schema:load
53+
bundle exec rake db:migrate
4254
4355
# run tests!
4456
- run:

.env

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,26 @@ SECRET_KEY_BASE=REPLACE_ME_NOW!
1010

1111
# Concurrency options
1212

13-
WEB_CONCURRENCY=2
13+
WEB_CONCURRENCY=1
1414
RAILS_MAX_THREADS=5
1515
RACK_TIMEOUT_SERVICE_TIMEOUT=20
1616

1717

1818
# Database setup
1919

20-
#DATABASE_ADAPTER=sqlite3
2120
#DATABASE_ENCODING=utf8
2221
#DATABASE_RECONNECT=true
23-
#DATABASE_NAME=db/development.sqlite3
22+
#DATABASE_NAME=active_workflow
2423
#DATABASE_POOL=20
2524
#DATABASE_USERNAME=
2625
#DATABASE_PASSWORD=""
2726
#DATABASE_HOST=
2827
#DATABASE_PORT=
2928
#TEST_DATABASE_NAME=
3029

31-
#DO_NOT_CREATE_DATABASE
30+
#CREATE_DATABASE=1
3231
#DO_NOT_MIGRATE=
33-
SEED_DATABASE=1
32+
#DO_NOT_SEED=1
3433
SEED_EMAIL=admin@example.com
3534
SEED_USERNAME=admin
3635
SEED_PASSWORD=password

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Changed
2020
- Remove SchedulerAgent (to be implemented as a core functionality).
2121
- Refactor agent runner and scheduler.
22+
- `SEED_DATABASE` and `DO_NOT_CREATE_DATABASE` environment flags where inverted and replaced with
23+
`DO_NOT_SEED` and `CREATE_DATABASE` correspondingly to represent default execution path.
24+
- You can now use Heroku single button deployment for both demonstration
25+
purposes running on free tier and production with scalable dyno formations.
26+
This is controlled with a single environment variable `SINGLE_DYNO`.
2227

2328

2429
## [0.9.8] - 2020-05-11

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ COPY ./ /app/
99

1010
# Get rid of annoying "fatal: Not a git repository (or any of the parent directories): .git" messages
1111
RUN umask 002 && git init && \
12-
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret DATABASE_ADAPTER=postgresql bundle install --without "test development" --path vendor/bundle -j 4 --no-local --no-cache --force && \
13-
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret DATABASE_ADAPTER=postgresql bundle exec rake assets:clean assets:precompile && \
12+
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret bundle install --without "test development" --path vendor/bundle -j 4 --no-local --no-cache --force && \
13+
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret bundle exec rake assets:clean assets:precompile && \
1414
chmod g=u /app/Gemfile.lock /app/config/ /app/tmp/
1515

1616

1717
EXPOSE 3000
1818

19-
COPY ["docker/scripts/setup_env", "docker/scripts/init", "/scripts/"]
19+
COPY docker/scripts/init /scripts/
2020
CMD ["/scripts/init"]
2121

2222
USER 1001

Gemfile

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ gem 'dotenv', '~> 2.5.0'
3838
gem 'faraday', '~> 0.9'
3939
gem 'faraday_middleware', '~> 0.12.2'
4040
gem 'feedjira', '~> 2.2'
41+
# TODO: use font-awesome-rails?
4142
gem 'font-awesome-sass', '~> 5.12.0'
4243
gem 'httparty', '~> 0.16'
4344
gem 'jquery-rails', '~> 4.3.5'
@@ -57,7 +58,6 @@ gem 'rails-html-sanitizer', '~> 1.3.0'
5758
gem 'coffee-rails', '~> 4.2.2'
5859
# TODO: update
5960
gem 'rufus-scheduler', '~> 3.4.2', require: false
60-
gem 'sass-rails', '~> 5.0'
6161
gem 'sassc', '~>2.3.0'
6262
# TODO: update
6363
gem 'select2-rails', '~> 3.5.4'
@@ -71,9 +71,9 @@ gem 'jquery-datatables', '~> 1.10.19'
7171
gem 'grape', '~> 1.3.2'
7272
gem 'grape-entity', '~> 0.8.0'
7373
gem 'jwt', '~> 2.2.1'
74+
gem 'foreman', '~> 0.87.1'
7475

7576
group :development do
76-
gem 'foreman', '~> 0.87.1'
7777
gem 'bullet', '~> 6.1.0'
7878
gem 'sqlite3', '~> 1.4.2'
7979
gem 'better_errors', '~> 2.7.0'
@@ -114,11 +114,4 @@ end
114114

115115
gem 'puma', '~> 4.3.5'
116116

117-
ENV['DATABASE_ADAPTER'] ||=
118-
if ENV['RAILS_ENV'] == 'production'
119-
'postgresql'
120-
else
121-
'sqlite3'
122-
end
123-
124117
gem 'pg', '~> 1.2.3'

Gemfile.lock

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ GEM
197197
faraday_middleware (>= 0.9)
198198
loofah (>= 2.0)
199199
sax-machine (>= 1.0)
200-
ffi (1.12.2)
200+
ffi (1.13.1)
201201
font-awesome-sass (5.12.0)
202202
sassc (>= 1.11)
203203
foreman (0.87.1)
@@ -508,12 +508,6 @@ GEM
508508
sass-listen (4.0.0)
509509
rb-fsevent (~> 0.9, >= 0.9.4)
510510
rb-inotify (~> 0.9, >= 0.9.7)
511-
sass-rails (5.1.0)
512-
railties (>= 5.2.0)
513-
sass (~> 3.1)
514-
sprockets (>= 2.8, < 4.0)
515-
sprockets-rails (>= 2.0, < 4.0)
516-
tilt (>= 1.1, < 3)
517511
sassc (2.3.0)
518512
ffi (~> 1.9)
519513
sassc-rails (2.1.2)
@@ -666,7 +660,6 @@ DEPENDENCIES
666660
rturk (~> 2.12.1)
667661
rubocop (~> 0.82.0)
668662
rufus-scheduler (~> 3.4.2)
669-
sass-rails (~> 5.0)
670663
sassc (~> 2.3.0)
671664
select2-rails (~> 3.5.4)
672665
selenium-webdriver (~> 3.142.7)

Makefile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ build-image:
99
HEROKU_APP = $(shell heroku apps:info | grep 'Web URL' | awk -F'[/.]' '{print $$3}')
1010
HEROKU_CONTAINER = registry.heroku.com/${HEROKU_APP}/web
1111

12-
.PHONY: heroku-docker-push
13-
heroku-docker-push:
14-
docker tag local/active_workflow ${HEROKU_CONTAINER}
15-
docker push ${HEROKU_CONTAINER}
16-
17-
.PHONY: heroku-docker-release
18-
heroku-docker-release:
19-
heroku container:release web
20-
2112
.PHONY: test
2213
test:
2314
bundle exec rspec spec

Procfile

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
# Use configuration bellow to run jobs on a separate dyno.
21
web: bundle exec puma
3-
scheduler: bundle exec rails runner bin/pro_scheduler.rb
4-
worker: bundle exec script/delayed_job -n 4 run
5-
6-
###############################
7-
# Multiple DelayedJob workers #
8-
###############################
9-
# Per default ActiveWorkflow can just run one agent at a time. Using a lot of agents or calling slow
10-
# external services frequently might require more DelayedJob workers (an indicator for this is
11-
# a backlog in your 'Job Management' page).
12-
# Every uncommented line starts an additional DelayedJob worker. This works for development, production
13-
# and for the threaded and separate worker processes. Keep in mind one worker needs about 300MB of RAM.
14-
#
15-
#dj2: bundle exec script/delayed_job -i 2 run
16-
#dj3: bundle exec script/delayed_job -i 3 run
17-
#dj4: bundle exec script/delayed_job -i 4 run
18-
#dj5: bundle exec script/delayed_job -i 5 run
19-
#dj6: bundle exec script/delayed_job -i 6 run
20-
#dj7: bundle exec script/delayed_job -i 7 run
21-
#dj8: bundle exec script/delayed_job -i 8 run
22-
#dj9: bundle exec script/delayed_job -i 9 run
23-
#dj10: bundle exec script/delayed_job -i 10 run
2+
scheduler: bundle exec rails runner bin/scheduler.rb
3+
worker: bundle exec script/delayed_job -n 2 run

README.md

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,13 @@ button bellow and fill in the environment variables for your seed user (admin):
327327
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/automaticmode/active_workflow)
328328

329329
A free Heroku plan could be used to try out ActiveWorkflow, but it wouldn't be
330-
enough for real use. That's because the limited run time and automatic turning
331-
off of unused workers inhibits ActiveWorkflow from running scheduled tasks.
330+
enough for real use. This is controlled by setting `SINGLE_DYNO` environment
331+
variable to '1'. In such a case all the processes (web, scheduler, workers) are
332+
run in a single dyno. This is only recommended for demonstration purposes,
333+
though. For production use you should unset `SINGLE_DYNO` (or set to an empty
334+
value) and run web, scheduler and worker dynos separately. Note: you should
335+
never create more than one scheduler dyno.
332336

333-
### Manual Heroku Deployment
334-
335-
If you would like more control or intend to deploy ActiveWorkflow from a modified
336-
source tree, you could do that using Heroku's command line interface.
337-
338-
Please install Heroku's command line interface tool from
339-
[Heroku Toolbelt](https://toolbelt.heroku.com).
340-
341-
For additional configuration options please take a look at the `.env` file.
342-
Don't forget to set any configuration options you may require using the
343-
`heroku config` command line tool.
344-
345-
FIXME:
346-
The default ActiveWorkflow configuration uses the same single dyno to run both
347-
the web server and workers.
348337

349338
### Deployment with Docker
350339

@@ -377,34 +366,6 @@ make build-image
377366
This creates an image named `local/active_workflow`.
378367

379368

380-
#### Deployment with Docker to Heroku
381-
382-
You may prefer to use Heroku in a container mode (instead of deploying via
383-
GitHub). Please be sure to login to Heroku docker registry before doing that:
384-
385-
```sh
386-
heroku container:login
387-
```
388-
389-
Docker deployment to Heroku happens in two steps. Push:
390-
391-
```sh
392-
make heroku-docker-push
393-
```
394-
395-
And release:
396-
397-
```sh
398-
make heroku-docker-release
399-
```
400-
401-
If you no longer wish to use image based deployment to Heroku you will need to
402-
reset Heroku stack to `heroku-18` like this:
403-
404-
```sh
405-
heroku stack:set heroku-18
406-
```
407-
408369
## Development
409370

410371
### Requirements
@@ -427,11 +388,23 @@ brew install graphviz
427388

428389
### Running Locally without Docker
429390

430-
If you want to test out ActiveWorkflow locally you can start a demo instance
431-
using a local sqlite database. First prepare the database with:
391+
ActiveWorkflow uses Postgres database to store all the data. If you have
392+
Postgres database set up all you need is set environment variable DATABASE_URL
393+
for the ActiveWorkflow to use like this:
394+
395+
```sh
396+
export DATABASE_URL=postgres://mydbusername:password@localhost:5432/dbname
397+
```
398+
399+
> You can also reuse postgres docker image preconfigured for use with
400+
> ActiveWorkflow when running it with docker-compose. You can start it with
401+
> `docker-compose up postgres` and stop with `Ctrl+C` and `docker-compose down`
402+
> afterwards.
403+
404+
Before running ActiveWorkflow you have to prepare the database with:
432405

433406
```sh
434-
bundle exec rake db:create
407+
#bundle exec rake db:create # Optionally create database if you haven't created it in advance
435408
bundle exec rake db:migrate
436409
bundle exec rake db:seed
437410
```

app.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@
33
"description": "Business process automation platform.",
44
"website": "https://github.com/automaticmode/active_workflow",
55
"repository": "https://github.com/automaticmode/active_workflow",
6-
"buildpacks": [
7-
{
8-
"url": "heroku/ruby"
9-
},
10-
{
11-
"url": "https://github.com/weibeld/heroku-buildpack-graphviz.git"
6+
"stack": "container",
7+
"formation": {
8+
"web": {
9+
"quantity": 1,
10+
"size": "free"
1211
}
13-
],
12+
},
1413
"env": {
14+
"SINGLE_DYNO": {
15+
"description": "Set to '1' if you want to run all the processes in a single dyno, leave empty otherwise. Usable only for demonstration purposes. Do not run scheduler and worker dynos if running in SINGLE_DYNO mode.",
16+
"value": "1"
17+
},
1518
"SEED_USERNAME": "admin",
1619
"SEED_PASSWORD": "password",
1720
"SEED_EMAIL": "admin@example.com",
1821
"SECRET_KEY_BASE": {
1922
"generator": "secret"
20-
}
21-
},
22-
"scripts": {
23-
"postdeploy": "bundle exec rake db:migrate db:seed"
23+
},
24+
"RAILS_ENV": "production",
25+
"RAILS_LOG_TO_STDOUT": "enabled",
26+
"RAILS_MAX_THREADS": "2",
27+
"RAILS_SERVE_STATIC_FILES": "enabled"
2428
},
2529
"addons": ["heroku-postgresql"],
2630
"success_url": "/"

0 commit comments

Comments
 (0)