diff --git a/.gitignore b/.gitignore index aa2270236..66b1738a3 100644 --- a/.gitignore +++ b/.gitignore @@ -102,8 +102,12 @@ node_modules bower_components npm-debug.log +# Mac + local +*.DS_Store environment.sh .envrc +.env +.env* # CloudFoundry .cf diff --git a/Makefile b/Makefile index 71d631b9c..b72616f0f 100644 --- a/Makefile +++ b/Makefile @@ -26,15 +26,20 @@ VIRTUALENV_ROOT := $(shell [ -z $$VIRTUAL_ENV ] && echo $$(pwd)/venv || echo $$V bootstrap: generate-version-file ## Set up everything to run the app pip3 install -r requirements_for_test.txt source $(HOME)/.nvm/nvm.sh && nvm install && npm ci --no-audit - . environment.sh; source $(HOME)/.nvm/nvm.sh && npm run build + source $(HOME)/.nvm/nvm.sh && npm run build + +.PHONY: bootstrap-with-docker +bootstrap-with-docker: generate-version-file ## Set up everything to run the app + # npm ci --no-audit + npm run build .PHONY: watch-frontend watch-frontend: ## Build frontend and watch for changes - . environment.sh; npm run watch + npm run watch .PHONY: run-flask run-flask: ## Run flask - . environment.sh && flask run -p 6012 + flask run -p 6012 .PHONY: npm-audit npm-audit: ## Check for vulnerabilities in NPM packages diff --git a/app/config.py b/app/config.py index 63da11bf7..041e17ada 100644 --- a/app/config.py +++ b/app/config.py @@ -104,9 +104,9 @@ class Development(Config): MOU_BUCKET_NAME = 'notify.tools-mou' TRANSIENT_UPLOADED_LETTERS = 'development-transient-uploaded-letters' PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'development-letters-precompiled-originals-backup' - ADMIN_CLIENT_SECRET = 'dev-notify-secret-key' - API_HOST_NAME = 'http://localhost:6011' + # check for local compose orchestration variable + API_HOST_NAME = os.environ.get('DEV_API_HOST_NAME', 'http://dev:6011') DANGEROUS_SALT = 'dev-notify-salt' SECRET_KEY = 'dev-notify-secret-key' ANTIVIRUS_API_HOST = 'http://localhost:6016' @@ -115,7 +115,8 @@ class Development(Config): ASSET_PATH = '/static/' - REDIS_URL = 'redis://localhost:6379/0' + REDIS_URL = os.environ.get('DEV_REDIS_URL', 'http://redis:6379') + REDIS_ENABLED = os.environ.get('REDIS_ENABLED') == '1' diff --git a/app/utils/email_domains.txt b/app/utils/email_domains.txt index a74de1640..a090b14ba 100644 --- a/app/utils/email_domains.txt +++ b/app/utils/email_domains.txt @@ -1,11 +1,5 @@ -gov.uk -nhs.uk -nhs.net -nhs.scot -police.uk -cjsm.net -ac.uk -sch.uk -onevoicewales.wales -suttonmail.org -hscni.net +gsa.gov +gmail.com +dispostable.com +simulator.amazonses.com +amazonses.com \ No newline at end of file diff --git a/devcontainer-admin/.devcontainer.json b/devcontainer-admin/.devcontainer.json new file mode 100644 index 000000000..d14e66411 --- /dev/null +++ b/devcontainer-admin/.devcontainer.json @@ -0,0 +1,42 @@ +{ + "name": "notification-admin", + "dockerComposeFile": "../docker-compose.devcontainer.yml", + "service": "admin", + "workspaceFolder": "/workspace", + "shutdownAction": "stopCompose", + "remoteEnv": { + "PATH": "/home/vscode/.local/bin:${containerEnv:PATH}" // give our installed Python modules precedence + }, + "settings": { + "[python]": { + "editor.formatOnSave": true + }, + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.pythonPath": "/usr/local/bin/python" + }, + "features": { + "docker-from-docker": { + "version": "latest", + "moby": true + } + }, + "extensions": [ + "ms-python.black-formatter", + "donjayamanne.python-extension-pack", + "ms-azuretools.vscode-docker", + "ms-python.vscode-pylance", + "eamodio.gitlens", + "wholroyd.jinja", + "pmbenjamin.vscode-snyk", + "visualstudioexptteam.vscodeintellicode", + "yzhang.markdown-all-in-one", + "ms-ossdata.vscode-postgresql", + "GitHub.copilot" + ], + "forwardPorts": [ + 6012 + ], + "postCreateCommand": "chmod u+x devcontainer-admin/scripts/notify-admin-entrypoint.sh && ./devcontainer-admin/scripts/notify-admin-entrypoint.sh", + "remoteUser": "vscode" +} \ No newline at end of file diff --git a/devcontainer-admin/Dockerfile b/devcontainer-admin/Dockerfile new file mode 100644 index 000000000..2510859f6 --- /dev/null +++ b/devcontainer-admin/Dockerfile @@ -0,0 +1,52 @@ +FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.9 + +# RUN groupadd --gid 1000 node \ +# && useradd --uid 1000 --gid node --shell /bin/bash --create-home node + +ENV NODE_VERSION 16.15.1 + +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils 2>&1 \ + && apt-get -y install \ + curl \ + emacs \ + exa \ + fd-find \ + git \ + iproute2 \ + less \ + libsodium-dev \ + lsb-release \ + man-db \ + manpages \ + net-tools \ + nodejs \ + npm \ + openssh-client \ + procps \ + sudo \ + tldr \ + unzip \ + vim \ + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +RUN echo $(node --version) +RUN echo $(npm --version) + +# Upgrade pip +RUN pip install --upgrade pip + +RUN groupadd --gid 1001 node \ + && useradd --uid 1001 --gid node --shell /bin/bash --create-home node + +COPY package-lock.json ./ +COPY package.json ./ +COPY devcontainer-admin/scripts/notify-admin-entrypoint.sh ./ + +RUN npm ci --no-audit + +ENV SHELL /bin/zsh + +EXPOSE 6012 \ No newline at end of file diff --git a/devcontainer-admin/scripts/notify-admin-entrypoint.sh b/devcontainer-admin/scripts/notify-admin-entrypoint.sh new file mode 100755 index 000000000..26a300fa0 --- /dev/null +++ b/devcontainer-admin/scripts/notify-admin-entrypoint.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -ex + +################################################################### +# This script will get executed *once* the Docker container has +# been built. Commands that need to be executed with all available +# tools and the filesystem mount enabled should be located here. +################################################################### + +# Define aliases +echo -e "\n\n# User's Aliases" >> ~/.zshrc +echo -e "alias fd=fdfind" >> ~/.zshrc +echo -e "alias l='ls -al --color'" >> ~/.zshrc +echo -e "alias ls='exa'" >> ~/.zshrc +echo -e "alias l='exa -alh'" >> ~/.zshrc +echo -e "alias ll='exa -alh@ --git'" >> ~/.zshrc +echo -e "alias lt='exa -al -T -L 2'" >> ~/.zshrc + +cd /workspace + +# Warm up git index prior to display status in prompt else it will +# be quite slow on every invocation of starship. +git status + +pip3 install -r requirements.txt +pip3 install -r requirements_for_test.txt + +# npm rebuild node-sass +make generate-version-file +# make babel + +# npm ci install +npm run build + +# run flask +# make run \ No newline at end of file diff --git a/docker-compose.devcontainer.yml b/docker-compose.devcontainer.yml new file mode 100644 index 000000000..eeaad2650 --- /dev/null +++ b/docker-compose.devcontainer.yml @@ -0,0 +1,25 @@ +version: '3' + +services: + admin: + container_name: admin + image: notification-admin + env_file: .env + build: + context: . + dockerfile: devcontainer-admin/Dockerfile + command: sleep infinity + volumes: + - .:/workspace:cached + ports: + - "6012:6012" + expose: + - "6012" + adminredis: + container_name: adminredis + image: redis:latest + +networks: + default: + name: notify-network + external: true diff --git a/requirements.in b/requirements.in index f7f0afbe2..dd5ab2761 100644 --- a/requirements.in +++ b/requirements.in @@ -24,6 +24,7 @@ notifications-python-client==6.3.0 rtreelib==0.2.0 fido2==0.9.3 pyproj==3.3.1 +python-dotenv==0.20.0 # PaaS awscli-cwlogs>=1.4,<1.5 diff --git a/requirements.txt b/requirements.txt index 7e4f4dc29..f3cb81f49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -172,6 +172,8 @@ python-dateutil==2.8.2 # via # awscli-cwlogs # botocore +python-dotenv==0.20.0 + # via -r requirements.in python-json-logger==2.0.2 # via notifications-utils pytz==2022.1