diff --git a/.dockerignore b/.dockerignore index 070ac1eb8..e18b26d77 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,32 @@ -db -docs -docker -.editorconfig -.env-sample -CONTRIBUTING.md -django -README.md -setup.md -docker-compose.yml -.github -.git -node -api/lightning/googleapis \ No newline at end of file +# This file reduces build context size and speeds up builds +# Leading slash (/) anchors patterns to the build context root +# Trailing slash (/) matches only directories +# Best practices: +# - Prefer anchored patterns over unanchored ones +# - List directories or nested paths first, then root-level files, then unanchored patterns +# - Keep the lists sorted in alphabetical order ignoring case + +# Directories and nested paths +/.git/ +/.github/ +/android/ +/api/lightning/googleapis/ +/collected_static/ +/desktopApp/ +/development/ +/docker/ +/docs/ +/node/ +/nodeapp/ +/tests/ + +# Root-level files +/.dockerignore +/.editorconfig +/.gitignore +/CONTRIBUTING.md +/docker-compose.yml +/README.md + +# Unanchored patterns +node_modules/ diff --git a/.gitignore b/.gitignore index 6227db435..2f506d6f7 100755 --- a/.gitignore +++ b/.gitignore @@ -649,6 +649,7 @@ node desktopApp/release-builds # frontend statics +collected_static frontend/templates/frontend/*.html frontend/*.html desktopApp/static diff --git a/Dockerfile b/Dockerfile index b3bdeebb8..fc8f4917c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,11 @@ COPY . . RUN sh scripts/generate_grpc.sh RUN chmod +x scripts/entrypoint.sh +RUN cp .env-sample .env \ + && python manage.py collectstatic --noinput --clear \ + && rm .env-sample .env \ + && find /usr/src/static -type f -exec gzip -9 --keep {} + + EXPOSE 8000 ENTRYPOINT [ "/usr/src/robosats/scripts/entrypoint.sh" ] diff --git a/docker-compose.yml b/docker-compose.yml index 63b8574ee..b90391285 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -64,8 +64,6 @@ services: pull_policy: never restart: always container_name: clord-dev - environment: - SKIP_COLLECT_STATIC: "true" command: python3 manage.py clean_orders volumes: - .:/usr/src/robosats @@ -81,8 +79,6 @@ services: depends_on: - bitcoind - lnd - environment: - SKIP_COLLECT_STATIC: "true" command: python3 manage.py follow_invoices volumes: - .:/usr/src/robosats @@ -95,8 +91,6 @@ services: pull_policy: never container_name: tg-dev restart: always - environment: - SKIP_COLLECT_STATIC: "true" command: python3 manage.py telegram_watcher volumes: - .:/usr/src/robosats @@ -111,7 +105,6 @@ services: restart: always environment: REDIS_URL: redis://localhost:6379 - SKIP_COLLECT_STATIC: "true" volumes: - .:/usr/src/robosats - ./node/lnd:/lnd @@ -128,7 +121,6 @@ services: restart: always environment: REDIS_URL: redis://localhost:6379 - SKIP_COLLECT_STATIC: "true" command: celery -A robosats beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler volumes: - .:/usr/src/robosats diff --git a/docker-tests.yml b/docker-tests.yml index 457735d1d..4dba64dbd 100644 --- a/docker-tests.yml +++ b/docker-tests.yml @@ -194,7 +194,6 @@ services: # BITCOIND_RPCURL: 'http://127.0.0.1:18443' # BITCOIND_RPCUSER: 'test' # BITCOIND_RPCPASSWORD: 'test' - # SKIP_COLLECT_STATIC: "true" # env_file: # - ${ROBOSATS_ENVS_FILE} # volumes: @@ -211,4 +210,4 @@ volumes: bitcoin: lnd: cln: - lndrobot: \ No newline at end of file + lndrobot: diff --git a/nodeapp/nginx.conf b/nodeapp/nginx.conf index 739e15565..81a1e1a20 100644 --- a/nodeapp/nginx.conf +++ b/nodeapp/nginx.conf @@ -92,4 +92,4 @@ http { } } -} \ No newline at end of file +} diff --git a/robosats/settings.py b/robosats/settings.py index ca467f982..ce8360d69 100644 --- a/robosats/settings.py +++ b/robosats/settings.py @@ -32,6 +32,7 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ +STATIC_ROOT = "/usr/src/static" STATIC_URL = "static/" # RoboSats version @@ -41,6 +42,7 @@ # SECURITY WARNING: don't run with debug turned on in production! if config("DEVELOPMENT", cast=bool, default=False): DEBUG = True + STATIC_ROOT = BASE_DIR / "collected_static" ALLOWED_HOSTS = [ config("HOST_NAME"), diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index ebb419f61..8c043a154 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -3,13 +3,6 @@ # Apply migrations python manage.py migrate -# Collect static files -if [ $SKIP_COLLECT_STATIC ]; then - echo "Skipping collection of static files." -else - python manage.py collectstatic --noinput -fi - # Collect static files if [ $DEVELOPMENT ]; then echo "Installing python development dependencies" @@ -26,4 +19,4 @@ fi cp -R /tmp/* /usr/src/robosats/api/lightning/ # Start server / gunicorn / daphne / command -exec "$@" \ No newline at end of file +exec "$@" diff --git a/scripts/traditional/templates/nginx.conf b/scripts/traditional/templates/nginx.conf index c85033c22..aa62e3719 100644 --- a/scripts/traditional/templates/nginx.conf +++ b/scripts/traditional/templates/nginx.conf @@ -24,6 +24,9 @@ http { types_hash_max_size 2048; server_tokens off; + gzip_static on; + gzip_proxied expired no-cache no-store private auth; + # nginx: [emerg] could not build map_hash, you should increase map_hash_bucket_size: 64 map_hash_bucket_size 4096; diff --git a/web/nginx.conf b/web/nginx.conf index 58413ce32..330c0f542 100644 --- a/web/nginx.conf +++ b/web/nginx.conf @@ -56,4 +56,4 @@ http { alias /usr/src/web/static/assets/images/favicon-96x96.png; } } -} \ No newline at end of file +}