Updating scripts, changing db dockerfile
This commit is contained in:
parent
8866703a9f
commit
eb130720b9
|
|
@ -1,12 +1,4 @@
|
||||||
# Use the same content as Dockerfile.stg.db, but for prod. If you want to customize, edit this file.
|
FROM mariadb:latest
|
||||||
# For now, copy the staging DB Dockerfile and adjust as needed for production.
|
|
||||||
FROM mysql:5.7
|
|
||||||
|
|
||||||
ENV MYSQL_ROOT_PASSWORD=secureRootPassword
|
COPY deploy/scripts/restore_db_from_backup.sh /docker-entrypoint-initdb.d/restore_db_from_backup.sh
|
||||||
ENV MYSQL_DATABASE=cmc
|
RUN chmod +x /docker-entrypoint-initdb.d/restore_db_from_backup.sh
|
||||||
ENV MYSQL_USER=cmc
|
|
||||||
ENV MYSQL_PASSWORD=xVRQI&cA?7AU=hqJ!%au
|
|
||||||
|
|
||||||
EXPOSE 3306
|
|
||||||
|
|
||||||
VOLUME ["/var/lib/mysql"]
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,37 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
# Default to staging
|
||||||
|
TARGET="stg"
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [[ "$arg" == "-target" ]]; then
|
||||||
|
NEXT_IS_TARGET=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ $NEXT_IS_TARGET == 1 ]]; then
|
||||||
|
TARGET="$arg"
|
||||||
|
NEXT_IS_TARGET=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$TARGET" == "prod" ]]; then
|
||||||
|
DB_CONTAINER="cmc-prod-db"
|
||||||
|
DB_USER="cmc"
|
||||||
|
DB_PASS="xVRQI&cA?7AU=hqJ!%au"
|
||||||
|
DB_NAME="cmc"
|
||||||
|
else
|
||||||
|
DB_CONTAINER="cmc-db"
|
||||||
|
DB_USER="cmc"
|
||||||
|
DB_PASS="xVRQI&cA?7AU=hqJ!%au"
|
||||||
|
DB_NAME="cmc"
|
||||||
|
fi
|
||||||
|
|
||||||
# Sync latest backup from production
|
# Sync latest backup from production
|
||||||
rsync -avz -e "ssh -i ~/.ssh/cmc-old" --progress cmc@sales.cmctechnologies.com.au:~/backups /home/cmc/
|
rsync -avz -e "ssh -i ~/.ssh/cmc-old" --progress cmc@sales.cmctechnologies.com.au:~/backups /home/cmc/
|
||||||
LATEST_BACKUP=$(ls -t /home/cmc/backups/backup_*.sql.gz | head -n1)
|
LATEST_BACKUP=$(ls -t /home/cmc/backups/backup_*.sql.gz | head -n1)
|
||||||
echo "Restoring database from latest backup: $LATEST_BACKUP"
|
echo "Restoring database from latest backup: $LATEST_BACKUP to $TARGET ($DB_CONTAINER)"
|
||||||
if [ -f "$LATEST_BACKUP" ]; then
|
if [ -f "$LATEST_BACKUP" ]; then
|
||||||
docker cp "$LATEST_BACKUP" cmc-db:/tmp/backup.sql.gz
|
docker cp "$LATEST_BACKUP" "$DB_CONTAINER":/tmp/backup.sql.gz
|
||||||
docker exec cmc-db sh -c "gunzip < /tmp/backup.sql.gz | mariadb -u cmc -p'xVRQI&cA?7AU=hqJ!%au' cmc"
|
docker exec "$DB_CONTAINER" sh -c "gunzip < /tmp/backup.sql.gz | mariadb -u $DB_USER -p'$DB_PASS' $DB_NAME"
|
||||||
echo "Database restore complete."
|
echo "Database restore complete."
|
||||||
else
|
else
|
||||||
echo "No backup file found in /home/cmc/backups. Skipping database restore."
|
echo "No backup file found in /home/cmc/backups. Skipping database restore."
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,31 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
SQL_DIR="/home/cmc/cmc-sales-staging/go-app/sql/schema"
|
# Default to staging
|
||||||
DB_USER="cmc"
|
TARGET="stg"
|
||||||
DB_PASS="xVRQI&cA?7AU=hqJ!%au"
|
for arg in "$@"; do
|
||||||
DB_NAME="cmc"
|
if [[ "$arg" == "-target" ]]; then
|
||||||
DB_HOST="127.0.0.1"
|
NEXT_IS_TARGET=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ $NEXT_IS_TARGET == 1 ]]; then
|
||||||
|
TARGET="$arg"
|
||||||
|
NEXT_IS_TARGET=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$TARGET" == "prod" ]]; then
|
||||||
|
DB_CONTAINER="cmc-prod-db"
|
||||||
|
DB_USER="cmc"
|
||||||
|
DB_PASS="xVRQI&cA?7AU=hqJ!%au"
|
||||||
|
DB_NAME="cmc"
|
||||||
|
SQL_DIR="/home/cmc/cmc-sales-prod/go-app/sql/schema"
|
||||||
|
else
|
||||||
|
DB_CONTAINER="cmc-db"
|
||||||
|
DB_USER="cmc"
|
||||||
|
DB_PASS="xVRQI&cA?7AU=hqJ!%au"
|
||||||
|
DB_NAME="cmc"
|
||||||
|
SQL_DIR="/home/cmc/cmc-sales-staging/go-app/sql/schema"
|
||||||
|
fi
|
||||||
|
|
||||||
for sqlfile in "$SQL_DIR"/*.sql; do
|
for sqlfile in "$SQL_DIR"/*.sql; do
|
||||||
# Skip files starting with ignore_
|
# Skip files starting with ignore_
|
||||||
|
|
@ -12,8 +33,8 @@ for sqlfile in "$SQL_DIR"/*.sql; do
|
||||||
echo "Skipping ignored migration: $sqlfile"
|
echo "Skipping ignored migration: $sqlfile"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
echo "Running migration: $sqlfile"
|
echo "Running migration: $sqlfile on $TARGET ($DB_CONTAINER)"
|
||||||
docker cp "$sqlfile" cmc-db:/tmp/migration.sql
|
docker cp "$sqlfile" "$DB_CONTAINER":/tmp/migration.sql
|
||||||
docker exec cmc-db sh -c "mariadb -u $DB_USER -p'$DB_PASS' $DB_NAME < /tmp/migration.sql"
|
docker exec "$DB_CONTAINER" sh -c "mariadb -u $DB_USER -p'$DB_PASS' $DB_NAME < /tmp/migration.sql"
|
||||||
done
|
done
|
||||||
echo "All migrations applied."
|
echo "All migrations applied."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue