diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..b786f37e7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,162 @@ +FROM node:14.21.3 AS frontend-build + +ENV LOG_LEVEL="info" + +RUN apt update && \ + apt install -y git build-essential python3 python3-pip make g++ && \ + apt autoremove -y && \ + apt clean + +WORKDIR /app/frontend + +COPY ./frontend/package*.json /app/frontend/ + +RUN npm install + +COPY ./frontend /app/frontend/ + +RUN npm run build + +FROM python:3.7-slim AS backend-build + +# Envars +ENV ENVIRONMENT="local" +ENV APP_CONTEXT_ROOT=gwells +ENV CSRF_COOKIE_SECURE="False" +ENV CUSTOM_GDAL_GEOS="False" +ENV DATABASE_NAME=gwells +ENV DATABASE_USER="gwells" +ENV DATABASE_PASSWORD="test1" +ENV DATABASE_SERVICE_NAME=gwells +ENV DJANGO_ADMIN_URL=admin +ENV DJANGO_DEBUG="true" +ENV DJANGO_SECRET_KEY=secret +ENV ENABLE_ADDITIONAL_DOCUMENTS="true" +ENV ENABLE_AQUIFERS_SEARCH="true" +ENV GWELLS_SERVICE_HOST="db" +ENV GWELLS_SERVICE_PORT="5432" +ENV MINIO_ACCESS_KEY=minio +ENV MINIO_SECRET_KEY=minio1234 +ENV PYTHONUNBUFFERED="1" +ENV SESSION_COOKIE_SECURE="False" +ENV SSO_AUDIENCE=gwells-4121 +ENV SSO_CLIENT=gwells-4121 +ENV SSO_TEST_AUDIENCE=gwells-api-tests-4820 +ENV SSO_TEST_CLIENT=gwells-api-tests-4820 +ENV SSO_AUTH_HOST=https://test.loginproxy.gov.bc.ca/auth +ENV SSO_IDP_HINT="undefined" +ENV SSO_PORT=0 +ENV SSO_REALM=standard +ENV SSO_PUBKEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiFdv9GA83uHuy8Eu9yiZHGGF9j6J8t7FkbcpaN81GDjwbjsIJ0OJO9dKRAx6BAtTC4ubJTBJMPvQER5ikOhIeBi4o25fg61jpgsU6oRZHkCXc9gX6mrjMjbsPaf3/bjjYxP5jicBDJQeD1oRa24+tiGggoQ7k6gDEN+cRYqqNpzC/GQbkUPk8YsgroncEgu8ChMh/3ERsLV2zorchMANUq76max16mHrhtWIQxrb/STpSt4JuSlUzzBV/dcXjJe5gywZHe0jAutFhNqjHzHdgyaC4RAd3eYQo+Kl/JOgy2AZrnx+CiPmvOJKe9tAW4k4H087ng8aVE40v4HW/FEbnwIDAQAB +ENV S3_HOST=minio-public:9000 +ENV S3_PRIVATE_HOST=minio-private:9001 +ENV S3_PRIVATE_BUCKET=gwells +ENV S3_PRIVATE_ROOT_BUCKET=gwells +ENV S3_PRIVATE_WELL_BUCKET=well-docs +ENV S3_PRIVATE_AQUIFER_BUCKET=aquifer-docs +ENV S3_PRIVATE_REGISTRANT_BUCKET=driller-docs +ENV S3_PUBLIC_ACCESS_KEY=minio +ENV S3_PUBLIC_SECRET_KEY=minio1234 +ENV S3_AQUIFER_BUCKET=aquifer-docs +ENV S3_REGISTRANT_BUCKET=driller-docs +ENV S3_ROOT_BUCKET=gwells +ENV S3_WELL_BUCKET=well-docs +ENV S3_WELL_EXPORT_BUCKET=gwells +ENV S3_USE_SECURE=0 +ENV EMAIL_NOTIFICATION_RECIPIENT=sustainment.team@gov.bc.ca +ENV GEOCODER_ADDRESS_API_BASE=https://geocoder.api.gov.bc.ca/addresses.json? +ENV LOCAL="true" +ENV LOAD_FIXTURES="true" +ENV GDAL_LIBRARY_PATH="/usr/local/lib/libgdal.so" + +# Install dependencies +RUN apt -y update && apt -y install git build-essential gdal-bin libgdal-dev + +ENV PATH="/usr/bin/python3:${PATH}" + +WORKDIR /app/backend + +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install ptvsd +RUN python3 -m pip install 'setuptools<58.0' + +COPY ./backend/ . +COPY ./backend/requirements.txt . + +# # RUN chmod +x load_fixtures.sh works when i pull the dockerfile into backend but not when dockerfile is with other docker files +RUN chmod +x /app + +# # RUN python3 -m pip install -r requirements.txt + +RUN python3 -m pip install -r requirements.txt + +FROM python:3.7-slim AS production + +# # Envars +ENV ENVIRONMENT="local" +ENV APP_CONTEXT_ROOT=gwells +ENV CSRF_COOKIE_SECURE="False" +ENV CUSTOM_GDAL_GEOS="False" +ENV DATABASE_NAME=gwells +ENV DATABASE_USER="gwells" +ENV DATABASE_PASSWORD="test1" +ENV DATABASE_SERVICE_NAME=gwells +ENV DJANGO_ADMIN_URL=admin +ENV DJANGO_DEBUG="true" +ENV DJANGO_SECRET_KEY=secret +ENV ENABLE_ADDITIONAL_DOCUMENTS="true" +ENV ENABLE_AQUIFERS_SEARCH="true" +ENV GWELLS_SERVICE_HOST="db" +ENV GWELLS_SERVICE_PORT="5432" +ENV MINIO_ACCESS_KEY=minio +ENV MINIO_SECRET_KEY=minio1234 +ENV PYTHONUNBUFFERED="1" +ENV SESSION_COOKIE_SECURE="False" +ENV SSO_AUDIENCE=gwells-4121 +ENV SSO_CLIENT=gwells-4121 +ENV SSO_TEST_AUDIENCE=gwells-api-tests-4820 +ENV SSO_TEST_CLIENT=gwells-api-tests-4820 +ENV SSO_AUTH_HOST=https://test.loginproxy.gov.bc.ca/auth +ENV SSO_IDP_HINT="undefined" +ENV SSO_PORT=0 +ENV SSO_REALM=standard +ENV SSO_PUBKEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiFdv9GA83uHuy8Eu9yiZHGGF9j6J8t7FkbcpaN81GDjwbjsIJ0OJO9dKRAx6BAtTC4ubJTBJMPvQER5ikOhIeBi4o25fg61jpgsU6oRZHkCXc9gX6mrjMjbsPaf3/bjjYxP5jicBDJQeD1oRa24+tiGggoQ7k6gDEN+cRYqqNpzC/GQbkUPk8YsgroncEgu8ChMh/3ERsLV2zorchMANUq76max16mHrhtWIQxrb/STpSt4JuSlUzzBV/dcXjJe5gywZHe0jAutFhNqjHzHdgyaC4RAd3eYQo+Kl/JOgy2AZrnx+CiPmvOJKe9tAW4k4H087ng8aVE40v4HW/FEbnwIDAQAB +ENV S3_HOST=minio-public:9000 +ENV S3_PRIVATE_HOST=minio-private:9001 +ENV S3_PRIVATE_BUCKET=gwells +ENV S3_PRIVATE_ROOT_BUCKET=gwells +ENV S3_PRIVATE_WELL_BUCKET=well-docs +ENV S3_PRIVATE_AQUIFER_BUCKET=aquifer-docs +ENV S3_PRIVATE_REGISTRANT_BUCKET=driller-docs +ENV S3_PUBLIC_ACCESS_KEY=minio +ENV S3_PUBLIC_SECRET_KEY=minio1234 +ENV S3_AQUIFER_BUCKET=aquifer-docs +ENV S3_REGISTRANT_BUCKET=driller-docs +ENV S3_ROOT_BUCKET=gwells +ENV S3_WELL_BUCKET=well-docs +ENV S3_WELL_EXPORT_BUCKET=gwells +ENV S3_USE_SECURE=0 +ENV EMAIL_NOTIFICATION_RECIPIENT=sustainment.team@gov.bc.ca +ENV GEOCODER_ADDRESS_API_BASE=https://geocoder.api.gov.bc.ca/addresses.json? +ENV LOCAL="true" +ENV LOAD_FIXTURES="true" +ENV GDAL_LIBRARY_PATH="/usr/local/lib/libgdal.so" + +# Install dependencies +RUN apt -y update && apt -y install git build-essential gdal-bin libgdal-dev + +ENV PATH="/usr/bin/python3:${PATH}" + +COPY --from=backend-build . / + +COPY --from=frontend-build /app/frontend/dist/ app/backend/gwells/static +COPY --from=frontend-build /app/frontend/dist/index.html app/backend/gwells/templates/ + +WORKDIR /app/backend + +CMD sh -c "python3 manage.py migrate --noinput && \ + ./load_fixtures.sh all && \ + python3 manage.py createinitialrevisions && \ + python3 manage.py collectstatic --noinput && \ + # python3 manage.py export --cleanup=1 --upload=1 && \ + python3 manage.py runserver 0.0.0.0:8000" diff --git a/backend/Dockerfile b/backend/Dockerfile deleted file mode 100644 index e97ab29a9..000000000 --- a/backend/Dockerfile +++ /dev/null @@ -1,118 +0,0 @@ -FROM python:3.7-slim - -# Envars -ENV ENVIRONMENT="local" -ENV APP_CONTEXT_ROOT=gwells -ENV CSRF_COOKIE_SECURE="False" -ENV CUSTOM_GDAL_GEOS="False" -ENV DATABASE_NAME=gwells -ENV DATABASE_USER="gwells" -ENV DATABASE_PASSWORD="test1" -ENV DATABASE_SERVICE_NAME=gwells -ENV DJANGO_ADMIN_URL=admin -ENV DJANGO_DEBUG="true" -ENV DJANGO_SECRET_KEY=secret -ENV ENABLE_ADDITIONAL_DOCUMENTS="true" -ENV ENABLE_AQUIFERS_SEARCH="true" -ENV GWELLS_SERVICE_HOST="db" -ENV GWELLS_SERVICE_PORT="5432" -ENV MINIO_ACCESS_KEY=minio -ENV MINIO_SECRET_KEY=minio1234 -ENV PYTHONUNBUFFERED="1" -ENV SESSION_COOKIE_SECURE="False" -ENV SSO_AUDIENCE=gwells-4121 -ENV SSO_CLIENT=gwells-4121 -ENV SSO_TEST_AUDIENCE=gwells-api-tests-4820 -ENV SSO_TEST_CLIENT=gwells-api-tests-4820 -ENV SSO_AUTH_HOST=https://test.loginproxy.gov.bc.ca/auth -ENV SSO_IDP_HINT="undefined" -ENV SSO_PORT=0 -ENV SSO_REALM=standard -ENV SSO_PUBKEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiFdv9GA83uHuy8Eu9yiZHGGF9j6J8t7FkbcpaN81GDjwbjsIJ0OJO9dKRAx6BAtTC4ubJTBJMPvQER5ikOhIeBi4o25fg61jpgsU6oRZHkCXc9gX6mrjMjbsPaf3/bjjYxP5jicBDJQeD1oRa24+tiGggoQ7k6gDEN+cRYqqNpzC/GQbkUPk8YsgroncEgu8ChMh/3ERsLV2zorchMANUq76max16mHrhtWIQxrb/STpSt4JuSlUzzBV/dcXjJe5gywZHe0jAutFhNqjHzHdgyaC4RAd3eYQo+Kl/JOgy2AZrnx+CiPmvOJKe9tAW4k4H087ng8aVE40v4HW/FEbnwIDAQAB -ENV S3_HOST=minio-public:9000 -ENV S3_PRIVATE_HOST=minio-private:9001 -ENV S3_PRIVATE_BUCKET=gwells -ENV S3_PRIVATE_ROOT_BUCKET=gwells -ENV S3_PRIVATE_WELL_BUCKET=well-docs -ENV S3_PRIVATE_AQUIFER_BUCKET=aquifer-docs -ENV S3_PRIVATE_REGISTRANT_BUCKET=driller-docs -ENV S3_PUBLIC_ACCESS_KEY=minio -ENV S3_PUBLIC_SECRET_KEY=minio1234 -ENV S3_AQUIFER_BUCKET=aquifer-docs -ENV S3_REGISTRANT_BUCKET=driller-docs -ENV S3_ROOT_BUCKET=gwells -ENV S3_WELL_BUCKET=well-docs -ENV S3_WELL_EXPORT_BUCKET=gwells -ENV S3_USE_SECURE=0 -ENV EMAIL_NOTIFICATION_RECIPIENT=sustainment.team@gov.bc.ca -ENV GEOCODER_ADDRESS_API_BASE=https://geocoder.api.gov.bc.ca/addresses.json? -ENV LOCAL="true" -ENV LOAD_FIXTURES="true" - -# Install dependencies -RUN apt -y update && apt -y install git build-essential gdal-bin libgdal-dev - -ENV PATH="/usr/bin/python3:${PATH}" - -WORKDIR /app - -RUN python3 -m pip install --upgrade pip -RUN python3 -m pip install ptvsd -RUN python3 -m pip install 'setuptools<58.0' - -COPY . /app -# COPY ./backend-command-script.sh /backend-command-script.sh -COPY ./requirements.txt /requirements.txt - -# RUN chmod +x load_fixtures.sh works when i pull the dockerfile into backend but not when dockerfile is with other docker files -RUN chmod +x /app - -# RUN python3 -m pip install -r requirements.txt - -RUN python3 -m pip install -r requirements.txt - - -# TODO: move to entrypoint in deployment template? -# chmod -R 777 /app && \ -CMD sh -c "python3 manage.py migrate --noinput && \ - ./load_fixtures.sh all && \ - python3 manage.py createinitialrevisions && \ - # python3 manage.py collectstatic --noinput && \ - # python3 manage.py export --cleanup=1 --upload=1 && \ - python3 manage.py runserver 0.0.0.0:8000" - -# RUN mkdir -p /app/staticfiles/admin/css && \ -# ln -s /app/staticfiles /tmp/staticfiles && \ -# chmod -R 777 /app/staticfiles - -# make script executable -# RUN chmod +x /backend/backend-command-script.sh - -# production image step -# FROM python:3.7-slim - -# # TODO: need to confirm version of libgdal-dev used with FROM python version -# RUN apt-get -y update && \ -# apt-get -y install libgdal32 \ -# gdal-bin - -# ENV PATH="/usr/bin/python3:${PATH}" - -# WORKDIR /app - -# RUN python3 -m pip install 'setuptools<58.0' -# RUN python3 -m pip install --upgrade pip -# RUN python3 -m pip install ptvsd - -# COPY --from=build /app /app -# COPY --from=build /backend-command-script.sh /backend-command-script.sh -# COPY --from=build /requirements.txt /requirements.txt - -# RUN chmod +x /app - -# RUN python3 -m pip install -r requirements.txt - -# make script executable -# RUN chmod +x /backend/backend-command-script.sh - -# CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/backend/gwells/settings/__init__.py b/backend/gwells/settings/__init__.py index 61110eec4..acacda7cd 100644 --- a/backend/gwells/settings/__init__.py +++ b/backend/gwells/settings/__init__.py @@ -100,13 +100,13 @@ # Application definition INSTALLED_APPS = ( - # 'whitenoise.runserver_nostatic', + 'whitenoise.runserver_nostatic', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - # 'django.contrib.staticfiles', + 'django.contrib.staticfiles', 'debug_toolbar', 'django.contrib.postgres', 'rest_framework', @@ -129,7 +129,7 @@ MIDDLEWARE = ( 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', - # 'whitenoise.middleware.WhiteNoiseMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.middleware.gzip.GZipMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -198,17 +198,17 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ -# if APP_CONTEXT_ROOT: -# STATIC_URL = '/' + APP_CONTEXT_ROOT + '/' -# else: -# STATIC_URL = '/' +if APP_CONTEXT_ROOT: + STATIC_URL = '/' + APP_CONTEXT_ROOT + '/' +else: + STATIC_URL = '/' -# STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') -# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' -# STATICFILES_DIR = ( -# os.path.join(BASE_DIR, 'staticfiles') -# ) +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' +STATICFILES_DIR = ( + os.path.join(BASE_DIR, 'staticfiles') +) LOGGING = { 'version': 1, @@ -344,5 +344,5 @@ def __getitem__(self, item): if get_env_variable('DISABLE_MIGRATIONS', None, strict=False, warn=False) == 'DISABLE_MIGRATIONS': MIGRATION_MODULES = DisableMigrations() -# WHITENOISE_INDEX_FILE = True +WHITENOISE_INDEX_FILE = True APPEND_SLASH = True diff --git a/backend/requirements.txt b/backend/requirements.txt index 2c17b185f..3287a774c 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -12,7 +12,7 @@ django-crispy-forms==2.0 django-formtools==2.4.1 django-filter==23.5 requests==2.27.1 -# whitenoise==6.5.0 +whitenoise==6.5.0 django-cors-headers==4.1.0 django-extensions==3.2.3 django-rest-multiple-models==2.1.3 diff --git a/docker-compose.yml b/docker-compose.yml index 015c16ccf..bb8faae38 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,7 +51,7 @@ services: ### CrunchyDB ### ############################################################################################# db: - platform: linux/x86_64 + # platform: linux/x86_64 image: crunchydata/crunchy-postgres-gis:centos7-12.2-4.2.2 hostname: db environment: @@ -103,10 +103,9 @@ services: # timeout: 3s # retries: 10 # start_period: 5s - # test: psql -q -U $${POSTGRES_USER} -d $${POSTGRES_DB} -c 'SELECT 1' - # test: pg_isready -d $${{POSTGRES_DB}} -U $${{POSTGRES_USER}} - # test: ["CMD-SHELL", "/usr/pgsql-12/bin/pg_isready", "-d", "gwells"] - + # # test: psql -q -U $${POSTGRES_USER} -d $${POSTGRES_DB} -c 'SELECT 1' + # # test: pg_isready -d $${{POSTGRES_DB}} -U $${{POSTGRES_USER}} + # # test: ["CMD-SHELL", "/usr/pgsql-12/bin/pg_isready", "-d", "gwells"] ############################################################################################# ### Tileserv ### @@ -146,52 +145,54 @@ services: API_TARGET: "http://backend:8000/" BACKEND_URL: "http://backend:8000" LOG_LEVEL: "info" + MAPS_URL: python $manage_file collectstatic --noinput command: /bin/bash -c "cd /frontend && npm install && npm run serve" ports: - - "3000:8080" + - "8080:8080" volumes: - ./frontend:/frontend - /frontend/node_modules/ depends_on: backend: condition: service_started - tileserv: - condition: service_started - caddy: - container_name: caddy - profiles: ["caddy"] - build: ./frontend - environment: - NODE_ENV: development - PORT: 3000 - BACKEND_URL: http://backend:8000 - LOG_LEVEL: info - # VUE_APP_AXIOS_BASE_URL: "http://backend:8000/gwells/api/v2/" - # VUE_APP_VECTOR_TILE_BASE_URL: "/tiles/" - # VECTOR_TILE_SERVER: "http://tileserv:7800/" - # API_TARGET: "http://backend:8000/" - # LOG_LEVEL: "info" - ports: ["3005:3000"] - volumes: ["./frontend/Caddyfile:/etc/caddy/Caddyfile"] - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3005"] - interval: 5s - timeout: 3s - retries: 10 - start_period: 20s - depends_on: - backend: - condition: service_healthy + # caddy: + # container_name: caddy + # profiles: ["caddy"] + # build: ./frontend + # environment: + # NODE_ENV: development + # PORT: 3000 + # BACKEND_URL: http://backend:8000 + # LOG_LEVEL: info + # MAPS_URL: 'https://maps.gov.bc.ca' + # # VUE_APP_AXIOS_BASE_URL: "http://backend:8000/gwells/api/v2/" + # # VUE_APP_VECTOR_TILE_BASE_URL: "/tiles/" + # # VECTOR_TILE_SERVER: "http://tileserv:7800/" + # # API_TARGET: "http://backend:8000/" + # # LOG_LEVEL: "info" + # ports: ["3005:3000"] + # volumes: ["./frontend/Caddyfile:/etc/caddy/Caddyfile"] + # healthcheck: + # test: ["CMD", "curl", "-f", "http://localhost:3005"] + # interval: 5s + # timeout: 3s + # retries: 10 + # start_period: 20s + # depends_on: + # backend: + # condition: service_healthy + # tileserv: + # condition: service_healthy ############################################################################################# ### Backend ### ############################################################################################# backend: platform: linux/x86_64 - working_dir: /backend + working_dir: /app/backend build: - context: ./backend + context: ./ dockerfile: Dockerfile hostname: backend # env_file: @@ -255,11 +256,14 @@ services: start_period: 20s ports: - "8000:8000" + - "3000:3000" depends_on: db: condition: service_healthy minio-public: condition: service_started + tileserv: + condition: service_healthy ############################################################################################# ### PGAdmin ###