1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-18 20:39:36 +02:00

feat: Add CDN generation scripts and Docker setup; include Nginx configuration

This commit is contained in:
Sean Morley 2025-02-02 20:31:28 -05:00
parent 659c56f02d
commit dc169d1046
8 changed files with 117 additions and 0 deletions

View file

@ -144,6 +144,7 @@ Hi! I'm Sean, the creator of AdventureLog. I'm a college student and software de
- WorldTravel Dataset [dr5hn/countries-states-cities-database](https://github.com/dr5hn/countries-states-cities-database)
### Top Supporters 💖
- [Veymax](https://x.com/veymax)
- [nebriv](https://github.com/nebriv)
- [Victor Butler](https://x.com/victor_butler)

1
cdn/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
data/

33
cdn/Dockerfile Normal file
View file

@ -0,0 +1,33 @@
# Use an official Python image as a base
FROM python:3.11-slim
# Set the working directory
WORKDIR /app
# Install required Python packages
RUN pip install --no-cache-dir requests osm2geojson
# Copy the script and data folder into the container
COPY main.py /app/main.py
COPY data /app/data/
# Ensure the data folder exists
RUN mkdir -p /app/data
# Run the script to generate GeoJSON files
RUN python /app/main.py
# Install Nginx
RUN apt update && apt install -y nginx && rm -rf /var/lib/apt/lists/*
# Copy the entire data folder to the Nginx serving directory
RUN mkdir -p /var/www/html/data && cp -r /app/data/* /var/www/html/data/
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Expose port 80 for Nginx
EXPOSE 80
# Start Nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]

3
cdn/README.md Normal file
View file

@ -0,0 +1,3 @@
This folder contains the scripts to generate AdventureLOG CDN files.
Special thanks to [@larsl-net](https://github.com/larsl-net) for the GeoJSON generation script.

9
cdn/docker-compose.yml Normal file
View file

@ -0,0 +1,9 @@
services:
geojson:
build: .
container_name: adventurelog-cdn
ports:
- "8080:80"
restart: unless-stopped
volumes:
- ./data:/app/data # Ensures new data files persist

56
cdn/main.py Normal file
View file

@ -0,0 +1,56 @@
import requests
import json
import os
# https://github.com/dr5hn/countries-states-cities-database/tags
COUNTRY_REGION_JSON_VERSION = 'v2.5' # Should match the version stated in the settings.py file of AdventureLog
def downloadCountriesStateCities():
res = requests.get(f'https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/{COUNTRY_REGION_JSON_VERSION}/json/countries%2Bstates%2Bcities.json')
def downloadGeojson(iso_code=None, region_name=None):
"""
Download geojson data for a specific region using the Overpass API.
:param iso_code: ISO 3166-2 code for the region (e.g. "US-CT")
:param region_name: Name of the region (e.g. "Connecticut")
:return: Geojson data for the region
"""
base_url = "https://overpass-api.de/api/interpreter"
# Get the directory where the script is located
script_dir = os.path.dirname(__file__)
# Ensure the ./data directory exists
data_dir = os.path.join(script_dir, "data")
os.makedirs(data_dir, exist_ok=True)
# Set the path for the geojson file
geojson_path = os.path.join(data_dir, "geojson.json")
if iso_code:
query = f'[out:json];relation["boundary"="administrative"]["admin_level"="4"]["ISO3166-2"="{iso_code}"];out body;way(r);(._;>;);out geom;'
response = requests.post(base_url, data=query)
if response.ok and response.json().get("elements"):
data = response.json()
with open(geojson_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)
return data
if region_name:
query = f'[out:json];relation["boundary"="administrative"]["admin_level"="4"]["name"="{region_name}"];out body;way(r);(._;>;);out geom;'
response = requests.post(base_url, data=query)
if response.ok and response.json().get("elements"):
data = response.json()
with open(geojson_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)
return data
return None # No results found
# Example usage
data = downloadGeojson(iso_code="US-CT", region_name="Connecticut")
if data:
print(f"Region data found and saved to {os.path.join(os.path.dirname(__file__), 'data', 'geojson.json')}!")
else:
print("No region data found.")

13
cdn/nginx.conf Normal file
View file

@ -0,0 +1,13 @@
events {}
http {
server {
listen 80;
server_name _;
location /data/ {
root /var/www/html;
autoindex on; # Enable directory listing
}
}
}

1
cdn/requirements.txt Normal file
View file

@ -0,0 +1 @@
osm2geojson==0.2.5