Skip to content

Commit 2e5aac4

Browse files
committed
Added example dockerfile for using MySQL as datastore and updated documentation
1 parent 9ff7345 commit 2e5aac4

10 files changed

+307
-0
lines changed

.dockerignore

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Git
2+
.git/
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
env/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
46+
# Translations
47+
*.mo
48+
*.pot
49+
50+
# Django stuff:
51+
*.log
52+
53+
# Sphinx documentation
54+
docs/_build/
55+
56+
# PyBuilder
57+
target/
58+
59+
# Editor files
60+
*.iml
61+
.idea

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ docs/_build/
5252

5353
# PyBuilder
5454
target/
55+
56+
# Editor files
57+
*.iml
58+
.idea

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Set the base image to Python
2+
FROM python:2.7.9
3+
4+
5+
# Environment
6+
ENV DEBIAN_FRONTEND noninteractive
7+
8+
# Create the working dir and set the working directory
9+
WORKDIR /
10+
11+
# Install dependencies
12+
COPY ./requirements.txt /requirements.txt
13+
RUN pip install -r requirements.txt \
14+
&& pip install supervisor \
15+
&& pip install gunicorn
16+
17+
# Install OpenTaxii
18+
RUN mkdir /opentaxii
19+
COPY ./ /opentaxii/
20+
RUN cd /opentaxii && python setup.py install && rm -rf /opentaxii
21+
22+
# Setup default config
23+
COPY opentaxii/defaults.yml /opentaxi.yml
24+
ENV OPENTAXII_CONFIG /opentaxii.yml
25+
26+
# Expose and Run
27+
COPY docker-supervisord.conf /supervisord.conf
28+
EXPOSE 9000
29+
CMD ["supervisord","-c","/supervisord.conf"]
30+

docker-supervisord.conf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:opentaxii]
5+
environment = OPENTAXII_CONFIG="/opentaxii.yml"
6+
command = gunicorn opentaxii.http:app
7+
--workers 2
8+
--log-level info
9+
--log-file -
10+
--timeout 300
11+
--bind 0.0.0.0:9000
12+
13+
stdout_logfile = /var/log/opentaxii.log
14+
redirect_stderr = true
15+
autostart = true
16+
autorestart = true

docs/docker.rst

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
=============
2+
Docker
3+
=============
4+
5+
.. highlight:: sh
6+
7+
OpenTAXII can also be run using docker. This guide assumes that you have access to a local or remote docker server, and won't go into the setup of docker.
8+
9+
To get a default (development) instance using docker
10+
11+
12+
.. code-block:: shell
13+
14+
docker run -d -p 9000:9000 intelworks/opentaxii
15+
16+
.. note::
17+
18+
OpenTAXII is now accessible through port 9000, and is not configured.
19+
20+
Extending
21+
====================
22+
23+
A better way using the OpenTAXII docker image, is to extend it, and create the custom configuration on startup. An example of is can be found `examples/Dockerfile <https://raw.githubusercontent.com/Intelworks/OpenTAXII/master/examples/Dockerfile>`_. Here the the configuration is replaced by an instance using MySQL.
24+
25+
.. code-block:: docker
26+
27+
FROM intelworks/opentaxii:latest
28+
MAINTAINER [email protected]
29+
30+
RUN pip install mysql-python
31+
32+
COPY services.yml /services.yml
33+
COPY collections.yml /collections.yml
34+
COPY docker-entrypoint.sh /entrypoint.sh
35+
36+
ENV OPENTAXII_AUTH_SECRET "SOME SECRET"
37+
ENV OPENTAXII_DOMAIN "localhost:9000"
38+
ENV OPENTAXII_USER ""
39+
ENV OPENTAXII_PASS ""
40+
ENV DB_USER ""
41+
ENV DB_PASS ""
42+
ENV DB_NAME ""
43+
ENV DB_HOST ""
44+
ENV DB_PORT ""
45+
46+
ENTRYPOINT ["./entrypoint.sh"]
47+
CMD [ "supervisord","-c","/supervisord.conf" ]
48+
49+
50+
Using this configuration it is possible to add a new `/opentaxii.yml` configuration, which in this case is generated by the `entrypoint.sh` script. Furthermore it adds the example `services.yml` and `collections.yml` to the image.
51+
52+
To see this in action, you can use the `docker-compose <https://docs.docker.com/compose/>`_ tool to run a complete working setup using mysql. The configuration is located at: `examples/docker-compose.yml <https://raw.githubusercontent.com/Intelworks/OpenTAXII/master/examples/docker-compose.yml>`_
53+
54+
.. code-block:: yaml
55+
56+
db:
57+
image: mysql
58+
environment:
59+
MYSQL_USER: user
60+
MYSQL_PASSWORD: password
61+
MYSQL_DATABASE: opentaxii
62+
MYSQL_ROOT_PASSWORD: pass
63+
ports:
64+
- 3306:3306
65+
66+
opentaxii:
67+
build: .
68+
environment:
69+
OPENTAXII_AUTH_SECRET: secret
70+
OPENTAXII_DOMAIN: localhost:9000
71+
OPENTAXII_USER: user1
72+
OPENTAXII_PASS: pass1
73+
DB_HOST: db
74+
DB_PORT: 3306
75+
DB_NAME: opentaxii
76+
DB_USER: user
77+
DB_PASS: password
78+
ports:
79+
- 9000:9000
80+
links:
81+
- db:db
82+
83+
This configuration starts two containers: 'opentaxii' and 'mysql', creates the given collections and services, and adds a user for authentication.
84+
85+
86+
.. rubric:: Next steps
87+
88+
Continue to :doc:`Authentication <auth>` page to learn how OpenTAXII authentication process works.
89+
90+
91+
92+
.. vim: set spell spelllang=en:

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ OpenTAXII architecture follows TAXII specification in its idea of TTA (TAXII tra
3232
installation
3333
configuration
3434
running
35+
docker
3536
auth
3637
public-apis
3738
opentaxii-apis

examples/Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM intelworks/opentaxii:latest
2+
3+
4+
RUN pip install mysql-python
5+
6+
COPY services.yml /services.yml
7+
COPY collections.yml /collections.yml
8+
COPY docker-entrypoint.sh /entrypoint.sh
9+
10+
ENV OPENTAXII_AUTH_SECRET "SOME SECRET"
11+
ENV OPENTAXII_DOMAIN "localhost:9000"
12+
ENV OPENTAXII_USER ""
13+
ENV OPENTAXII_PASS ""
14+
ENV DB_USER ""
15+
ENV DB_PASS ""
16+
ENV DB_NAME ""
17+
ENV DB_HOST ""
18+
ENV DB_PORT ""
19+
20+
ENTRYPOINT ["./entrypoint.sh"]
21+
CMD [ "supervisord","-c","/supervisord.conf" ]

examples/create-fixtures.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12

23
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
34

examples/docker-compose.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
db:
2+
image: mysql
3+
environment:
4+
MYSQL_USER: user
5+
MYSQL_PASSWORD: password
6+
MYSQL_DATABASE: opentaxii
7+
MYSQL_ROOT_PASSWORD: pass
8+
ports:
9+
- 3306:3306
10+
11+
opentaxii:
12+
build: .
13+
environment:
14+
OPENTAXII_AUTH_SECRET: secret
15+
OPENTAXII_DOMAIN: localhost:9000
16+
OPENTAXII_USER: user1
17+
OPENTAXII_PASS: pass1
18+
DB_HOST: db
19+
DB_PORT: 3306
20+
DB_NAME: opentaxii
21+
DB_USER: user
22+
DB_PASS: password
23+
24+
ports:
25+
- 9000:9000
26+
links:
27+
- db:db

examples/docker-entrypoint.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
function wait_for_port() {
4+
(echo >/dev/tcp/$1/$2) &>/dev/null
5+
while [ $? -ne 0 ];
6+
do
7+
echo "Waiting for $1:$2 to become available"
8+
sleep 1
9+
(echo >/dev/tcp/$1/$2) &>/dev/null
10+
done
11+
echo "$1:$2 is now open"
12+
}
13+
14+
AUTH_SECRET="${OPENTAXII_AUTH_SECRET-SOME_SECRET}"
15+
AUTH=""
16+
[ "$DB_USER" -a "$DB_PASS" ] && AUTH="${DB_USER}:${DB_PASS}@"
17+
PORT=":3306"
18+
[ "$DB_PORT" ] && PORT=":$DB_PORT"
19+
20+
tmpConfig='/tmp/opentaxii.yml'
21+
cat > "$tmpConfig" <<-EOCONFIG
22+
---
23+
24+
domain: "${OPENTAXII_DOMAIN}"
25+
26+
persistence_api:
27+
class: opentaxii.persistence.sqldb.SQLDatabaseAPI
28+
parameters:
29+
db_connection: mysql://${AUTH}${DB_HOST}${PORT}/${DB_NAME}
30+
create_tables: yes
31+
32+
auth_api:
33+
class: opentaxii.auth.sqldb.SQLDatabaseAPI
34+
parameters:
35+
db_connection: mysql://${AUTH}${DB_HOST}${PORT}/${DB_NAME}
36+
create_tables: yes
37+
secret: ${AUTH_SECRET}
38+
39+
logging:
40+
opentaxii: info
41+
root: info
42+
43+
hooks:
44+
EOCONFIG
45+
cat $tmpConfig
46+
cp -f $tmpConfig /opentaxii.yml
47+
48+
49+
wait_for_port $DB_HOST $PORT
50+
[ -f /services.yml ] && opentaxii-create-services -c /services.yml
51+
[ -f /collections.yml ] && opentaxii-create-collections -c /collections.yml
52+
[ "$OPENTAXII_USER" -a "$OPENTAXII_PASS" ] && opentaxii-create-account -u "$OPENTAXII_USER" -p "$OPENTAXII_PASS"
53+
54+
exec "$@"

0 commit comments

Comments
 (0)