From 1f9a0fe543e3a83984373993ebe2db6d0c2d2a22 Mon Sep 17 00:00:00 2001 From: LightJack05 <66321084+LightJack05@users.noreply.github.com> Date: Thu, 15 Jan 2026 13:02:15 +0100 Subject: [PATCH] Added database import logic --- .dockerignore | 17 +++++++++++++++++ .gitignore | 1 + docker-compose.yaml | 22 ++++++++++++++++++++++ restore_db.sh | 4 ++++ 4 files changed, 44 insertions(+) create mode 100644 .dockerignore create mode 100755 restore_db.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b4342a3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +.git +.github +.gitignore + +flake.nix +flake.lock +Makefile +README.md + +*.exe +*.test +*.out +coverage.* +.env +data/ +data-clean/ +openfoodfacts-mongodbdump.gz diff --git a/.gitignore b/.gitignore index 470f8b2..896147c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ go.work.sum # .vscode/ data/ data-clean/ +openfoodfacts-mongodbdump.gz diff --git a/docker-compose.yaml b/docker-compose.yaml index a7b3be8..b57bee9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,13 +5,35 @@ services: - SERVICE_CONFIG_APP_NAME=SnackLog - SERVICE_CONFIG_API_ROOT_URL=localhost - SERVICE_CONFIG_SERVICE_NAME=database-api-wrapper + - MONGO_INITDB_ROOT_USERNAME=database_api_wrapper + - MONGO_INITDB_ROOT_PASSWORD=d812d430-de21-413d-9630-47ff5a5b3daa - GIN_MODE=debug build: . ports: - 8080:80 + depends_on: + mongodb: + condition: service_healthy healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:80/health || exit 1"] interval: 10s timeout: 5s retries: 5 + mongodb: + image: mongo:latest + environment: + MONGO_INITDB_ROOT_USERNAME: database_api_wrapper + MONGO_INITDB_ROOT_PASSWORD: d812d430-de21-413d-9630-47ff5a5b3daa + volumes: + - ./openfoodfacts-mongodbdump.gz:/openfoodfacts-mongodbdump.gz:ro + - ./restore_db.sh:/docker-entrypoint-initdb.d/restore.sh:ro + - ./data/mongo/:/data/db:rw + ports: + - "27017:27017" + healthcheck: + test: ["CMD-SHELL", "mongosh --quiet --username $$MONGO_INITDB_ROOT_USERNAME --password $$MONGO_INITDB_ROOT_PASSWORD --authenticationDatabase admin --eval \"db.adminCommand('ping')\""] + interval: 10s + timeout: 5s + retries: 5 + start_period: 120s diff --git a/restore_db.sh b/restore_db.sh new file mode 100755 index 0000000..b9c8d4a --- /dev/null +++ b/restore_db.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Restore from the mounted /dump folder +# We use the env vars provided in compose to authenticate +mongorestore --username "$MONGO_INITDB_ROOT_USERNAME" --password "$MONGO_INITDB_ROOT_PASSWORD" --authenticationDatabase admin --archive=openfoodfacts-mongodbdump.gz --gzip