Skip to content

Commit

Permalink
Merge pull request #10 from tangoslee/develop
Browse files Browse the repository at this point in the history
Develop to main
  • Loading branch information
tangoslee authored Dec 29, 2022
2 parents 81bba40 + 531bd00 commit 6423318
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ MEILISEARCH_PORT=7700
MEILISEARCH_DATA=${DATA_DIR}/data.ms
MEILISEARCH_KEY=masterKey

# Swagger
SWAGGER_ROOT=${APP_DIR}/swagger.localhost/public

# Resource
PHP_MEMORY_LIMITS=2G
PHP8_MEMORY_LIMITS=2G
MYSQL_MEMORY_LIMITS=4G
NGIX_MEMORY_LIMITS=128M
REDIS_MEMORY_LIMITS=16M
MEILSEARCH_MEMORY_LIMITS=512M

8 changes: 6 additions & 2 deletions bin/dump_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EOL
exit 1
}

SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }')
SECURE_DIR=$($CMD mysql -u root -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }')
[ "$SECURE_DIR" = "" ] && SECURE_DIR=/var/lib/mysql-files

[ -d "${DB_DUMP_DIR}" ] &&
Expand All @@ -28,7 +28,11 @@ SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{
find "${DB_DUMP_DIR}" -type f -exec rm -f {} \;
} && {
echo "Dump Started to ${DB_DUMP_DIR}"
$CMD mysqldump "$DATABASE" --tab=$SECURE_DIR --fields-terminated-by=0x1e --single-transaction --order-by-primary
$CMD mysqldump -u root "$DATABASE" --tab=$SECURE_DIR --fields-terminated-by=0x1e --single-transaction --order-by-primary
#$CMD mysqlpump -u root "$DATABASE" --tab=$SECURE_DIR --fields-terminated-by=0x1e --single-transaction --skip-definer
} && {
echo "Remove DEFINER"
$CMD find $SECURE_DIR -type f -name "*.sql" -exec perl -pi -E 's/\/\*![0-9]+\sDEFINER=.+\*\///g' {} \;
} && {
echo "The job has been successfully done!"
}
Expand Down
16 changes: 8 additions & 8 deletions bin/restore_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ EOL
exit 1
}

SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }')
SECURE_DIR=$($CMD mysql -u root -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }')
[ "$SECURE_DIR" = "" ] && SECURE_DIR=/var/lib/mysql-files

echo "Start to restore database from ${SRC}"
echo "Start to restore database from ${SRC}";
{
echo "Drop database: ${DATABASE}"
$CMD mysql -e "DROP DATABASE IF EXISTS $DATABASE"
$CMD mysql -u root -e "DROP DATABASE IF EXISTS $DATABASE"
} && {
echo "Create database"
$CMD mysql -e "CREATE DATABASE IF NOT EXISTS $DATABASE" 2> /dev/null
$CMD mysql -u root -e "CREATE DATABASE IF NOT EXISTS $DATABASE" 2> /dev/null
} && {
echo "Restore $DATABASE"
for localTxtFile in "${SRC}"/*.txt; do
Expand All @@ -38,18 +38,18 @@ echo "Start to restore database from ${SRC}"
sqlFile=${localSqlFile/.txt/.sql}
txtFile=${localTxtFile/${SRC}/${SECURE_DIR::-1}}

#echo "Create table: $table"
$CMD mysql "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;source ${sqlFile};"
echo "Create table: $table"
$CMD mysql -u root "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;source ${sqlFile};"

echo -n "Restore data: $table (${rows} rows)"
startedAt=$(date +%s.%3N)
$CMD mysql "${DATABASE}" --local-infile=1 -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;SET AUTOCOMMIT=0;ALTER TABLE ${table} DISABLE KEYS;LOAD DATA LOCAL INFILE '${txtFile}' INTO TABLE ${table} FIELDS TERMINATED BY 0x1e LINES TERMINATED BY '\n';COMMIT;ALTER TABLE ${table} ENABLE KEYS;"
$CMD mysql -u root "${DATABASE}" --local-infile=1 -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;SET AUTOCOMMIT=0;ALTER TABLE ${table} DISABLE KEYS;LOAD DATA LOCAL INFILE '${txtFile}' INTO TABLE ${table} FIELDS TERMINATED BY 0x1e LINES TERMINATED BY '\n';COMMIT;ALTER TABLE ${table} ENABLE KEYS;"
endedAt=$(date +%s.%3N)
time1=$(echo "scale=3; ${endedAt} - ${startedAt}" | bc)
echo " $time1 sec"
done

$CMD mysql "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=1;SET UNIQUE_CHECKS=1;SET AUTOCOMMIT=1;"
$CMD mysql -u root "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=1;SET UNIQUE_CHECKS=1;SET AUTOCOMMIT=1;"
} && {
echo "The job has been successfully done!"
}
Expand Down
2 changes: 2 additions & 0 deletions config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
for f in `grep -vE '^#' docker-compose.conf`;do echo -n "-f $f "; done
3 changes: 3 additions & 0 deletions docker-compose.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker-compose.yml
#docker-compose.swagger.yml
#docker-compose.meilisearch.yml
20 changes: 20 additions & 0 deletions docker-compose.meilisearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3"
services:
meilisearch:
image: getmeili/meilisearch:latest
deploy:
resources:
limits:
memory: ${MEILSEARCH_MEMORY_LIMITS}
hostname: meilisearch
container_name: meilisearch
user: ${USER_UID}:${USER_UID}
#restart: unless-stopped
#command: ./meilisearch --master-key=${MEILISEARCH_KEY} --no-analytics
command: ./meilisearch --no-analytics --http-payload-size-limit=500Mb
ports:
- "127.0.0.1:${MEILISEARCH_PORT}:${MEILISEARCH_PORT}"
volumes:
- ${MEILISEARCH_DATA}:/data.ms
networks:
- intranet
25 changes: 25 additions & 0 deletions docker-compose.swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"
services:
swagger-editor:
image: swaggerapi/swagger-editor
hostname: swagger-editor
container_name: "swagger-editor"
ports:
- "8081:8080"
networks:
- intranet

swagger-ui:
image: swaggerapi/swagger-ui
hostname: swagger-ui
container_name: "swagger-ui"
ports:
- "127.0.0.1:8082:8080"
volumes:
#- ./swagger/openapi.json:/openapi.json
- ${SWAGGER_ROOT}/openapi.json:/openapi.json
environment:
SWAGGER_JSON: /openapi.json
# API_URL: ""
networks:
- intranet
27 changes: 6 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ services:
- intranet

mysql:
image: mysql:8.0
image: mysql:8.0.23
# to fix mbind: Operation not permitted
cap_add:
- SYS_NICE
deploy:
resources:
limits:
Expand All @@ -75,7 +78,8 @@ services:
- ${DB_DUMP_DIR}:/var/lib/mysql-files
networks:
- intranet
command: --explicit_defaults_for_timestamp=ON
command: --user=mysql
--explicit_defaults_for_timestamp=ON
--character-set-server=utf8mb4
--collation-server=utf8mb4_0900_ai_ci

Expand Down Expand Up @@ -113,25 +117,6 @@ services:
networks:
- intranet

meilisearch:
image: getmeili/meilisearch:latest
deploy:
resources:
limits:
memory: ${MEILSEARCH_MEMORY_LIMITS}
hostname: meilisearch
container_name: meilisearch
user: ${USER_UID}:${USER_UID}
#restart: unless-stopped
#command: ./meilisearch --master-key=${MEILISEARCH_KEY} --no-analytics
command: ./meilisearch --no-analytics --http-payload-size-limit=500Mb
ports:
- "127.0.0.1:${MEILISEARCH_PORT}:${MEILISEARCH_PORT}"
volumes:
- ${MEILISEARCH_DATA}:/data.ms
networks:
- intranet

networks:
intranet:
driver: bridge
36 changes: 23 additions & 13 deletions mysql/etc/mysqld.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,38 @@ local_infile = 1
secure_file_priv = "/var/lib/mysql-files/"
#secure_file_priv = ""
#skip-networking = 1
disable_log_bin = 1
skip_log_bin = 1
#host_cache_size = 0
disable_log_bin = 1

# https://stackoverflow.com/questions/59391611/how-to-improve-performance-of-mysql-dump-restore#:~:text=Summary%20(for%20best%20dump%20restore,should%20be%20enabled%20on%20production.
#innodb_buffer_pool_size = 268435456
innodb_buffer_pool_size = 2G
#innodb_log_file_size = 1G
innodb_redo_log_capacity = 1G
sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

# https://dev.mysql.com/doc/refman/8.0/en/stored-programs-logging.html#:~:text=By%20default%2C%20this%20variable%20has,enabled%2C%20log_bin_trust_function_creators%20does%20not%20apply.
#binlog_format = MIXED
# https://stackoverflow.com/questions/1404107/permissions-for-creating-a-trigger-in-mysql
log_bin_trust_function_creators = ON

sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

# https://stackoverflow.com/questions/59391611/how-to-improve-performance-of-mysql-dump-restore#:~:text=Summary%20(for%20best%20dump%20restore,should%20be%20enabled%20on%20production.
# Default
#innodb_buffer_pool_size = 134217728
#innodb_log_file_size = 50331648
#bulk_insert_buffer_size = 8388608
#max_connections = 151

# 4G for MySQL
innodb_buffer_pool_size = 2G
innodb_log_file_size = 128M
#innodb_redo_log_capacity = 128M
bulk_insert_buffer_size = 128M

# default
#sort_buffer_size = 262144
#innodb_sort_buffer_size = 1048576
sort_buffer_size = 4M
innodb_sort_buffer_size = 10M
# tune
sort_buffer_size = 8M
innodb_sort_buffer_size = 16M

#innodb_max_undo_log_size = 1073741824

#innodb-force-recovery=1
#innodb_force_recovery=6
#
## default max_allowed_packet = 67108864
#max_allowed_packet = 1G
23 changes: 18 additions & 5 deletions nginx/etc/www.localhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,26 @@ server {
fastcgi_param PATH_INFO $fastcgi_path_info;
}

# S:Swagger
location /swagger/editor/ {
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://swagger-editor:8080/;
}

location /swagger/docs/ {
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://swagger-ui:8080/;
}
# E:Swagger

location / {
# try_files $uri $uri/ /index.php?$query_string @not_found;
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}

# location @not_found {
# echo "404 - Please create $file_path/public/index.html";
# }
}
7 changes: 4 additions & 3 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash

CFG=$(./config.sh)
OPT="$1"

uname -a | grep 'Darwin' > /dev/null
if [ $? -eq 0 ]; then
# Mac
docker-compose up -d $OPT
docker-compose $CFG up -d $OPT
else
# Ubuntu
# laradock_elasticsearch_1 exited with code 78
Expand All @@ -20,7 +21,7 @@ else

sudo systemctl start docker.socket && {
sudo systemctl start docker.service
docker-compose down
docker-compose up -d $OPT
docker-compose $CFG down
docker-compose $CFG up -d $OPT
} && sudo systemctl status docker.service
fi
3 changes: 2 additions & 1 deletion stop.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
docker-compose down && {
CFG=$(./config.sh)
docker-compose $CFG down && {
sudo systemctl stop docker.socket &&
sudo systemctl stop docker
} && {
Expand Down

0 comments on commit 6423318

Please sign in to comment.