MySQL > MariaDB

This commit is contained in:
Dennis Postma 2025-02-07 22:35:54 +01:00
parent 50f595f718
commit 13252e056f
2 changed files with 16 additions and 16 deletions

View File

@ -3,17 +3,17 @@ FROM node:23.7.0-alpine
# Install dependencies with versions
RUN apk add --no-cache \
redis \
mysql \
mysql-client \
mariadb \
mariadb-client \
tmux
# Create non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Setup MySQL
# Setup MariaDB
RUN mkdir -p /run/mysqld && \
chown -R mysql:mysql /run/mysqld && \
mysql_install_db --user=mysql --datadir=/var/lib/mysql
mariadb-install-db --user=mysql --datadir=/var/lib/mysql
WORKDIR /usr/src/app
COPY package*.json ./
@ -29,6 +29,6 @@ USER appuser
EXPOSE 80 6379 3306
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD mysqladmin ping -h localhost || exit 1
CMD mariadb-admin ping -h localhost || exit 1
CMD ["./start.sh"]

View File

@ -10,7 +10,7 @@ cleanup() {
echo "Cleaning up..."
tmux kill-session -t $APP_NAME 2>/dev/null || true
redis-cli shutdown || true
mysqladmin -u root shutdown || true
mariadb-admin -u root shutdown || true
exit 0
}
@ -25,23 +25,23 @@ if ! redis-cli ping > /dev/null 2>&1; then
exit 1
fi
# Start MySQL
echo "Starting MySQL..."
mysqld --user=mysql --datadir=/var/lib/mysql &
# Start MariaDB
echo "Starting MariaDB..."
mariadbd --user=mysql --datadir=/var/lib/mysql &
# Wait for MySQL with timeout
echo "Waiting for MySQL to be ready..."
# Wait for MariaDB with timeout
echo "Waiting for MariaDB to be ready..."
COUNTER=0
while ! mysqladmin ping -h localhost --silent; do
while ! mariadb-admin ping -h localhost --silent; do
if [ $COUNTER -gt $MAX_MYSQL_WAIT ]; then
echo "MySQL failed to start within $MAX_MYSQL_WAIT seconds"
echo "MariaDB failed to start within $MAX_MYSQL_WAIT seconds"
exit 1
fi
echo "Still waiting..."
sleep 2
COUNTER=$((COUNTER+2))
done
echo "MySQL is ready!"
echo "MariaDB is ready!"
# Run migrations with error handling
echo "Running database migrations..."
@ -61,8 +61,8 @@ while true; do
echo "Redis died"
exit 1
fi
if ! mysqladmin ping -h localhost --silent; then
echo "MySQL died"
if ! mariadb-admin ping -h localhost --silent; then
echo "MariaDB died"
exit 1
fi
if ! tmux has-session -t $APP_NAME 2>/dev/null; then