Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile.dev for development #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
49 changes: 49 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# cyclops dev environment
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move your files to specific directory, for example
docker/work/Dockerfile
docker/work/root/usr/local/bin/docker-entrypoint.sh
docker/work/root/usr/local/bin/post-install.sh

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make no sense for small deployments like this one.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about prod docker file? where it will be stored?

#
# NOTE: This should not be used in production!
#
# Instructions:
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This information should be in README or CONTRIBUTING

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

#
# Build the container:
# $ docker build --rm -t cyclops:dev -f Dockerfile.dev .
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push and image to docker hub!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related with this PR

# Bootstrap the container:
# $ docker run --rm -d --name=cyclops-dev -v $PWD:/opt/cyclops cyclops:dev
# Run the container:
# $ docker start cyclops-dev
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have running container. Docker remove it on stop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, you suggest remove --rm from docker run?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I suggest single flow. If you use --rm - no need to write instructions like start

# Attach into the container:
# $ docker exec -it cyclops-dev bash
# Stop container:
# $ docker stop cyclops-dev
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and next instructions, you already recommend once-running containers.

# Remove container:
# $ docker rm -f cyclops-dev
#
# Install dependencies and run tests (after start of container and login into it):
# $ cd /opt/cyclops
# $ pip install -e . -e .[mysql] -e .[tests]
# $ CYCLOPS_TEST_DB_USER=sentry CYCLOPS_TEST_DB_PASS=sentry make tests

FROM mysql:5.7

RUN apt-get update && apt-get install -y --no-install-recommends build-essential tcl curl wget vim python2.7 python3.4 python-pip python-dev python3-dev libssl-dev libcurl4-openssl-dev libmysqlclient-dev
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear apt cache at the end of command


RUN mkdir -p /tmp/redis-server
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to make redis build in single RUN instruction. No need to create huge file system layers, which you will not use

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to combine few RUN instructions?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. Any instructions like RUN, ENV, COPY... create new file system layer

RUN curl -s http://download.redis.io/releases/redis-3.2.10.tar.gz | tar -xzf - -C /tmp/redis-server --strip-components=1
RUN cd /tmp/redis-server && make && make install
RUN sed '/^#/ d ; /^$/ d ; s/^dir \.\//dir \/var\/lib\/redis/ ; s/^daemonize no/daemonize no/' /tmp/redis-server/redis.conf > /etc/redis.conf
RUN rm -rf /tmp/redis-server
RUN cat /etc/redis.conf
RUN adduser --system --group --no-create-home redis
RUN mkdir /var/lib/redis /var/log/redis
RUN chown redis:redis /var/lib/redis /var/log/redis
RUN chmod 770 /var/lib/redis && chmod 755 /var/log/redis

RUN update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
RUN mkdir -p /opt/cyclops

COPY docker/docker-entrypoint-dev.sh /usr/bin/docker-entrypoint.sh
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you any plans to create another files, like docker-entrypoint-prod.sh?

COPY docker/post-install-dev.sh /usr/bin/post-install.sh

WORKDIR /opt/cyclops

EXPOSE 6379 3306
ENTRYPOINT bash /usr/bin/docker-entrypoint.sh
17 changes: 17 additions & 0 deletions docker/docker-entrypoint-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

if [ ! -f /var/lock/post-install ]; then
bash /usr/bin/post-install.sh

RESULT=$?
if [ $RESULT -ne 0 ]; then
exit $RESULT
fi

touch /var/lock/post-install
fi

service mysql start
/usr/local/bin/redis-server /etc/redis.conf

tail -F /var/log/mysql/error.log
19 changes: 19 additions & 0 deletions docker/post-install-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
mysqld --initialize-insecure --datadir=/var/lib/mysql

chown -R mysql:mysql /var/lib/mysql
service mysql start

mysql -e "SET @@SESSION.SQL_LOG_BIN=0;\
DELETE FROM mysql.user WHERE user NOT IN ('mysql.sys', 'mysqlxsys', 'root') OR host NOT IN ('localhost');\
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('root');\
CREATE USER 'sentry'@'localhost' IDENTIFIED BY 'sentry' PASSWORD EXPIRE NEVER;\
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;\
GRANT ALL PRIVILEGES ON sentry.* TO 'sentry'@'localhost';\
GRANT ALL PRIVILEGES ON sentry_tests.* TO 'sentry'@'localhost';\
FLUSH PRIVILEGES ;"

mysql -usentry -psentry -e "CREATE DATABASE sentry;"
mysql -usentry -psentry sentry < /opt/cyclops/tests/sentry_db.sql

service mysql stop
Copy link

@index0h index0h Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For unification purpose. post install runs once but service mysql start runs on every run. I think that checking that mysql is running each time docker start calls is much worse than stop-start cycle on bootstrap phase.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok