From 74a423c9a4031d6a413f9b7468d6cb36fbe13b54 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 17 Oct 2019 16:27:38 +0800 Subject: [PATCH 1/3] Adds MySQL Docker container build --- docker/README.md | 1 + docker/hooks/post_build | 2 +- docker/hooks/post_push | 2 +- docker/storage/mysql/Dockerfile | 31 ++++++++++++++++ docker/storage/mysql/README.md | 16 +++++++++ docker/storage/mysql/configure.sh | 60 +++++++++++++++++++++++++++++++ docker/storage/mysql/install.sh | 22 ++++++++++++ docker/storage/mysql/run.sh | 16 +++++++++ 8 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 docker/storage/mysql/Dockerfile create mode 100644 docker/storage/mysql/README.md create mode 100755 docker/storage/mysql/configure.sh create mode 100755 docker/storage/mysql/install.sh create mode 100755 docker/storage/mysql/run.sh diff --git a/docker/README.md b/docker/README.md index 159b5475906..4db396fc118 100644 --- a/docker/README.md +++ b/docker/README.md @@ -28,6 +28,7 @@ base layer `openzipkin/zipkin`, and setting up schema where relevant. * [zipkin-elasticsearch6](storage/elasticsearch6/README.md) - runs Elasticsearch 6.x * [zipkin-elasticsearch7](storage/elasticsearch7/README.md) - runs Elasticsearch 7.x * [zipkin-kafka](collector/kafka/README.md) - runs both Kafka+ZooKeeper +* [zipkin-mysql](storage/mysql/README.md) - runs MySQL initialized with Zipkin's schema * [zipkin-ui](lens/README.md) - serves the (Lens) UI directly with NGINX ### Dockerfile migration diff --git a/docker/hooks/post_build b/docker/hooks/post_build index 6d08e350adb..ee9c169b604 100755 --- a/docker/hooks/post_build +++ b/docker/hooks/post_build @@ -26,7 +26,7 @@ for tag in ${TAGS[@]:1}; do done # We also build testing images to correspond with the server version to keep schemas up to date -for path in collector/kafka storage/cassandra storage/elasticsearch6 storage/elasticsearch7; do +for path in collector/kafka storage/cassandra storage/elasticsearch6 storage/elasticsearch7 storage/msql; do image=$(basename ${path}) echo Building ${image} docker build --build-arg version="$SOURCE_BRANCH" -f "docker/${path}/Dockerfile" -t "openzipkin/${image}:${TAGS[0]}" . diff --git a/docker/hooks/post_push b/docker/hooks/post_push index f716ee30e2b..c18152824cd 100755 --- a/docker/hooks/post_push +++ b/docker/hooks/post_push @@ -13,7 +13,7 @@ if [[ "$DOCKER_REPO" == "index.docker.io/openzipkin/zipkin" ]]; then docker push "openzipkin/zipkin-${collector}:$tag" done - for storage in cassandra elasticsearch6 elasticsearch7; do + for storage in cassandra elasticsearch6 elasticsearch7 mysql; do docker push "openzipkin/zipkin-${storage}:$tag" done done diff --git a/docker/storage/mysql/Dockerfile b/docker/storage/mysql/Dockerfile new file mode 100644 index 00000000000..4abfe5d9110 --- /dev/null +++ b/docker/storage/mysql/Dockerfile @@ -0,0 +1,31 @@ +# +# Copyright 2015-2019 The OpenZipkin Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# + +FROM alpine +LABEL MAINTAINER Zipkin "https://zipkin.io/" + +ENV ZIPKIN_VERSION 2.18.0 + +WORKDIR /mysql +ADD docker/storage/mysql/install.sh /mysql/install +ADD docker/storage/mysql/configure.sh /mysql/configure +ADD docker/storage/mysql/run.sh /mysql/run.sh +ADD zipkin-storage/mysql-v1/src/main/resources/mysql.sql /mysql/zipkin.sql + +RUN /mysql/install && \ + /mysql/configure + +CMD /mysql/run.sh + +EXPOSE 3306 diff --git a/docker/storage/mysql/README.md b/docker/storage/mysql/README.md new file mode 100644 index 00000000000..59d7200ce6d --- /dev/null +++ b/docker/storage/mysql/README.md @@ -0,0 +1,16 @@ +## zipkin-mysql Docker image + +The `zipkin-mysql` testing image runs MySQL 3.11.x initialized with Zipkin's schema for +[MySQL storage](../../../zipkin-storage/mysql-v1) integration. + +To build `openzipkin/zipkin-mysql`, from the top level of the repository, run: + +```bash +$ docker build -t openzipkin/zipkin-mysql:test -f docker/storage/mysql/Dockerfile . +``` + +When running with docker-machine, you can connect like so: + +```bash +$ mysql -h $(docker-machine ip) -u zipkin -pzipkin -D zipkin +``` diff --git a/docker/storage/mysql/configure.sh b/docker/storage/mysql/configure.sh new file mode 100755 index 00000000000..4f9fabfcb07 --- /dev/null +++ b/docker/storage/mysql/configure.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# +# Copyright 2015-2019 The OpenZipkin Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# + +set -eux + +echo "*** Installing MySQL client" +apk add --update --no-cache mysql-client +chown -R mysql /mysql + +echo "*** Starting MySQL" +mysqld --user=mysql --basedir=/usr/ --datadir=/mysql/data & + +timeout=300 +while [[ "$timeout" -gt 0 ]] && ! mysql --user=mysql --protocol=socket -uroot -e 'SELECT 1' >/dev/null 2>/dev/null; do + echo "Waiting ${timeout} seconds for mysql to come up" + sleep 2 + timeout=$(($timeout - 2)) +done + +echo "*** Installing Schema" +mysql --verbose --user=mysql --protocol=socket -uroot <<-EOSQL +USE mysql ; + +DELETE FROM mysql.user ; +DROP DATABASE IF EXISTS test ; + +CREATE DATABASE zipkin ; + +USE zipkin; +SOURCE /mysql/zipkin.sql ; + +GRANT ALL PRIVILEGES ON zipkin.* TO zipkin@'%' IDENTIFIED BY 'zipkin' WITH GRANT OPTION ; +FLUSH PRIVILEGES ; +EOSQL + +echo "*** Stopping MySQL" +pkill -f mysqld + + +echo "*** Enabling Networking" +cat >> /etc/my.cnf <<-"EOF" +[mysqld] +skip-networking=0 +skip-bind-address +EOF + +echo "*** Cleaning Up" +apk del mysql-client --purge diff --git a/docker/storage/mysql/install.sh b/docker/storage/mysql/install.sh new file mode 100755 index 00000000000..4aa91bf27da --- /dev/null +++ b/docker/storage/mysql/install.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# +# Copyright 2015-2019 The OpenZipkin Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# + +set -eux + +echo "*** Installing MySQL" +apk add --update --no-cache mysql curl +mysql_install_db --user=mysql --basedir=/usr/ --datadir=/mysql/data --force +mkdir -p /run/mysqld/ +chown -R mysql /mysql /run/mysqld/ diff --git a/docker/storage/mysql/run.sh b/docker/storage/mysql/run.sh new file mode 100755 index 00000000000..39b647bf907 --- /dev/null +++ b/docker/storage/mysql/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# +# Copyright 2015-2019 The OpenZipkin Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# + +/usr/bin/mysqld_safe --user=mysql --basedir=/usr/ --datadir=/mysql/data From 04aa898ac95225a4c5b481727da429909b1ce166 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 17 Oct 2019 16:41:48 +0800 Subject: [PATCH 2/3] removes orphaned version links --- docker/storage/cassandra/Dockerfile | 2 -- docker/storage/mysql/Dockerfile | 2 -- 2 files changed, 4 deletions(-) diff --git a/docker/storage/cassandra/Dockerfile b/docker/storage/cassandra/Dockerfile index c5f93f75b8c..d4ea261cbec 100644 --- a/docker/storage/cassandra/Dockerfile +++ b/docker/storage/cassandra/Dockerfile @@ -16,8 +16,6 @@ FROM openzipkin/jre-full:1.8.0_212 MAINTAINER OpenZipkin "http://zipkin.io/" -ENV ZIPKIN_VERSION 2.18.0 - ENV CASSANDRA_VERSION=3.11.4 \ JAVA=/usr/local/java/jre/bin/java \ JVM_OPTS="-Dcassandra -Djava.net.preferIPv4Stack=true" diff --git a/docker/storage/mysql/Dockerfile b/docker/storage/mysql/Dockerfile index 4abfe5d9110..e3856e78f8f 100644 --- a/docker/storage/mysql/Dockerfile +++ b/docker/storage/mysql/Dockerfile @@ -15,8 +15,6 @@ FROM alpine LABEL MAINTAINER Zipkin "https://zipkin.io/" -ENV ZIPKIN_VERSION 2.18.0 - WORKDIR /mysql ADD docker/storage/mysql/install.sh /mysql/install ADD docker/storage/mysql/configure.sh /mysql/configure From 23d69cd7b5993d39a0eb92aa430d84ebb9e3bb30 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 17 Oct 2019 16:44:26 +0800 Subject: [PATCH 3/3] typo --- docker/hooks/post_build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/hooks/post_build b/docker/hooks/post_build index ee9c169b604..8ef4c389a67 100755 --- a/docker/hooks/post_build +++ b/docker/hooks/post_build @@ -26,7 +26,7 @@ for tag in ${TAGS[@]:1}; do done # We also build testing images to correspond with the server version to keep schemas up to date -for path in collector/kafka storage/cassandra storage/elasticsearch6 storage/elasticsearch7 storage/msql; do +for path in collector/kafka storage/cassandra storage/elasticsearch6 storage/elasticsearch7 storage/mysql; do image=$(basename ${path}) echo Building ${image} docker build --build-arg version="$SOURCE_BRANCH" -f "docker/${path}/Dockerfile" -t "openzipkin/${image}:${TAGS[0]}" .