From 145b5b8fbdfe8eb30f5b50d2cd9d0c86298a2101 Mon Sep 17 00:00:00 2001 From: Dmitry Menshikov Date: Tue, 3 Oct 2017 19:56:15 +0300 Subject: [PATCH 1/2] Dockerfile.dev for development --- Dockerfile.dev | 49 +++++++++++++++++++++++++++++++++ docker/docker-entrypoint-dev.sh | 18 ++++++++++++ docker/post-install-dev.sh | 19 +++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 Dockerfile.dev create mode 100755 docker/docker-entrypoint-dev.sh create mode 100644 docker/post-install-dev.sh diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..1e5c034 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,49 @@ +# cyclops dev environment +# +# NOTE: This should not be used in production! +# +# Instructions: +# +# Build the container: +# $ docker build --rm -t cyclops:dev -f Dockerfile.dev . +# Bootstrap the container: +# $ docker run --rm -d --name=cyclops-dev -v $PWD:/opt/cyclops cyclops:dev +# Run the container: +# $ docker start cyclops-dev +# Attach into the container: +# $ docker exec -it cyclops-dev bash +# Stop container: +# $ docker stop cyclops-dev +# 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 + +RUN mkdir -p /tmp/redis-server +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 docker/post-install-dev.sh /usr/bin/post-install.sh + +WORKDIR /opt/cyclops + +EXPOSE 6379 3306 +ENTRYPOINT bash /usr/bin/docker-entrypoint.sh diff --git a/docker/docker-entrypoint-dev.sh b/docker/docker-entrypoint-dev.sh new file mode 100755 index 0000000..0f4d4ff --- /dev/null +++ b/docker/docker-entrypoint-dev.sh @@ -0,0 +1,18 @@ +#!/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 + diff --git a/docker/post-install-dev.sh b/docker/post-install-dev.sh new file mode 100644 index 0000000..c7858b0 --- /dev/null +++ b/docker/post-install-dev.sh @@ -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 \ No newline at end of file From 4098eff9da46529be5ee54a8f35bbfb0e3620568 Mon Sep 17 00:00:00 2001 From: Dmitry Menshikov Date: Tue, 3 Oct 2017 20:01:53 +0300 Subject: [PATCH 2/2] Dockerfile.dev for development. Blank lines. --- docker/docker-entrypoint-dev.sh | 1 - docker/post-install-dev.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docker/docker-entrypoint-dev.sh b/docker/docker-entrypoint-dev.sh index 0f4d4ff..3fbb62f 100755 --- a/docker/docker-entrypoint-dev.sh +++ b/docker/docker-entrypoint-dev.sh @@ -15,4 +15,3 @@ service mysql start /usr/local/bin/redis-server /etc/redis.conf tail -F /var/log/mysql/error.log - diff --git a/docker/post-install-dev.sh b/docker/post-install-dev.sh index c7858b0..02ac8fb 100644 --- a/docker/post-install-dev.sh +++ b/docker/post-install-dev.sh @@ -16,4 +16,4 @@ mysql -e "SET @@SESSION.SQL_LOG_BIN=0;\ mysql -usentry -psentry -e "CREATE DATABASE sentry;" mysql -usentry -psentry sentry < /opt/cyclops/tests/sentry_db.sql -service mysql stop \ No newline at end of file +service mysql stop