From d258965a0fedac6468f7c8dcd0483b31b53dd8b8 Mon Sep 17 00:00:00 2001 From: sudan45 Date: Tue, 3 Sep 2024 10:53:31 +0545 Subject: [PATCH] Overide gh docker compose with docker compose services --- .github/workflows/ci.yml | 4 +++ docker-compose.yml | 2 +- gh-docker-compose.yml | 64 ++-------------------------------------- main/settings.py | 2 +- main/urls.py | 7 +++++ 5 files changed, 16 insertions(+), 63 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a2d3a0..1c5ad35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: - develop pull_request: +env: + COMPOSE_FILE: docker-compose.yml:gh-docker-compose.yml + jobs: test: name: 🚴 Test 🚴 @@ -48,6 +51,7 @@ jobs: - name: 🕮 Validate if there are no pending django migrations. env: + COMPOSE_FILE: ./docker-compose.yml:./gh-docker-compose.yml DOCKER_IMAGE_BACKEND: ${{ steps.prep.outputs.tagged_image }} run: | docker compose -f ./gh-docker-compose.yml run --rm web bash -c 'wait-for-it db:5432 && ./manage.py makemigrations --check --dry-run' || { diff --git a/docker-compose.yml b/docker-compose.yml index ea55a25..be762cd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,7 +30,7 @@ services: environment: DJANGO_DEBUG: ${DJANGO_DEBUG:-True} DJANGO_ALLOWED_HOST: ${DJANGO_ALLOWED_HOST:-localhost} - DJNAGO_SECRET_KEY: ${DJANGO_SECRET_KEY:- test} + DJNAGO_SECRET_KEY: ${DJANGO_SECRET_KEY} DATABASE_NAME: ${DATABASE_NAME:-chatbot} DATABASE_USER: ${DATABASE_USER:-postgres} DATABASE_PASSWORD: ${DATABASE_PASSWORD:-postgres} diff --git a/gh-docker-compose.yml b/gh-docker-compose.yml index 8c99b06..f4d84e9 100644 --- a/gh-docker-compose.yml +++ b/gh-docker-compose.yml @@ -1,66 +1,8 @@ services: - db: - image: postgres:16-alpine - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - volumes: - - postgres-data16:/var/lib/postgresql/data - - redis: - image: redis:6-alpine - volumes: - - redis-data:/data - - qdrant: - image: qdrant/qdrant:v1.11.3 - ports: - - "6333:6333" - volumes: - - qdrant_data:/qdrant/storage - web: image: $DOCKER_IMAGE_BACKEND - # To attach to container with stdin `docker attach ` - # Used for python debugging. - stdin_open: true - tty: true - extra_hosts: - - "host.docker.internal:host-gateway" + env_file: !reset null environment: - CI: "true" - APP_ENVIRONMENT: CI - APP_TYPE: web - DJANGO_DEBUG: "true" - DJANGO_SECRET_KEY: RANDOM_KEY - # -- Domain configurations - DJANGO_ALLOWED_HOSTS: "*" - APP_DOMAIN: localhost:8000 - APP_HTTP_PROTOCOL: http - APP_FRONTEND_HOST: http://localhost:3000 - SESSION_COOKIE_DOMAIN: localhost - CSRF_COOKIE_DOMAIN: localhost - # Database config - DATABASE_NAME: postgres - DATABASE_USER: postgres - DATABASE_PASSWORD: postgres - DATABASE_HOST: db - DATABASE_PORT: 5432 - # # Redis config - CELERY_REDIS_URL: ${CELERY_REDIS_URL:-redis://redis:6379/0} - DJANGO_CACHE_REDIS_URL: ${DJANGO_CACHE_REDIS_URL:-redis://redis:6379/1} - # Email config - EMAIL_FROM: ${EMAIL_FROM:-togglecorp-dev } - volumes: - - ./:/code - - ./ci-share/:/ci-share/ - # - ./coverage/:/code/coverage/ - depends_on: + DJANGO_SECRET_KEY: "test" + network: - db - - redis - -volumes: - postgres-data16: - redis-data: - qdrant_data: diff --git a/main/settings.py b/main/settings.py index fe70129..6db134f 100644 --- a/main/settings.py +++ b/main/settings.py @@ -25,9 +25,9 @@ DJANGO_ALLOWED_HOST=(list, ["*"]), DJANGO_STATIC_ROOT=(str, os.path.join(BASE_DIR, "assets/static")), # Where to store DJANGO_MEDIA_ROOT=(str, os.path.join(BASE_DIR, "assets/media")), # Where to store - DJANGO_TIME_ZONE=(str, "UTC"), DJANGO_STATIC_URL=(str, "/static/"), DJANGO_MEDIA_URL=(str, "/media/"), + DJANGO_TIME_ZONE=(str, "UTC"), # Database DATABASE_NAME=str, DATABASE_USER=str, diff --git a/main/urls.py b/main/urls.py index 2b954f2..bf803c8 100644 --- a/main/urls.py +++ b/main/urls.py @@ -15,9 +15,16 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings +from django.conf.urls.static import static from django.contrib import admin from django.urls import path urlpatterns = [ path("admin/", admin.site.urls), ] +if settings.DEBUG: + + # Static and media file URLs + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)