Skip to content

Commit

Permalink
Load mysql data via persistent data volume
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed May 10, 2024
1 parent 6212cc2 commit 954ab5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ docker-cache-new/

# Ignore the version.json as this should be created during the build
version.json

# Ignore db backup files
backup-olympia.*.sql
5 changes: 4 additions & 1 deletion Makefile-docker
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ initialize_db: ## create a new database
$(PYTHON_COMMAND) manage.py migrate --noinput
$(PYTHON_COMMAND) manage.py loaddata initial.json
$(PYTHON_COMMAND) manage.py import_prod_versions
$(PYTHON_COMMAND) manage.py createsuperuser
$(PYTHON_COMMAND) manage.py createsuperuser \
--no-input \
--username "$(SUPERUSER_USERNAME)" \
--email $(SUPERUSER_EMAIL)
$(PYTHON_COMMAND) manage.py loaddata zadmin/users

.PHONY: populate_data
Expand Down
22 changes: 21 additions & 1 deletion Makefile-os
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ VERSION_BUILD_URL ?= build
# Exporting these variables make them default values for docker-compose*.yml files
export DOCKER_VERSION ?= local

EXPORT_FILE ?= backup-olympia.$(shell date +%Y%m%d%H%M%S).sql
# define the username and email for the superuser in the container
SUPERUSER_EMAIL=$(shell git config user.email)
SUPERUSER_USERNAME=$(shell git config user.name)

.PHONY: help_redirect
help_redirect:
@$(MAKE) help --no-print-directory
Expand Down Expand Up @@ -41,7 +46,22 @@ rootshell: ## connect to a running addons-server docker shell with root user

.PHONY: create_env_file
create_env_file:
echo "HOST_UID=${HOST_UID}" > .env
@ rm -f .env
echo "HOST_UID=${HOST_UID}" >> .env
echo "SUPERUSER_EMAIL=${SUPERUSER_EMAIL}" >> .env
echo "SUPERUSER_USERNAME=${SUPERUSER_USERNAME}" >> .env

.PHONY: db_export
db_export:
@echo "Exporting database to $(EXPORT_FILE)"
docker compose exec mysqld /usr/bin/mysqldump olympia > $(EXPORT_FILE)

.PHONY: db_restore
db_restore:
@if [ ! -f "$(RESTORE_FILE)" ]; then echo "File $(RESTORE_FILE) does not exist"; exit 1; fi
@echo "Restoring database from $(RESTORE_FILE)"
cat $(RESTORE_FILE) | docker compose exec -T mysqld /usr/bin/mysql olympia
rm $(RESTORE_FILE)

.PHONY: create_docker_builder
create_docker_builder: ## Create a custom builder for buildkit to efficiently build local images
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ x-env-mapping: &env
# it exists. ./docker/entrypoint.sh uses this variable to fix
# the uid of the olympia user to match the host user id if necessary.
- HOST_UID=${HOST_UID:-}
# This is the email address of the superuser created when initializing the db
- SUPERUSER_EMAIL=${SUPERUSER_EMAIL:-admin@mozilla.com}
- SUPERUSER_USERNAME=${SUPERUSER_USERNAME:-admin}

services:
worker: &worker
Expand Down Expand Up @@ -89,6 +92,8 @@ services:
- MYSQL_DATABASE=olympia
ports:
- "3306:3306"
volumes:
- data:/var/lib/mysql

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.3
Expand Down Expand Up @@ -144,3 +149,6 @@ services:

networks:
default:

volumes:
data:

0 comments on commit 954ab5e

Please sign in to comment.