mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 05:05:17 +02:00
Merge 1088673f1c
into 2412754350
This commit is contained in:
commit
cef8003314
5 changed files with 122 additions and 5 deletions
21
.devcontainer/.env
Normal file
21
.devcontainer/.env
Normal file
|
@ -0,0 +1,21 @@
|
|||
PUBLIC_SERVER_URL='http://127.0.0.1:8000'
|
||||
ORIGIN='http://127.0.0.1:5173'
|
||||
__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS='127.0.0.1'
|
||||
BODY_SIZE_LIMIT=Infinity
|
||||
POSTGRES_DB=database
|
||||
POSTGRES_USER=adventure
|
||||
POSTGRES_PASSWORD=changeme123
|
||||
PGHOST=localhost
|
||||
PGDATABASE=database
|
||||
PGUSER=adventure
|
||||
PGPASSWORD=changeme123
|
||||
SECRET_KEY=changeme123
|
||||
DJANGO_ADMIN_USERNAME=admin
|
||||
DJANGO_ADMIN_PASSWORD=admin
|
||||
DJANGO_ADMIN_EMAIL='admin@example.com'
|
||||
PUBLIC_URL='http://127.0.0.1:8000'
|
||||
CSRF_TRUSTED_ORIGINS='http://127.0.0.1:8000,http://127.0.0.1:5173'
|
||||
DEBUG=True
|
||||
FRONTEND_URL='http://127.0.0.1:5173'
|
||||
EMAIL_BACKEND=console
|
||||
SECRET_KEY='pleasechangethisbecauseifyoudontitwillbeverybadandyouwillgethackedinlessthanaminuteguaranteed'
|
|
@ -8,19 +8,28 @@
|
|||
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
||||
"ghcr.io/devcontainers/features/node:1": {},
|
||||
"ghcr.io/devcontainers/features/python:1": {}
|
||||
}
|
||||
},
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
// "features": {},
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
"forwardPorts": [5173,8000],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "uname -a",
|
||||
"postCreateCommand": "./.devcontainer/postcreate.sh",
|
||||
|
||||
"postStartCommand": "./.devcontainer/poststart.sh",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"svelte.svelte-vscode",
|
||||
"Lokalise.i18n-ally"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
|
|
11
.devcontainer/postcreate.sh
Executable file
11
.devcontainer/postcreate.sh
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Install dependencies for backend and poststart.sh
|
||||
sudo apt update && sudo apt install -y python3-gdal postgresql-client
|
||||
pip install -r ./backend/server/requirements.txt
|
||||
cd ./backend/server
|
||||
# Create static files on backend
|
||||
python manage.py collectstatic --noinput
|
||||
cd ../../frontend
|
||||
# Install frontend dependencies
|
||||
npm install
|
71
.devcontainer/poststart.sh
Executable file
71
.devcontainer/poststart.sh
Executable file
|
@ -0,0 +1,71 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -a # Make sure to export vars to the whole environment
|
||||
source ./.devcontainer/.env
|
||||
set +a
|
||||
|
||||
# Run PostGIS with "docker in docker" on port 5432
|
||||
docker run --rm --name adventurelog-devdb -e POSTGRES_USER -e POSTGRES_PASSWORD -e POSTGRES_DB -p 5432:5432 -d postgis/postgis:15-3.3
|
||||
|
||||
cd ./backend/server
|
||||
|
||||
# Function to check PostgreSQL availability
|
||||
check_postgres() {
|
||||
psql -c '\q' >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Wait for PostgreSQL to become available
|
||||
until check_postgres; do
|
||||
>&2 echo "PostgreSQL is unavailable - sleeping"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
>&2 echo "PostgreSQL is up - continuing..."
|
||||
|
||||
# Apply Django migrations
|
||||
python manage.py migrate
|
||||
|
||||
# Create superuser if environment variables are set and there are no users present at all.
|
||||
if [ -n "$DJANGO_ADMIN_USERNAME" ] && [ -n "$DJANGO_ADMIN_PASSWORD" ] && [ -n "$DJANGO_ADMIN_EMAIL" ]; then
|
||||
echo "Creating superuser..."
|
||||
python manage.py shell << EOF
|
||||
from django.contrib.auth import get_user_model
|
||||
from allauth.account.models import EmailAddress
|
||||
User = get_user_model()
|
||||
# Check if the user already exists
|
||||
if not User.objects.filter(username='$DJANGO_ADMIN_USERNAME').exists():
|
||||
# Create the superuser
|
||||
superuser = User.objects.create_superuser(
|
||||
username='$DJANGO_ADMIN_USERNAME',
|
||||
email='$DJANGO_ADMIN_EMAIL',
|
||||
password='$DJANGO_ADMIN_PASSWORD'
|
||||
)
|
||||
print("Superuser created successfully.")
|
||||
# Create the EmailAddress object for AllAuth
|
||||
EmailAddress.objects.create(
|
||||
user=superuser,
|
||||
email='$DJANGO_ADMIN_EMAIL',
|
||||
verified=True,
|
||||
primary=True
|
||||
)
|
||||
print("EmailAddress object created successfully for AllAuth.")
|
||||
else:
|
||||
print("Superuser already exists.")
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Sync the countries and world travel regions
|
||||
mkdir media
|
||||
python manage.py download-countries
|
||||
if [ $? -eq 137 ]; then
|
||||
>&2 echo "WARNING: The download-countries command was interrupted. This is likely due to lack of memory allocated to the container or the host. Please try again with more memory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run backend in dev mode
|
||||
nohup $SHELL -c "python manage.py runserver 2>&1 | tee -a /tmp/servers.log >> /tmp/backend.log" > /dev/null &
|
||||
|
||||
cd ../../frontend
|
||||
|
||||
# Run frontend in dev mode
|
||||
nohup $SHELL -c "npm run dev 2>&1 | tee -a /tmp/servers.log >> /tmp/frontend.log" > /dev/null &
|
|
@ -9,5 +9,10 @@ export default defineConfig({
|
|||
Icons({
|
||||
compiler: 'svelte'
|
||||
})
|
||||
]
|
||||
],
|
||||
server: {
|
||||
watch: {
|
||||
usePolling: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue