Skip to content

Commit

Permalink
Adds MySQL Docker container build (#2854)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriancole authored Oct 17, 2019
1 parent b5f0d17 commit b2445f5
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 4 deletions.
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/hooks/post_build
Original file line number Diff line number Diff line change
Expand Up @@ -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/mysql; do
image=$(basename ${path})
echo Building ${image}
docker build --build-arg version="$SOURCE_BRANCH" -f "docker/${path}/Dockerfile" -t "openzipkin/${image}:${TAGS[0]}" .
Expand Down
2 changes: 1 addition & 1 deletion docker/hooks/post_push
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docker/storage/cassandra/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions docker/storage/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# 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/"

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
16 changes: 16 additions & 0 deletions docker/storage/mysql/README.md
Original file line number Diff line number Diff line change
@@ -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
```
60 changes: 60 additions & 0 deletions docker/storage/mysql/configure.sh
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions docker/storage/mysql/install.sh
Original file line number Diff line number Diff line change
@@ -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/
16 changes: 16 additions & 0 deletions docker/storage/mysql/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b2445f5

Please sign in to comment.