6576f28cc0
gates / gates (push) Successful in 25s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
102 lines
4.4 KiB
Plaintext
102 lines
4.4 KiB
Plaintext
# ghcr.io/seanmorley15/adventurelog-backend:v0.13.0 — entrypoint + cmd
|
|
ENTRYPOINT=["/code/entrypoint.sh"] CMD=["supervisord","-c","/etc/supervisor/conf.d/supervisord.conf"]
|
|
# /code/entrypoint.sh
|
|
7-wait_for_postgres
|
|
8-run_migrations
|
|
9-create_superuser_if_needed
|
|
10:run_download_countries
|
|
11-finalize_startup
|
|
12-
|
|
13-exec "$@"
|
|
# the management command
|
|
/code/worldtravel/management/commands/download-countries.py
|
|
/code/build_files.sh
|
|
/code/entrypoint.sh
|
|
|
|
/code/scripts:
|
|
entrypoint-common.sh
|
|
run-cron-job.sh
|
|
write-cron-env.sh
|
|
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
cd /code
|
|
source /code/scripts/entrypoint-common.sh
|
|
## /code/entrypoint.sh
|
|
## /code/scripts/entrypoint-common.sh
|
|
68:run_download_countries() {
|
|
69- if [[ "${SKIP_WORLD_DATA:-}" == "1" ]]; then
|
|
70- >&2 echo "SKIP_WORLD_DATA=1 — skipping download-countries"
|
|
71- return 0
|
|
72- fi
|
|
73-
|
|
74- >&2 echo "Running download-countries (first boot may take several minutes; ensure ~2GB RAM is available)..."
|
|
75- python manage.py download-countries
|
|
76- local download_exit=$?
|
|
77- if [[ "$download_exit" -eq 137 ]]; then
|
|
78- >&2 echo "WARNING: download-countries was interrupted (likely out of memory). Retry with more RAM or set SKIP_WORLD_DATA=1."
|
|
79- exit 1
|
|
80- elif [[ "$download_exit" -ne 0 ]]; then
|
|
81- >&2 echo "ERROR: download-countries failed."
|
|
82- exit 1
|
|
83- fi
|
|
84-}
|
|
85-
|
|
86-finalize_startup() {
|
|
87- if [[ -f /code/adventurelog.txt ]]; then
|
|
88- cat /code/adventurelog.txt
|
|
89- fi
|
|
90-
|
|
91- /code/scripts/write-cron-env.sh
|
|
92-}
|
|
# the command itself (options, cache, what it writes)
|
|
6:import ijson
|
|
17:COUNTRY_REGION_JSON_VERSION = settings.COUNTRY_REGION_JSON_VERSION
|
|
30: # Check if the flag already exists in storage
|
|
31: if default_storage.exists(flag_path):
|
|
32: print(f'Flag for {country_code} already exists')
|
|
45: def add_arguments(self, parser):
|
|
46: parser.add_argument('--force', action='store_true', help='Force download the countries+regions+states.json file')
|
|
47: parser.add_argument('--batch-size', type=int, default=500, help='Batch size for database operations')
|
|
92: force = options['force']
|
|
94: countries_json_path = f'countries+regions+states-{COUNTRY_REGION_JSON_VERSION}.json'
|
|
96: # Download or validate JSON file
|
|
97: if not default_storage.exists(countries_json_path) or force:
|
|
98: self.stdout.write('Downloading JSON file...')
|
|
99: if force and default_storage.exists(countries_json_path):
|
|
100: default_storage.delete(countries_json_path)
|
|
101: res = requests.get(f'https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/{COUNTRY_REGION_JSON_VERSION}/json/countries%2Bstates%2Bcities.json')
|
|
103: default_storage.save(countries_json_path, ContentFile(res.content))
|
|
104: self.stdout.write(self.style.SUCCESS('JSON file downloaded successfully'))
|
|
106: self.stdout.write(self.style.ERROR('Error downloading JSON file'))
|
|
108: elif default_storage.size(countries_json_path) == 0:
|
|
109: self.stdout.write(self.style.ERROR('JSON file is empty'))
|
|
121: self.stdout.write('Step 1: Parsing JSON and storing in temporary database...')
|
|
122: self._parse_and_store_temp(countries_json_path, temp_conn)
|
|
138: def _parse_and_store_temp(self, json_path, temp_conn):
|
|
139: """Parse JSON once and store in temporary SQLite database"""
|
|
144: with default_storage.open(json_path, 'rb') as f:
|
|
145: parser = ijson.items(f, 'item')
|
|
# v0.12.1: 398:COUNTRY_REGION_JSON_VERSION = 'v3.1'
|
|
/code/entrypoint.sh:0
|
|
# v0.13.0: 470:COUNTRY_REGION_JSON_VERSION = 'v3.1'
|
|
/code/scripts/entrypoint-common.sh:3 /code/entrypoint.sh:0
|
|
# where the JSON is stored (default_storage root)
|
|
216:MEDIA_ROOT = BASE_DIR / 'media' # Must match NGINX root for media serving
|
|
227:STORAGES = {
|
|
237: STORAGES["default"] = {
|
|
# v0.12.1 entrypoint: download-countries?
|
|
77-# Sync the countries and world travel regions
|
|
78-# Sync the countries and world travel regions
|
|
79:python manage.py download-countries
|
|
80-if [ $? -eq 137 ]; then
|
|
81: >&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."
|
|
82- exit 1
|
|
83-fi
|
|
84-
|
|
85-cat /code/adventurelog.txt
|
|
86-
|
|
87-exec "$@"
|
|
# v0.12.1 command: same cache check?
|
|
93: countries_json_path = os.path.join(settings.MEDIA_ROOT, f'countries+regions+states-{COUNTRY_REGION_JSON_VERSION}.json')
|