Skip to content

Commit 6473183

Browse files
author
Vidas P
committed
Simplify docker defaults
ActiveWorkflow docker image can now be run without any arguments: ```sh docker run -p 3000:3000 automaticmode/active_workflow ``` If you want to make all the data persistent, you should use docker volume like this: ```sh docker run -p 3000:3000 -v aw-data:/var/lib/postgresql/11/main automaticmode/active_workflow ``` ActiveWorkflow image now has postgres database server included and runs all processes in one container. For production use it is still recommended to use external database and multiple containers to run web, scheduler and worker respectively.
1 parent 9cc512a commit 6473183

File tree

8 files changed

+79
-26
lines changed

8 files changed

+79
-26
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ coverage
1313
spec/tmp/*
1414
.travis.yml
1515
build_docker_image.sh
16+
Dockerfile
17+
docker-compose.yml
1618

1719
# Copied from .gitignore
1820
*.rbc

Dockerfile

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
FROM ruby:2.6.6-slim
1+
FROM ruby:2.6.6-slim-buster
22

3-
COPY docker/scripts/prepare /scripts/
4-
RUN /scripts/prepare
3+
COPY docker/scripts/prepare_os /scripts/
4+
RUN /scripts/prepare_os
55

6-
WORKDIR /app
7-
8-
COPY ./ /app/
6+
VOLUME /var/lib/postgresql/11/main
97

10-
ENV RAILS_ENV=production
8+
WORKDIR /app
119

12-
# Get rid of annoying "fatal: Not a git repository (or any of the parent directories): .git" messages
13-
RUN umask 002 && git init && \
14-
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret bundle install --redownload --no-local -j 4 && \
15-
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret bundle exec rake assets:clean assets:precompile && \
16-
chmod g=u /app/Gemfile.lock /app/config/ /app/tmp/
10+
COPY --chown=active_workflow ./ /app/
1711

12+
RUN su active_workflow -c 'docker/scripts/prepare_app'
1813

1914
EXPOSE 3000
2015

2116
COPY docker/scripts/init /scripts/
22-
CMD ["/scripts/init"]
2317

24-
USER 1001
18+
ENTRYPOINT ["tini", "--", "/app/docker/scripts/entrypoint"]

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,18 @@ entities that act on schedule or react to external triggers. These unsupervised
3737

3838
## Getting Started
3939

40+
4041
See the [Getting Started wiki page](https://github.com/automaticmode/active_workflow/wiki/Getting-Started) and follow the simple setup process.
4142

43+
44+
## Try it with docker
45+
46+
```sh
47+
docker run -p 3000:3000 automaticmode/active_workflow
48+
```
49+
50+
Once it starts you can login at [http://localhost:3000](http://localhost:3000) with `admin`/`password`.
51+
4252
## Try it on Heroku
4353

4454
A quick and easy way to check out ActiveWorkflow is by deploying it to

config/database.yml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ default: &default
66
username: <%= ENV['DATABASE_USERNAME'].presence || "active_workflow" %>
77
host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
88
port: <%= ENV['DATABASE_PORT'] || 5432 %>
9-
socket: <%= ENV['DATABASE_SOCKET'] || "" %>
109
password: <%= ENV['DATABASE_PASSWORD'] || "myactiveworkflowpassword" %>
1110
strict: false
1211

docker/scripts/entrypoint

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export RAILS_ENV=production
5+
6+
# Start internal postgres if no database is configured.
7+
if [ -z "${DATABASE_HOST}" ] && [ -z "${DATABASE_URL}" ]; then
8+
/etc/init.d/postgresql start
9+
echo -n 'Waiting for postgres to be ready'
10+
until runuser -l postgres -c 'pg_isready' 2>/dev/null; do
11+
sleep 1; echo -n '.'
12+
done
13+
echo ' done.'
14+
runuser -l postgres -c 'createuser --createdb active_workflow || true'
15+
# Use domain socket to connect to postgres.
16+
export DATABASE_URL=postgres:///active_workflow
17+
export DATABASE_HOST=''
18+
export DATABASE_USERNAME=''
19+
export DATABASE_PASSWORD=''
20+
export CREATE_DATABASE=${CREATE_DATABASE:-true}
21+
# Only use one container when running with internal database.
22+
export SINGLE_DYNO=1
23+
fi
24+
25+
if [ -n "$1" ]; then
26+
CMD=$1
27+
shift
28+
else
29+
CMD=docker/scripts/init
30+
fi
31+
32+
# Drop root and execute startup script with normal permissions.
33+
exec setpriv --reuid active_workflow --clear-groups $CMD "$@"

docker/scripts/init

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
#!/bin/bash
22
set -e
33

4+
# Environment defaults
5+
export DISABLE_SSL=${DISABLE_SSL:-true}
6+
47
cd /app
58

69
# Cleanup any leftover pid file
710
if [ -f /app/tmp/pids/server.pid ]; then
811
rm /app/tmp/pids/server.pid
912
fi
1013

14+
if [ -z "${SECRET_KEY_BASE}" ]; then
15+
echo 'WARNING: Please set SECRET_KEY_BASE to a random string, using "change me!" for this run.'
16+
export SECRET_KEY_BASE='change me!'
17+
fi
18+
1119
# The database may need to start up for a bit first
1220
if [ -n "${INTENTIONALLY_SLEEP}" ]; then
1321
echo "Intentionally sleeping ${INTENTIONALLY_SLEEP}"
1422
sleep ${INTENTIONALLY_SLEEP}
1523
fi
16-
17-
1824
if [ -n "${DATABASE_INITIAL_CONNECT_MAX_RETRIES}" ]; then
1925
max=${DATABASE_INITIAL_CONNECT_MAX_RETRIES}
2026
count=0

docker/scripts/prepare_app

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
umask 002
5+
gem install bundler
6+
bundle config set no-cache 'true'
7+
bundle config set without 'test development'
8+
bundle config set deployment 'true'
9+
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret bundle install --redownload --no-local -j 4
10+
LC_ALL=en_US.UTF-8 RAILS_ENV=production SECRET_KEY_BASE=secret bundle exec rake assets:clean assets:precompile
11+
chmod g=u /app/Gemfile.lock /app/config/ /app/tmp/

docker/scripts/prepare renamed to docker/scripts/prepare_os

+7-9
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ $minimal_apt_get_install build-essential git-core \
2222
zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev \
2323
libncurses5-dev libffi-dev libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev \
2424
graphviz libgraphviz-dev \
25-
libpq-dev libsqlite3-dev tzdata
25+
libpq-dev libsqlite3-dev tzdata \
26+
postgresql-11 tini
2627

2728
apt-get purge -y python3* rsyslog rsync manpages
2829
apt -y autoremove
2930
apt-get -y clean
3031

31-
gem install bundler
32-
bundle config set no-cache 'true'
33-
bundle config set without 'test development'
34-
bundle config set deployment 'true'
35-
36-
mkdir -p /app
37-
chmod -R g=u /etc/passwd /app
38-
3932
rm -rf /var/lib/apt/lists/*
4033
rm -rf /usr/share/doc/
4134
rm -rf /usr/share/man/
4235
rm -rf /usr/share/locale/
4336
rm -rf /var/log/*
37+
38+
useradd --home-dir /app --no-create-home --no-log-init active_workflow
39+
mkdir -p /app
40+
chown -R active_workflow /app
41+
chmod 700 /app

0 commit comments

Comments
 (0)