-
Notifications
You must be signed in to change notification settings - Fork 111
Added Docker support #9
base: master
Are you sure you want to change the base?
Changes from 2 commits
a37efc8
476e1e8
c8aff67
10f9a40
5a9db9e
c357704
755253e
a5a5ce5
e806b2a
182816e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM python:2.7 | ||
|
||
COPY . /securitybot | ||
|
||
USER securitybot | ||
|
||
env PYTHONPATH $PYTHONPATH:/securitybot | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y mysql-client && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps rather than installing mysql in this container we could link to a separate mysql container, and include a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not installing MySQL server in the container. Just installing client and libs as it's a prereq for the python MySQLDB lib. I'm also using the client to test for database connection and presence before starting the bot. I could probably change these test to a Python script rather than call the client directly, should seemed to be less trouble this way. For deployment, i'm working on a docker-compose with MySQL and a Kubernetes deployment manifest in a separate repo. Can add them here when they're ready if you'd like, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. I think a docker-compose file with a MySQL linked container would be useful in this repository - makes it quite simple to get everything up and running locally. The kubernetes config files seem a little out of scope, and something that probably wouldn't be maintained here. Let's leave that in another repository :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, added docker-compose with DB, bot and frontend. Agreed kubernetes deployment is out of scope here, will keep it separate. |
||
pip install -r /securitybot/requirements.txt | ||
|
||
WORKDIR /securitybot | ||
|
||
ENTRYPOINT ["/securitybot/docker_entrypoint.sh"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per docker best practices, we should avoid running securitybot as root in the container. How about adding a new user, then adding: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was dumb of me, didn't create the user properly, and hadn't tested rebuild properly. Fixed now and added docker test to travis. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
|
||
end=$((SECONDS + 120)) | ||
|
||
# Wait max of 2 minutes for database to come up | ||
until mysql --user $DB_USER --password=$DB_PASS --host=$DB_HOST -e"quit" || [ $SECONDS -ge $end ]; do echo "Waiting for DB"; sleep 2; done; | ||
|
||
# Check if database is initialized | ||
if ! mysql --user $DB_USER --password=$DB_PASS --host=$DB_HOST -e"use $DB_NAME"; then | ||
echo "Creating database" | ||
mysql --user $DB_USER --password=$DB_PASS --host=$DB_HOST -e"create database $DB_NAME" | ||
echo "Populating database" | ||
python /securitybot/util/db_up.py | ||
fi | ||
|
||
|
||
if [ "$1" = 'bot' ]; then | ||
echo "Starting bot" | ||
shift | ||
exec python /securitybot/main.py "$@" | ||
elif [ "$1" = 'frontend' ]; then | ||
echo "Starting frontend" | ||
shift | ||
exec python /securitybot/frontend/securitybot_frontend.py "$@" | ||
fi | ||
|
||
exec "$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is going to throw an error, since the user will not exist.
Adding a new user up above is the way to go, something like this:
RUN adduser --disabled-password --gecos '' securitybot