new PHP ratings service
This commit is contained in:
16
mysql/Dockerfile
Normal file
16
mysql/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
||||
FROM mysql:5.7.20
|
||||
|
||||
ENV MYSQL_ALLOW_EMPTY_PASSWORD=yes \
|
||||
MYSQL_DATABASE=cities \
|
||||
MYSQL_USER=shipping \
|
||||
MYSQL_PASSWORD=secret
|
||||
|
||||
# change datadir entry in /etc/mysql/my.cnf
|
||||
COPY config.sh /root/
|
||||
RUN /root/config.sh
|
||||
|
||||
COPY scripts/* /docker-entrypoint-initdb.d/
|
||||
|
||||
RUN /entrypoint.sh mysqld & while [ ! -f /tmp/finished ]; do sleep 10; done
|
||||
RUN rm /docker-entrypoint-initdb.d/*
|
||||
|
19
mysql/config.sh
Executable file
19
mysql/config.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
DIR="/etc/mysql"
|
||||
|
||||
FILE=$(fgrep -Rl datadir "$DIR")
|
||||
if [ -n "$FILE" ]
|
||||
then
|
||||
# mkdir /data/mysql
|
||||
echo " "
|
||||
echo "Updating $FILE"
|
||||
echo " "
|
||||
sed -i -e '/^datadir/s/\/var\/lib\//\/data\//' $FILE
|
||||
fgrep -R datadir "$DIR"
|
||||
else
|
||||
echo " "
|
||||
echo "file not found"
|
||||
echo " "
|
||||
fi
|
||||
|
27
mysql/convert.sh
Executable file
27
mysql/convert.sh
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Convert cities CSV file to SQL
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "File required as first arg"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# \x27 is a single quote
|
||||
# \x60 is back tick
|
||||
awk '
|
||||
BEGIN {
|
||||
FS=","
|
||||
format = "INSERT INTO cities(country_code, city, name, region, latitude, longitude) VALUES(\x27%s\x27, \x27%s\x27, \x27%s\x27, \x27%s\x27, %s, %s);\n"
|
||||
getline
|
||||
}
|
||||
{
|
||||
gsub(/\x27/, "\x60", $2)
|
||||
gsub(/\x27/, "\x60", $3)
|
||||
gsub(/\x27/, "\x60", $4)
|
||||
if(NF == 6) printf format, $1, $2, $3, $4, $5, $6
|
||||
else printf format, $1, $2, $3, $4, $6, $7
|
||||
}
|
||||
' $1
|
||||
|
BIN
mysql/scripts/10-dump.sql.gz
Normal file
BIN
mysql/scripts/10-dump.sql.gz
Normal file
Binary file not shown.
16
mysql/scripts/20-ratings.sql
Normal file
16
mysql/scripts/20-ratings.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CREATE DATABASE ratings
|
||||
DEFAULT CHARACTER SET 'utf8';
|
||||
|
||||
USE ratings;
|
||||
|
||||
CREATE TABLE ratings (
|
||||
sku varchar(80) NOT NULL,
|
||||
avg_rating DECIMAL(3, 2) NOT NULL,
|
||||
rating_count INT NOT NULL,
|
||||
PRIMARY KEY (sku)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
GRANT ALL ON ratings.* TO 'ratings'@'%'
|
||||
IDENTIFIED BY 'iloveit';
|
||||
|
5
mysql/scripts/99-finished.sh
Executable file
5
mysql/scripts/99-finished.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
# signal that the import has finsihed
|
||||
touch /tmp/finished
|
||||
|
Reference in New Issue
Block a user