add build image mysql del

main
ycz 2025-05-28 16:57:11 +08:00
parent e0020a3aa8
commit fbb13501b9
4 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,8 @@
FROM mysql:8.0.33-debian
LABEL MAINTAINER='beaconfire'
ENV HOST="" PORT="" MYSQL_USER="" MYSQL_PASSWORD="" REMAIN_DAYS=""
COPY entrypoint.sh /usr/local/bin
CMD [ "/usr/local/bin/entrypoint.sh" ]

View File

@ -0,0 +1,12 @@
#!/bin/bash
echo -ne "[client]\nhost=${HOST}\nport=${PORT}\nuser=${MYSQL_USER}\npassword=${MYSQL_PASSWORD}\n" > /etc/my.cnf
create_time=$(mysql --defaults-extra-file=/etc/my.cnf -e "SELECT NOW() - INTERVAL '$REMAIN_DAYS' DAY"|egrep '[0-9]{4}')
if [ -z "$create_time" ]; then
echo "Failed to retrieve create_time. Exiting."
exit 1
fi
echo "Deleting records older than: $create_time"
mysql --defaults-extra-file=/etc/my.cnf -e "delete * from question.code_run where create_time <'${create_time}'"