feat: add mongo dump script, require ci checks before deployment (#89)

feat: add mongo dump script, require ci checks before deployment
This commit is contained in:
Lin, Hung-Shin authored and GitHub committed 2023-12-10 08:58:02 +08:00
commit 1bca61da40
4 files changed
+37 -3

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
secrets: inherit
build:
# needs: ci-checks
needs: ci-checks
uses: ./.github/workflows/build.yml
secrets: inherit
+1 -1
View File
@@ -25,7 +25,7 @@ jobs:
uses: mattzcarey/code-review-gpt@v0.1.4-alpha
with:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
MODEL: 'gpt-4'
MODEL: 'gpt-3.5-turbo'
GITHUB_TOKEN: ${{ github.token }}
build:
+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
secrets: inherit
build:
# needs: ci-checks
needs: ci-checks
uses: ./.github/workflows/build.yml
secrets: inherit
+34
View File
@@ -29,4 +29,38 @@ down() {
docker compose -f docker-compose.testing.yml down
}
dump() {
# Define service name and dump directory name
SERVICE_NAME="db"
DUMP_NAME="mongodump-$(date --iso).archive"
CONTAINER_ID=$(docker compose ps -q $SERVICE_NAME)
# Fetch credentials from Docker environment variables
MONGO_URL=$(docker compose exec -T backend printenv MONGO_URL)
echo mongo uri: $MONGO_URL
# Dump MongoDB data using credentials
docker compose exec -T $SERVICE_NAME sh -c "mongodump --gzip --archive=/tmp/$DUMP_NAME -d odyssey-test" &&
# Copy the dump from the container to the host
# Note: You will need to know the exact container name for this step
docker cp ${CONTAINER_ID}:/tmp/$DUMP_NAME . &&
echo "MongoDB data dumped successfully."
}
restore() {
# Define service name and dump directory name
SERVICE_NAME="db"
DUMP_NAME=$1
CONTAINER_ID=$(docker compose ps -q $SERVICE_NAME)
# Copy the dump from the host to the container
docker cp $DUMP_NAME ${CONTAINER_ID}:/tmp &&
# Dump MongoDB data using credentials
docker compose exec -T $SERVICE_NAME sh -c "mongorestore --gzip --archive=/tmp/$DUMP_NAME" &&
echo "MongoDB data dumped successfully."
}
$@