Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPAT-2026 Establish project structure #3

Merged
merged 29 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ef9688b
DPAT-2026 Establish project structure and basic tech
Nov 7, 2023
c652f87
DPAT-2026 added a dummy file to show the cli folder
Nov 7, 2023
13460ad
Add PostgreSQL
Nov 7, 2023
ab2d353
DPAT-2026 try to fix the superlint warnings
Nov 7, 2023
1b36da6
DPAT-2026 renamed some folders
Nov 7, 2023
da4e943
Add Docker Compose
Nov 7, 2023
e201cc6
Update post-create docker compose
Gary-H9 Nov 7, 2023
ee1f09f
Fix lint errors, add dev dependencies
michaeljcollinsuk Nov 7, 2023
21bb8ea
Add pre-commit config and add some basic running documentation
michaeljcollinsuk Nov 7, 2023
0875a6e
DPAT-2026 try to fix the rest of superlint warnings
Nov 7, 2023
fccf6a9
DPAT-2026 last one from superlinter (hopefully)
Nov 7, 2023
52e3ea8
Bump line length to match Black, add yamllint to pre-commit
michaeljcollinsuk Nov 8, 2023
f21558a
Remove django_prometheus from deps
michaeljcollinsuk Nov 8, 2023
40af1a0
Reformat readme
michaeljcollinsuk Nov 8, 2023
176d4e3
Add runArgs to devcontainer.json and fix directory
Nov 8, 2023
1699327
Remove git and pre-commit
Nov 8, 2023
c30d0f9
test pre-commit
Nov 8, 2023
ddffa6d
Remove git and pre-commit
Nov 8, 2023
e11aa50
Add postStartCommand for pre-commit
Nov 8, 2023
2170f72
Add hello world
Nov 8, 2023
a55bfec
Add Super-Linter Python settings
Nov 8, 2023
f4b63d4
Add LINTER_RULES_PATH
Nov 8, 2023
3e949e7
Push workarounds
Nov 8, 2023
2d86d81
Pass env vars direct to github action
michaeljcollinsuk Nov 8, 2023
02d5ba7
Ignore missing import errors in mypy
michaeljcollinsuk Nov 8, 2023
563dadd
Remove Super-Linter hackery
Nov 8, 2023
93274a7
Merge branch 'dpat-2062-tech-structure' of github.com:ministryofjusti…
Nov 8, 2023
8bd6e2b
Removed Super-Linter env
Nov 8, 2023
b35809a
Removed var loading step
Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
},
"ghcr.io/devcontainers/features/python:1": {
"version": "3.11"
}
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"./features/src/postgresql": {}
},
"postCreateCommand": "bash scripts/devcontainer/post-create.sh",
"postStartCommand": "bash scripts/devcontainer/post-start.sh",
"runArgs": ["--name=data-platform-control-panel-devcontainer"],
"customizations": {
"vscode": {
"extensions": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "postgresql",
"version": "1.0.0",
"name": "postgresql",
"description": "PostgreSQL"
}
13 changes: 13 additions & 0 deletions .devcontainer/features/src/postgresql/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" >/etc/apt/sources.list.d/pgdg.list

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

apt-get update

apt-get -y install \
postgresql-common \
postgresql-client-common \
postgresql-15 \
postgresql-client-15
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 88
extend-ignore = E203, E704
exclude =
venv
1 change: 0 additions & 1 deletion .github/super-linter.env

This file was deleted.

10 changes: 6 additions & 4 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ jobs:
with:
fetch-depth: 0

- name: Load Super-Linter Variables
id: load_super_linter_variables
run: cat .github/super-linter.env >>"${GITHUB_ENV}"

- name: Super-Linter
id: super_linter
# yamllint disable-line rule:line-length
uses: super-linter/super-linter/slim@35c3fa445cc217dfcc7b53eeb4e7aa95fcdd02fc # v5.6.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BRANCH: main
VALIDATE_ALL_CODEBASE: false
LINTER_RULES_PATH: /
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
PYTHON_FLAKE8_CONFIG_FILE: .flake8
PYTHON_MYPY_CONFIG_FILE: mypy.ini
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ env/
terraform.tfstate
super-linter.log
.mypy_cache/
.idea/
__pycache__
*.egg-info/
45 changes: 45 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- name: End of File Fixer
id: end-of-file-fixer
- name: Trailing Whitespace Fixer
id: trailing-whitespace
- name: Check yaml
id: check-yaml
- name: requirements.txt fixer
id: requirements-txt-fixer

- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
name: black formatting

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
name: flake8 lint

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
- id: mypy
name: mypy
additional_dependencies:
- django-stubs
- psycopg2-binary

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
hooks:
- id: yamllint
25 changes: 25 additions & 0 deletions README.md
michaeljcollinsuk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# Data Platform Control Panel

[![repo standards badge](https://img.shields.io/endpoint?labelColor=231f20&color=005ea5&style=for-the-badge&label=MoJ%20Compliant&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fapi%2Fv1%2Fcompliant_public_repositories%2Fendpoint%2Fdata-platform-control-panel&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABmJLR0QA/wD/AP+gvaeTAAAHJElEQVRYhe2YeYyW1RWHnzuMCzCIglBQlhSV2gICKlHiUhVBEAsxGqmVxCUUIV1i61YxadEoal1SWttUaKJNWrQUsRRc6tLGNlCXWGyoUkCJ4uCCSCOiwlTm6R/nfPjyMeDY8lfjSSZz3/fee87vnnPu75z3g8/kM2mfqMPVH6mf35t6G/ZgcJ/836Gdug4FjgO67UFn70+FDmjcw9xZaiegWX29lLLmE3QV4Glg8x7WbFfHlFIebS/ANj2oDgX+CXwA9AMubmPNvuqX1SnqKGAT0BFoVE9UL1RH7nSCUjYAL6rntBdg2Q3AgcAo4HDgXeBAoC+wrZQyWS3AWcDSUsomtSswEtgXaAGWlVI2q32BI0spj9XpPww4EVic88vaC7iq5Hz1BvVf6v3qe+rb6ji1p3pWrmtQG9VD1Jn5br+Knmm70T9MfUh9JaPQZu7uLsR9gEsJb3QF9gOagO7AuUTom1LpCcAkoCcwQj0VmJregzaipA4GphNe7w/MBearB7QLYCmlGdiWSm4CfplTHwBDgPHAFmB+Ah8N9AE6EGkxHLhaHU2kRhXc+cByYCqROs05NQq4oR7Lnm5xE9AL+GYC2gZ0Jmjk8VLKO+pE4HvAyYRnOwOH5N7NhMd/WKf3beApYBWwAdgHuCLn+tatbRtgJv1awhtd838LEeq30/A7wN+AwcBt+bwpD9AdOAkYVkpZXtVdSnlc7QI8BlwOXFmZ3oXkdxfidwmPrQXeA+4GuuT08QSdALxC3OYNhBe/TtzON4EziZBXD36o+q082BxgQuqvyYL6wtBY2TyEyJ2DgAXAzcC1+Xxw3RlGqiuJ6vE6QS9VGZ/7H02DDwAvELTyMDAxbfQBvggMAAYR9LR9J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lG+99bfdIoo5PU4w362xHePxl1slMab6tV72KUxDvzlAMT8G0ZohXq39VX1bNzzxij9K1Qb9lhdGe931B/kR6/zCwY9YvuytCsMlj+gbr5SemhqkyuzE8xau4MP865JvWNuj0b1YuqDkgvH2GkURfakly01Cg7Cw0+qyXxkjojq9Lw+vT2AUY+DlF/otYq1Ixc35re2V7R8aTRg2KUv7+ou3x/14PsUBn3NG51S0XpG0Z9PcOPKWSS0SKNUo9Rv2Mmt/G5WpPF6pHGra7Jv410OVsdaz217AbkAPX3ubkm240belCuudT4Rp5p/DyC2lf9mfq1iq5eFe8/lu+K0YrVp0uret4nAkwlB6vzjI/1PxrlrTp/oNHbzTJI92T1qAT+BfW49MhMg6JUp7ehY5a6Tl2jjmVvitF9fxo5Yq8CaAfAkzLMnySt6uz/1k6bPx59CpCNxGfoSKA30IPoH7cQXdArwCOllFX/i53P5P9a/gNkKpsCMFRuFAAAAABJRU5ErkJggg==)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/data-platform-control-panel)

## Running

The quickest way to get the project running is to use the dev container that has been configured to install all
dependencies required to run the project locally. To use the dev container, see the [Data Platform docs.](https://technical-documentation.data-platform.service.justice.gov.uk/documentation/platform/infrastructure/developing.html#developing-the-data-platform)

Alternatively you can install the project locally by installing python 3.11, creating a venv, and installing the
project dependencies with

```commandline
pip install -r requirements.dev.txt
```

You will also need to have Postgresql installed and running on your machine.

### Pre-commit

To avoid pushing code and seeing the GitHub actions fail due to linting errors, when installing the project for the
first time you should install the pre-commit hooks with:

```commandline
pre-commit install
```

This will run black, mypy, flake8 and isort before a commit to check for failures and stage any required changes.
13 changes: 13 additions & 0 deletions contrib/docker-compose-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: '3.8'

services:
postgres:
image: public.ecr.aws/docker/library/postgres:15.4
restart: always
environment:
POSTGRES_USER: controlpanel
POSTGRES_PASSWORD: controlpanel
POSTGRES_DB: controlpanel
ports:
- "5432:5432"
Empty file added controlpanel/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions controlpanel/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for controlpanel project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controlpanel.settings")

application = get_asgi_application()
Empty file added controlpanel/core/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions controlpanel/core/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CliConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "controlpanel.core"
Empty file.
Empty file.
Empty file.
Empty file added controlpanel/domains/apps.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions controlpanel/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from controlpanel.settings.common import * # noqa
141 changes: 141 additions & 0 deletions controlpanel/settings/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"""
Django settings for controlpanel project.

Generated by 'django-admin startproject' using Django 4.2.7.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

PROJECT_NAME = "controlpanel"

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn"


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS: list = []


# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "controlpanel.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]


WSGI_APPLICATION = "controlpanel.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

# -- Database
DB_HOST = os.environ.get("DB_HOST", "127.0.0.1")
ENABLE_DB_SSL = (
str(
os.environ.get("ENABLE_DB_SSL", DB_HOST not in ["127.0.0.1", "localhost"])
).lower()
== "true"
)
DATABASES: dict = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DB_NAME", PROJECT_NAME),
"USER": os.environ.get("DB_USER", ""),
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
"HOST": DB_HOST,
"PORT": os.environ.get("DB_PORT", "5432"),
}
}

if ENABLE_DB_SSL:
DATABASES["default"]["OPTIONS"] = {"sslmode": "require"}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
22 changes: 22 additions & 0 deletions controlpanel/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
URL configuration for controlpanel project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path("admin/", admin.site.urls),
]
16 changes: 16 additions & 0 deletions controlpanel/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for controlpanel project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controlpanel.settings")

application = get_wsgi_application()
23 changes: 23 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controlpanel.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
ignore_missing_imports = True
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 88
target-version = ["py311"]
Loading
Loading