diff --git a/build-image/mysql/Dockerfile b/build-image/mysql_bak/Dockerfile similarity index 100% rename from build-image/mysql/Dockerfile rename to build-image/mysql_bak/Dockerfile diff --git a/build-image/mysql/entrypoint.sh b/build-image/mysql_bak/entrypoint.sh similarity index 100% rename from build-image/mysql/entrypoint.sh rename to build-image/mysql_bak/entrypoint.sh diff --git a/build-image/mysql_del/Dockerfile b/build-image/mysql_del/Dockerfile new file mode 100644 index 0000000..7dd9e31 --- /dev/null +++ b/build-image/mysql_del/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/build-image/mysql_del/entrypoint.sh b/build-image/mysql_del/entrypoint.sh new file mode 100644 index 0000000..081b008 --- /dev/null +++ b/build-image/mysql_del/entrypoint.sh @@ -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}'" \ No newline at end of file