1
0
forked from noxious/server

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 # Install dependencies with versions
RUN apk add --no-cache \ RUN apk add --no-cache \
redis \ redis \
mysql \ mariadb \
mysql-client \ mariadb-client \
tmux tmux
# Create non-root user # Create non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Setup MySQL # Setup MariaDB
RUN mkdir -p /run/mysqld && \ RUN mkdir -p /run/mysqld && \
chown -R mysql:mysql /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 WORKDIR /usr/src/app
COPY package*.json ./ COPY package*.json ./
@ -29,6 +29,6 @@ USER appuser
EXPOSE 80 6379 3306 EXPOSE 80 6379 3306
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ 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"] CMD ["./start.sh"]

View File

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