diff --git a/.github/workflows/.deploy.yml b/.github/workflows/.deploy.yml index ad6b3c355..d71db8f7f 100644 --- a/.github/workflows/.deploy.yml +++ b/.github/workflows/.deploy.yml @@ -71,7 +71,7 @@ jobs: file: minio/openshift.deploy.yml parameters: -p ZONE=${{ inputs.target }} - -p IMAGE_TAG=${{ inputs.tag }} + -p TAG=${{ inputs.tag }} # ${{ inputs.environment && '' || '-p MINIO_DATA_DIR=/tmp/data' }} # ${{ inputs.environment && '' || '-p DEST_PVC_SIZE=1Mi' }} @@ -91,9 +91,9 @@ jobs: file: database/openshift.deploy.yml overwrite: true parameters: - -p IMAGE_STREAM_NAMESPACE=${{ vars.OC_NAMESPACE }} - -p IMAGE_STREAM_NAME=crunchy-postgres-gis - -p IMAGE_TAG=${{ inputs.tag }} + # -p IMAGE_STREAM_NAMESPACE=${{ vars.OC_NAMESPACE }} + # -p IMAGE_STREAM_NAME=crunchy-postgres-gis + -p TAG=${{ inputs.tag }} -p ZONE=${{ inputs.target }} -p STORAGE_CLASS=netapp-file-standard -p REQUEST_CPU=200m @@ -116,7 +116,7 @@ jobs: file: backend/openshift.deploy.yml parameters: -p ZONE=${{ inputs.target }} - -p IMAGE_TAG=${{ inputs.tag }} + -p TAG=${{ inputs.tag }} -p E_LICENSING_URL=${{ vars.E_LICENSING_URL }} -p DB_REPLICATE=${{ vars.DB_REPLICATE }} -p DJANGO_DEBUG=${{ vars.DJANGO_DEBUG }} @@ -145,21 +145,21 @@ jobs: -p EMAIL_NOTIFICATION_RECIPIENT=${{ vars.EMAIL_NOTIFICATION_RECIPIENT }} -p GEOCODER_ADDRESS_API_BASE=${{ vars.GEOCODER_ADDRESS_API_BASE }} - frontend: - name: Frontend - needs: [ init, database, backend ] - environment: ${{ inputs.environment }} - runs-on: ubuntu-latest - steps: - - name: Deploy Frontend - uses: bcgov-nr/action-deployer-openshift@v3.0.1 - with: - oc_namespace: ${{ vars.OC_NAMESPACE }} - oc_server: ${{ vars.OC_SERVER }} - oc_token: ${{ secrets.OC_TOKEN }} - oc_version: "4.14.37" - file: frontend/openshift.deploy.yml - parameters: - -p ZONE=${{ inputs.target }} - -p IMAGE_TAG=${{ inputs.tag }} + # frontend: + # name: Frontend + # needs: [ init, database, backend ] + # environment: ${{ inputs.environment }} + # runs-on: ubuntu-latest + # steps: + # - name: Deploy Frontend + # uses: bcgov-nr/action-deployer-openshift@v3.0.1 + # with: + # oc_namespace: ${{ vars.OC_NAMESPACE }} + # oc_server: ${{ vars.OC_SERVER }} + # oc_token: ${{ secrets.OC_TOKEN }} + # oc_version: "4.14.37" + # file: frontend/openshift.deploy.yml + # parameters: + # -p ZONE=${{ inputs.target }} + # -p TAG=${{ inputs.tag }} \ No newline at end of file diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index 82bbbe792..d23bc92b6 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -16,11 +16,17 @@ jobs: strategy: matrix: package: [database, backend, frontend, minio] + include: + - package: backend + build_context: ./ + build_file: ./backend/Dockerfile timeout-minutes: 20 steps: - uses: bcgov-nr/action-builder-ghcr@v2.2.0 with: keep_versions: 50 + build_context: ${{ matrix.build_context }} + build_file: ${{ matrix.build_file }} package: ${{ matrix.package }} tag: ${{ github.event.number }} tag_fallback: latest diff --git a/.gitignore b/.gitignore index 3e3560b6b..1f7a0e06c 100644 --- a/.gitignore +++ b/.gitignore @@ -361,3 +361,6 @@ poetry.toml pyrightconfig.json # End of https://www.toptal.com/developers/gitignore/api/node,java,python,go + +# Django static files +backend/staticfiles/ \ No newline at end of file diff --git a/backend/.envrc b/backend/.envrc index 7a44329b1..c6bcddba5 100644 --- a/backend/.envrc +++ b/backend/.envrc @@ -19,13 +19,13 @@ layout python3 # Set all required environment variables. export DJANGO_LOG_LEVEL=DEBUG -export DATABASE_SERVICE_NAME=localhost +# export DATABASE_SERVICE_NAME=localhost export LOCALHOST_SERVICE_HOST=localhost export BASEURL=http://127.0.0.1:8000/ export LOCALHOST_SERVICE_PORT=5432 -export DATABASE_NAME=gwells -export DATABASE_USER=gwells -export DATABASE_PASSWORD=gwells +# export DATABASE_NAME=gwells +# export DATABASE_USER=gwells +# export DATABASE_PASSWORD=gwells export DATABASE_SCHEMA=public export DJANGO_SECRET_KEY=blah export DJANGO_DEBUG=True diff --git a/backend/Dockerfile b/backend/Dockerfile index e97ab29a9..71907e0a7 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,56 +1,26 @@ -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" +FROM node:14.21.3 AS frontend + +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 + +COPY ./frontend/package*.json ./ + +RUN npm install + +COPY ./frontend/ /app + +RUN npm run build + +FROM python:3.7 # Install dependencies -RUN apt -y update && apt -y install git build-essential gdal-bin libgdal-dev +RUN apt -y update && apt -y install git build-essential gdal-bin libgdal-dev postgresql-client ENV PATH="/usr/bin/python3:${PATH}" @@ -60,59 +30,30 @@ 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 /app # COPY ./backend-command-script.sh /backend-command-script.sh -COPY ./requirements.txt /requirements.txt +COPY ./backend/requirements.txt /app/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 +COPY --from=frontend ./app/dist ./gwells/static +COPY --from=frontend ./app/dist/index.html ./gwells/templates/ +# COPY /backend/startup.sh /docker-entrypoint-initdb.d/ +# 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 -R +x /app +# RUN chmod -R 777 /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 [""] + CMD sh -c "python3 manage.py migrate --noinput && \ ./load_fixtures.sh all && \ python3 manage.py createinitialrevisions && \ - # python3 manage.py collectstatic --noinput && \ + 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"] +USER 1001 \ No newline at end of file diff --git a/backend/gwells/database.py b/backend/gwells/database.py index 3ec640911..7fdf056d5 100644 --- a/backend/gwells/database.py +++ b/backend/gwells/database.py @@ -12,19 +12,36 @@ limitations under the License. """ import os +import logging from django.conf import settings from gwells.settings.base import get_env_variable +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) def config(): service_name = get_env_variable('DATABASE_SERVICE_NAME', '').upper().replace('-', '_') name = get_env_variable('DATABASE_NAME') + + # logger.info(f'Django Database Config') + # logger.info(f'service_name: ', service_name[0]) + # logger.info(f'database_name: ', name[0]) + + # return { + # 'ENGINE': 'django.contrib.gis.db.backends.postgis', + # 'NAME': name, + # 'USER': get_env_variable('DATABASE_USER'), + # 'PASSWORD': get_env_variable('DATABASE_PASSWORD'), + # 'HOST': get_env_variable('{}_SERVICE_HOST'.format(service_name)), + # 'PORT': get_env_variable('{}_SERVICE_PORT'.format(service_name)), + # } + return { 'ENGINE': 'django.contrib.gis.db.backends.postgis', - 'NAME': name, - 'USER': get_env_variable('DATABASE_USER'), - 'PASSWORD': get_env_variable('DATABASE_PASSWORD'), - 'HOST': get_env_variable('{}_SERVICE_HOST'.format(service_name)), - 'PORT': get_env_variable('{}_SERVICE_PORT'.format(service_name)), + 'NAME': os.getenv('DATABASE_NAME'), + 'USER': os.getenv('DATABASE_USER'), + 'PASSWORD': os.getenv('DATABASE_PASSWORD'), + 'HOST': os.getenv('DATABASE_SERVICE_NAME'), + 'PORT': os.getenv('DATABASE_PORT') } diff --git a/backend/gwells/settings/__init__.py b/backend/gwells/settings/__init__.py index 61110eec4..1b32c3315 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', @@ -175,7 +175,14 @@ # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { - 'default': database.config() + 'default': { + 'ENGINE': 'django.contrib.gis.db.backends.postgis', + 'NAME': os.getenv('DATABASE_NAME'), + 'USER': os.getenv('DATABASE_USER'), + 'PASSWORD': os.getenv('DATABASE_PASSWORD'), + 'HOST': os.getenv('DATABASE_SERVICE_NAME'), + 'PORT': os.getenv('DATABASE_PORT') + } } # Re-use database connections, leave connection alive for 5 mimutes @@ -198,17 +205,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 +351,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/gwells/urls.py b/backend/gwells/urls.py index 19b4d7adf..3e93daf0a 100644 --- a/backend/gwells/urls.py +++ b/backend/gwells/urls.py @@ -24,7 +24,7 @@ from django.shortcuts import redirect from django.views.decorators.cache import never_cache -from gwells.views import SurveyListCreateView, SurveyUpdateDeleteView, HealthView, api +from gwells.views import SurveyListCreateView, SurveyUpdateDeleteView, HealthView, index, api from gwells.views.bulk import BulkWellAquiferCorrelation, BulkVerticalAquiferExtents from gwells.views.admin import * from gwells.settings.base import get_env_variable @@ -101,6 +101,6 @@ def api_path_prefix(): # Catch all other cases to api/ and 404 them re_path(r'' + app_root_slash + api_path_prefix() + '/*', api.api_404, name='api-404'), - # # Catch all other cases and push it to the SPA - # re_path(r'' + app_root_slash + '*', index, name='spa'), + # Catch all other cases and push it to the SPA + re_path(r'' + app_root_slash + '*', index, name='spa'), ] diff --git a/backend/gwells/views/__init__.py b/backend/gwells/views/__init__.py index df2ec269c..812aa7dee 100644 --- a/backend/gwells/views/__init__.py +++ b/backend/gwells/views/__init__.py @@ -103,8 +103,8 @@ def get_queryset(self): return super().get_queryset() -# @require_http_methods(["GET"]) -# def index(request, **kwargs): -# # Serve up the index.html generated by vue as a template. -# # This is not ideal, consider switching serving up of Vue.js entirely to caddy. -# return render(request, 'index.html') +@require_http_methods(["GET"]) +def index(request, **kwargs): + # Serve up the index.html generated by vue as a template. + # This is not ideal, consider switching serving up of Vue.js entirely to caddy. + return render(request, 'index.html') diff --git a/backend/openshift.deploy.yml b/backend/openshift.deploy.yml index 58a5276e1..5ceb4eca1 100644 --- a/backend/openshift.deploy.yml +++ b/backend/openshift.deploy.yml @@ -14,16 +14,16 @@ parameters: required: true - name: CPU_REQUEST required: false - value: 25m + value: 100m - name: CPU_LIMIT required: false - value: 100m + value: 500m - name: MEMORY_REQUEST required: false - value: 150Mi + value: 750Mi - name: MEMORY_LIMIT required: false - value: 450Mi + value: 1Gi - name: E_LICENSING_URL required: true - name: DB_REPLICATE @@ -135,25 +135,25 @@ objects: # command: # - "/usr/bin/container-entrypoint" # - "/opt/app-root/src/scripts/pre-deploy.sh" - # containerName: ${REPO}-${ZONE}-${COMPONENT}-app + # containerName: ${REPO}-${ZONE}-${COMPONENT} # env: - # - name: PGDATABASE + # - name: DATABASE_NAME # valueFrom: # secretKeyRef: - # name: ${REPO}-${ZONE}-${COMPONENT}-pg12 + # name: ${REPO}-${ZONE}-database # key: database-name - # - name: PGUSER + # - name: DATABASE_USER # valueFrom: # secretKeyRef: - # name: ${REPO}-${ZONE}-${COMPONENT}-pg12 + # name: ${REPO}-${ZONE}-database # key: database-user - # - name: PGPASSWORD + # - name: DATABASE_PASSWORD # valueFrom: # secretKeyRef: - # name: ${REPO}-${ZONE}-${COMPONENT}-pg12 + # name: ${REPO}-${ZONE}-database # key: database-password - # - name: PGHOST - # value: ${REPO}-${ZONE}-${COMPONENT}-pg12 + # - name: DATABASE_SERVICE_NAME + # value: ${REPO}-${ZONE}-database resources: {} activeDeadlineSeconds: 21600 replicas: 1 @@ -170,22 +170,56 @@ objects: name: ${REPO}-${ZONE}-${COMPONENT} deployment: ${REPO}-${ZONE}-${COMPONENT} spec: - volumes: - - name: staticfiles - emptyDir: - sizeLimit: 250Mi + # initContainers: + # - name: check-database + # image: 'ghcr.io/bcgov/${REPO}/database:${TAG}' + # labels: + # name: ${REPO}-${ZONE}-${COMPONENT} + # command: ["/bin/bash", "-c", "set -x; psql -qtAX -c 'select 1'"] + # env: + # - name: PGDATABASE + # valueFrom: + # secretKeyRef: + # name: ${REPO}-${ZONE}-database + # key: database-name + # - name: PGUSER + # valueFrom: + # secretKeyRef: + # name: ${REPO}-${ZONE}-database + # key: database-user + # - name: PGPASSWORD + # valueFrom: + # secretKeyRef: + # name: ${REPO}-${ZONE}-database + # key: database-password + # - name: PGHOST + # value: ${REPO}-${ZONE}-database + # resources: + # limits: + # cpu: 50m + # memory: 256Mi + # requests: + # cpu: 10m + # memory: 128Mi + + # volumes: + # - name: staticfiles + # emptyDir: + # sizeLimit: 250Mi containers: - name: ${REPO}-${ZONE}-${COMPONENT}-app image: 'ghcr.io/bcgov/${REPO}/${COMPONENT}:${TAG}' - volumeMounts: - - name: staticfiles - mountPath: /app/staticfiles + # volumeMounts: + # - name: staticfiles + # mountPath: /app/staticfiles ports: - - containerPort: 8080 + - containerPort: 8000 protocol: TCP env: - name: DATABASE_SERVICE_NAME value: ${REPO}-${ZONE}-database + - name: DATABASE_PORT + value: "5432" - name: DATABASE_NAME valueFrom: secretKeyRef: @@ -206,38 +240,38 @@ objects: - name: APP_MODULE value: wsgi:application - name: APP_HOME - value: ${COMPONENT} + value: backend - name: APP_CONFIG value: "/opt/app-root/src/${COMPONENT}/gunicorn.ocp4.cfg" - name: DJANGO_SECRET_KEY valueFrom: secretKeyRef: - name: ${REPO}-django-${ZONE} + name: ${REPO}-${ZONE}-django key: secret_key - name: DJANGO_ADMIN_URL valueFrom: secretKeyRef: - name: ${REPO}-django-${ZONE} + name: ${REPO}-${ZONE}-django key: admin_url - name: DJANGO_ADMIN_USER valueFrom: secretKeyRef: - name: ${REPO}-django-${ZONE} + name: ${REPO}-${ZONE}-django key: admin_user - name: DJANGO_ADMIN_PASSWORD valueFrom: secretKeyRef: - name: ${REPO}-django-${ZONE} + name: ${REPO}-${ZONE}-django key: admin_password - name: E_LICENSING_AUTH_PASSWORD valueFrom: secretKeyRef: - name: ${REPO}-e-licensing-${ZONE} + name: ${REPO}-${ZONE}-e-licensing key: E_LICENSING_AUTH_PASSWORD - name: E_LICENSING_AUTH_USERNAME valueFrom: secretKeyRef: - name: ${REPO}-e-licensing-${ZONE} + name: ${REPO}-${ZONE}-e-licensing key: E_LICENSING_AUTH_USERNAME - name: E_LICENSING_URL valueFrom: @@ -342,9 +376,9 @@ objects: - name: APP_CONTEXT_ROOT value: ${REPO} - name: SESSION_COOKIE_SECURE - value: 'true' + value: 'True' - name: CSRF_COOKIE_SECURE - value: 'true' + value: 'True' - name: DB_REPLICATE valueFrom: configMapKeyRef: @@ -400,6 +434,8 @@ objects: configMapKeyRef: key: SSO_IDP_HINT name: ${REPO}-${ZONE}-global-config + - name: CUSTOM_GDAL_GEOS + value: 'false' - name: WEB_CONCURRENCY value: '4' - name: GUNICORN_WORKERS @@ -425,31 +461,31 @@ objects: memory: "${MEMORY_REQUEST}" # readinessProbe: # httpGet: - # path: /gwells/health - # port: 8080 - # scheme: HTTP - # initialDelaySeconds: 20 - # timeoutSeconds: 3 - # periodSeconds: 5 - # successThreshold: 1 - # failureThreshold: 5 + # path: /health + # port: 8000 + # initialDelaySeconds: 20 + # timeoutSeconds: 3 + # periodSeconds: 5 + # successThreshold: 1 + # failureThreshold: 5 # livenessProbe: # httpGet: - # path: /gwells/health - # port: 8080 - # scheme: HTTP - # initialDelaySeconds: 20 - # timeoutSeconds: 3 - # periodSeconds: 30 - # successThreshold: 1 - # failureThreshold: 5 + # path: /health + # port: 8000 + # initialDelaySeconds: 20 + # timeoutSeconds: 3 + # periodSeconds: 30 + # successThreshold: 1 + # failureThreshold: 5 terminationMessagePath: "/dev/termination-log" terminationMessagePolicy: File imagePullPolicy: Always restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst - securityContext: {} + securityContext: + capabilities: + add: ["NET_BIND_SERVICE"] schedulerName: default-scheduler - apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler @@ -478,29 +514,29 @@ objects: ports: - name: web protocol: TCP - port: 8080 - targetPort: 8080 + port: 8000 + targetPort: 8000 selector: name: ${REPO}-${ZONE}-${COMPONENT} type: ClusterIP sessionAffinity: None -- kind: Route - apiVersion: v1 - metadata: - name: ${REPO}-${ZONE}-${COMPONENT} - labels: - frontend: 'true' - app: ${REPO}-${ZONE}-${COMPONENT} - spec: - host: ${REPO}-${ZONE}-${COMPONENT}.apps.silver.devops.gov.bc.ca - path: "/gwells" - to: - kind: Service - name: ${REPO}-${ZONE}-${COMPONENT} - weight: 100 - port: - targetPort: web - tls: - insecureEdgeTerminationPolicy: Redirect - termination: edge - wildcardPolicy: None +# - kind: Route +# apiVersion: v1 +# metadata: +# name: ${REPO}-${ZONE}-${COMPONENT} +# labels: +# frontend: 'true' +# app: ${REPO}-${ZONE}-${COMPONENT} +# spec: +# host: ${REPO}-${ZONE}-${COMPONENT}.apps.silver.devops.gov.bc.ca +# path: "/gwells" +# to: +# kind: Service +# name: ${REPO}-${ZONE}-${COMPONENT} +# weight: 100 +# port: +# targetPort: web +# tls: +# insecureEdgeTerminationPolicy: Redirect +# termination: edge +# wildcardPolicy: None 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/backend/startup.sh b/backend/startup.sh new file mode 100644 index 000000000..345424529 --- /dev/null +++ b/backend/startup.sh @@ -0,0 +1,6 @@ +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/common/openshift.init.yml b/common/openshift.init.yml index efa303940..406dbc68d 100644 --- a/common/openshift.init.yml +++ b/common/openshift.init.yml @@ -3,7 +3,7 @@ kind: Template parameters: - name: REPO description: Repository name - value: ${REPO} + value: nr-gwells - name: ZONE description: Deployment zone, e.g. pr-### or prod required: true @@ -69,6 +69,7 @@ objects: database-name: ${POSTGRESQL_DATABASE} database-password: ${POSTGRESQL_PASSWORD} database-user: ${POSTGRESQL_USER} + database-host: nr-gwells-232-database.cd43d9-dev.svc.cluster.local fdw-database-user: proxy_wells_gwells fdw-database-password: ${FDW_DATABASE_PASSWORD} fdw-database-server: "//nrk1-scan.bcgov/envprod1.nrs.bcgov" @@ -137,7 +138,14 @@ objects: metadata: name: allow-same-namespace labels: - template: ${REPO}-backend-network-security-policy + template: nr-gwells-backend-network-security-policy spec: + podSelector: {} + ingress: + - from: + - namespaceSelector: + matchLabels: + environment: dev + name: cd43d9 policyTypes: - - Ingress + - Ingress \ No newline at end of file diff --git a/database/openshift.deploy.yml b/database/openshift.deploy.yml index 998c728ed..37a4e450e 100644 --- a/database/openshift.deploy.yml +++ b/database/openshift.deploy.yml @@ -127,7 +127,7 @@ objects: protocol: TCP targetPort: 5432 selector: - deployment: ${REPO}-${ZONE}-${COMPONENT} + name: ${REPO}-${ZONE}-${COMPONENT} sessionAffinity: None type: ClusterIP status: @@ -175,7 +175,7 @@ objects: - name: PG_PRIMARY_PORT value: "5432" - name: CONTAINER_NAME - value: postgresql + value: ${REPO}-${ZONE}-${COMPONENT} - name: PG_PRIMARY_HOST value: ${REPO}-${ZONE}-${COMPONENT} - name: PGDATA_PATH_OVERRIDE @@ -227,7 +227,7 @@ objects: tcpSocket: port: 5432 timeoutSeconds: 1 - name: postgresql + name: ${REPO}-${ZONE}-${COMPONENT} ports: - containerPort: 5432 protocol: TCP diff --git a/docker-compose.yml b/docker-compose.yml index 015c16ccf..473261032 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: minio-public: build: context: ./minio/ - hostname: minio + container_name: minio ports: - "9000:9000" volumes: @@ -34,7 +34,7 @@ services: # minio-private: # build: # context: ./minio/ - # hostname: minio + # container_name: minio # ports: # - "9001:9001" # volumes: @@ -53,7 +53,7 @@ services: db: platform: linux/x86_64 image: crunchydata/crunchy-postgres-gis:centos7-12.2-4.2.2 - hostname: db + container_name: db environment: PG_USER: gwells PG_PASSWORD: test1 @@ -112,7 +112,7 @@ services: ### Tileserv ### ############################################################################################# tileserv: - hostname: tileserv + container_name: tileserv depends_on: - db platform: linux/x86_64 @@ -133,22 +133,22 @@ services: ############################################################################################# frontend: image: node:14.21.3 - hostname: frontend + container_name: frontend # working_dir: /app/frontend # build: # context: ./frontend # dockerfile: Dockerfile environment: DEBUG: "true" - VUE_APP_AXIOS_BASE_URL: "http://backend:8000/gwells/api/v2/" + VUE_APP_AXIOS_BASE_URL: "/api/" VUE_APP_VECTOR_TILE_BASE_URL: "/tiles/" VECTOR_TILE_SERVER: "http://tileserv:7800/" - API_TARGET: "http://backend:8000/" - BACKEND_URL: "http://backend:8000" - LOG_LEVEL: "info" + API_TARGET: "${API_TARGET:-http://backend:8000/}" + # BACKEND_URL: "http://backend:8000" + # LOG_LEVEL: "info" command: /bin/bash -c "cd /frontend && npm install && npm run serve" ports: - - "3000:8080" + - "8080:8080" volumes: - ./frontend:/frontend - /frontend/node_modules/ @@ -189,34 +189,37 @@ services: ############################################################################################# backend: platform: linux/x86_64 - working_dir: /backend + # working_dir: /backend build: - context: ./backend - dockerfile: Dockerfile - hostname: backend + context: ./ + dockerfile: ./backend/Dockerfile + image: nr-gwells/backend:latest + container_name: backend # env_file: # - path: ./.env.test # required: false environment: ENVIRONMENT: "${ENVIRONMENT:-local}" APP_CONTEXT_ROOT: gwells - CSRF_COOKIE_SECURE: "False" - CUSTOM_GDAL_GEOS: "False" + CSRF_COOKIE_SECURE: "false" + CUSTOM_GDAL_GEOS: "false" DATABASE_NAME: gwells DATABASE_USER: "${DATABASE_USER:-gwells}" DATABASE_PASSWORD: "${DATABASE_PASSWORD:-test1}" - DATABASE_SERVICE_NAME: gwells + # DATABASE_SERVICE_NAME: gwells DJANGO_ADMIN_URL: admin DJANGO_DEBUG: "true" DJANGO_SECRET_KEY: secret ENABLE_ADDITIONAL_DOCUMENTS: "true" ENABLE_AQUIFERS_SEARCH: "true" - GWELLS_SERVICE_HOST: "${GWELLS_SERVICE_HOST:-db}" - GWELLS_SERVICE_PORT: "${GWELLS_SERVICE_PORT:-5432}" + # GWELLS_SERVICE_HOST: "${GWELLS_SERVICE_HOST:-db}" + # GWELLS_SERVICE_PORT: "${GWELLS_SERVICE_PORT:-5432}" + DATABASE_SERVICE_NAME: db + DATABASE_PORT: 5432 MINIO_ACCESS_KEY: minio MINIO_SECRET_KEY: minio1234 PYTHONUNBUFFERED: "1" - SESSION_COOKIE_SECURE: "False" + SESSION_COOKIE_SECURE: "false" SSO_AUDIENCE: gwells-4121 SSO_CLIENT: gwells-4121 SSO_TEST_AUDIENCE: gwells-api-tests-4820 diff --git a/frontend/vue.config.js b/frontend/vue.config.js index 1f92deda5..60437f512 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -5,8 +5,8 @@ if (process.env.API_TARGET) { module.exports = { lintOnSave: false, runtimeCompiler: true, - // publicPath: process.env.NODE_ENV === 'production' ? '/gwells/' : '/', - publicPath: '/', + publicPath: process.env.NODE_ENV === 'production' ? '/gwells/' : '/', + // publicPath: '/', configureWebpack: { resolve: { alias: {