Small refactor of scripts, Dockerfile, and docker-compose to support load balancing, and mutiple replicas. Various fixes related to playwright installation in container environment, static file handling, and etc.
This commit is contained in:
parent
9b3b3d099f
commit
2dba19a77e
12 changed files with 109 additions and 127 deletions
5
scripts/deploy.sh
Executable file
5
scripts/deploy.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
django-admin makemigrations --noinput --check && django-admin migrate --noinput
|
||||
django-admin clear_cache
|
||||
django-admin collectstatic -c --no-input
|
||||
|
|
@ -1,23 +1,21 @@
|
|||
#!/bin/bash
|
||||
# Make the script exit when a command fails.
|
||||
set -e
|
||||
set -exc
|
||||
|
||||
# Define a cleanup function to handle CTRL-C (SIGINT)
|
||||
cleanup() {
|
||||
echo "CTRL-C caught! Shutting down Docker Compose services..."
|
||||
docker compose -f docker-compose_db_only.yml down
|
||||
exit 1
|
||||
}
|
||||
# check if the startup command has been provided
|
||||
if [ "$1" == "" ]; then
|
||||
echo "Startup command not set. Exiting"
|
||||
exit;
|
||||
fi
|
||||
|
||||
# Set trap to call cleanup() when SIGINT (Ctrl-C) is received.
|
||||
trap cleanup SIGINT
|
||||
# check if the $DJANGO_SETTINGS_MODULE environment variable has been set
|
||||
if [ "$DJANGO_SETTINGS_MODULE" == "" ]; then
|
||||
echo "Environment variable 'DJANGO_SETTINGS_MODULE' not set. Exiting."
|
||||
exit;
|
||||
else
|
||||
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
|
||||
fi
|
||||
|
||||
# Restart compose services.
|
||||
echo "Restarting compose services..."
|
||||
docker compose -f docker-compose_db_only.yml down
|
||||
docker compose -f docker-compose_db_only.yml up -d
|
||||
/deploy.sh
|
||||
|
||||
cd theme/static_src
|
||||
uv run npm run dev &
|
||||
cd ../../
|
||||
uv run python manage.py runserver
|
||||
echo "Enviroment is correct and deploy.sh has been run - executing command: '$@'"
|
||||
exec "$@" && exit 0
|
||||
12
scripts/prebuild.sh
Executable file
12
scripts/prebuild.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Remove all files in staticfiles except .gitkeep
|
||||
if [ -d "staticfiles" ]; then
|
||||
find staticfiles -type f ! -name '.gitkeep' -delete
|
||||
find staticfiles -type d -empty -delete
|
||||
fi
|
||||
|
||||
# Build the tailwind theme css
|
||||
cd theme/static_src
|
||||
npm install . && npm run build
|
||||
cd ../../
|
||||
9
scripts/rebuild-and-run.sh
Executable file
9
scripts/rebuild-and-run.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
docker compose down
|
||||
|
||||
# run prebuild tasks
|
||||
./scripts/prebuild.sh
|
||||
|
||||
# Build the docker image
|
||||
docker compose build && docker compose up -d
|
||||
|
|
@ -4,31 +4,16 @@ set -e
|
|||
|
||||
# Reset the database and migrations.
|
||||
echo "Resetting database and migrations... "
|
||||
docker compose -f docker-compose_db_only.yml down \
|
||||
&& docker compose -f docker-compose_entire_app.yml down \
|
||||
docker compose down \
|
||||
&& docker volume prune -a --filter label=db_is_resettable_via_script \
|
||||
&& find . -path "*/migrations/00*.py" -delete \
|
||||
&& docker compose -f docker-compose_db_only.yml up -d
|
||||
&& docker compose up -d
|
||||
|
||||
# Wait for the database to be ready.
|
||||
echo "Waiting for the database to be ready..."
|
||||
sleep 10
|
||||
|
||||
echo "Resetting static files..."
|
||||
uv run python manage.py collectstatic -c --no-input
|
||||
|
||||
echo "Running makemigrations..."
|
||||
uv run python manage.py makemigrations
|
||||
|
||||
echo "Running migrations..."
|
||||
uv run python manage.py migrate
|
||||
|
||||
echo "Loading seed data..."
|
||||
uv run python manage.py loaddata seed/0*
|
||||
docker compose exec -it web env DJANGO_SETTINGS_MODULE=django_project.settings django-admin loaddata /code/seed/0*
|
||||
|
||||
echo "Running deploy script..."
|
||||
./deploy.sh
|
||||
|
||||
docker compose -f docker-compose_db_only.yml down
|
||||
|
||||
echo "Done!"
|
||||
echo "Done & Started!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue