Skip to content

Commit 2222a53

Browse files
authored
Merge pull request #432 from open-plan-tool/fix/security
Update project dependencies
2 parents f5a4e85 + abf27f8 commit 2222a53

67 files changed

Lines changed: 565 additions & 861 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.envs/epa.postgres

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
EPA_SECRET_KEY=v@p9^=@lc3#1u_xtx*^xhrv0f3fli1(+8ik^k@g-_bzmexb0$7n
22
DEBUG=False
3-
TRUSTED_HOST=127.0.0.1:8080
3+
TRUSTED_HOST=http://127.0.0.1:8000
44
EMAIL_HOST_IP=127.0.0.1
55
USE_PROXY=False
66
PROXY_ADDRESS=http://proxy_address:port

.github/dependabot.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Config for Dependabot updates. See Documentation here:
2+
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3+
4+
version: 2
5+
updates:
6+
# Update GitHub actions in workflows
7+
- package-ecosystem: 'github-actions'
8+
directory: '/'
9+
schedule:
10+
interval: 'monthly'
11+
12+
# Enable version updates for Docker
13+
# We need to specify each Dockerfile in a separate entry because Dependabot doesn't
14+
# support wildcards or recursively checking subdirectories. Check this issue for updates:
15+
# https://github.com/dependabot/dependabot-core/issues/2178
16+
- package-ecosystem: 'docker'
17+
# Look for a `Dockerfile` in the directory
18+
directory: 'app/compose/production/app_postgres/'
19+
schedule:
20+
interval: 'monthly'
21+
ignore:
22+
- dependency-name: '*'
23+
update-types:
24+
- 'version-update:semver-major'
25+
- 'version-update:semver-minor'
26+
27+
# Enable version updates for Python/Pip - Production
28+
- package-ecosystem: 'pip'
29+
# Look for a `requirements.txt` in the `root` directory
30+
# also 'setup.cfg', '.python-version' and 'requirements/*.txt'
31+
directory: '/'
32+
schedule:
33+
interval: 'monthly'

.github/workflows/black_linter.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CI
2+
3+
# Enable Buildkit and let compose use it to speed up image building
4+
env:
5+
DOCKER_BUILDKIT: 1
6+
COMPOSE_DOCKER_CLI_BUILD: 1
7+
8+
on:
9+
pull_request:
10+
branches: ["main"]
11+
paths-ignore:
12+
- "README.md"
13+
14+
push:
15+
branches: ["main"]
16+
paths-ignore:
17+
- "README.md"
18+
19+
concurrency:
20+
group: ${{ github.head_ref || github.run_id }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
linter:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout Code Repository
28+
uses: actions/checkout@v6
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v6
32+
with:
33+
python-version-file: '.python-version'
34+
35+
- name: Run pre-commit
36+
uses: pre-commit/action@v3.0.1
37+
with:
38+
extra_args: --config app/.pre-commit-config.yaml --files $(git ls-files app)
39+
40+
build:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout Code Repository
44+
uses: actions/checkout@v6
45+
46+
- name: Build the Stack
47+
run: docker compose -f docker-compose-local.yml build app_pg
48+
49+
- name: Check DB Migrations
50+
run: docker compose -f docker-compose-local.yml run --rm app_pg python manage.py makemigrations --check
51+
52+
- name: Run DB Migrations
53+
run: docker compose -f docker-compose-local.yml run --rm app_pg python manage.py migrate
54+
55+
- name: Run Tests
56+
run: docker compose -f docker-compose-local.yml run --rm app_pg python manage.py test
57+
58+
- name: Tear down the Stack
59+
if: always()
60+
run: docker compose -f docker-compose-local.yml down

.github/workflows/tag-on-prod.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Tag release on prod
2+
3+
on:
4+
push:
5+
branches: ['production']
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
tag:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout (full history for tags)
15+
uses: actions/checkout@v6
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Read version from epa/settings.py
20+
id: version
21+
run: |
22+
set -euo pipefail
23+
VERSION=$(python - <<'PY'
24+
import re
25+
p = "epa/settings.py"
26+
s = open(p, "r", encoding="utf-8").read()
27+
m = re.search(r'APP_VERSION_NUMBER\s*=\s*"([^"]+)"', s)
28+
if not m:
29+
raise SystemExit(f"Could not find APP_VERSION_NUMBER in {p}")
30+
print(m.group(1))
31+
PY
32+
)
33+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
34+
echo "Detected version: $VERSION"
35+
36+
- name: Create and push tag if missing
37+
env:
38+
VERSION: ${{ steps.version.outputs.version }}
39+
run: |
40+
set -euo pipefail
41+
TAG="v${VERSION}"
42+
43+
# If tag already exists locally or remotely, do nothing
44+
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
45+
echo "Tag ${TAG} already exists (local)."
46+
exit 0
47+
fi
48+
if git ls-remote --tags origin "${TAG}" | grep -q "${TAG}"; then
49+
echo "Tag ${TAG} already exists (remote)."
50+
exit 0
51+
fi
52+
53+
git config user.name "github-actions[bot]"
54+
git config user.email "github-actions[bot]@users.noreply.github.com"
55+
56+
git tag -a "${TAG}" -m "Release ${TAG}"
57+
git push origin "${TAG}"
58+
echo "Pushed tag ${TAG}"

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This repository contains the code for the user interface. The simulations are pe
2121

2222
Prior to be able to develop locally, you might need to install postgres, simply google `install postgres` followed by your os name (`linux/mac/windows`)
2323

24-
1. Create a virtual environment
24+
1. Create a virtual environment using `python=3.12`
2525
2. Activate your virtual environment
2626
3. Move to the `app` folder with `cd app`
2727
4. Install local development dependencies with `pip install -r requirements/local.txt`
@@ -35,18 +35,18 @@ SQL_HOST=localhost
3535
SQL_PORT=5432
3636
TRUSTED_HOST=http://127.0.0.1:8000
3737
DEBUG=(True|False)
38-
MVS_HOST_API=<the simulation server you wish to use>
38+
MVS_API_HOST=<the simulation server you wish to use>
3939
```
40-
6. Execute the `local_setup.sh` file (`. local_setup.sh` on linux/mac `bash local_setup.sh` on windows) you might have to make it executable first. Answer yes to the question
41-
7. Start the local server with `python manage.py runserver`
42-
8. You can then login with `testUser` and `ASas12,.` or create your own account
40+
6. Set up pre-commit hooks with `pre-commit install`
41+
7. Execute the `local_setup.sh` file (`. local_setup.sh` on linux/mac `bash local_setup.sh` on windows) you might have to make it executable first. Answer yes to the question
42+
8. Start the local server with `python manage.py runserver`
43+
9. You can then login with `testUser` and `ASas12,.` or create your own account
4344

4445
## Deploy using Docker Compose
4546
The following commands should get everything up and running, using the web based version of the MVS API.
4647

4748
You need to be able to run docker-compose inside your terminal. If you can't you should install [Docker desktop](https://www.docker.com/products/docker-desktop/) first.
4849

49-
5050
* Clone the repository locally `git clone --single-branch --branch main https://github.com/open-plan-tool/gui.git open_plan_gui`
5151
* Move inside the created folder (`cd open_plan_gui`)
5252
* Edit the `.envs/epa.postgres` and `.envs/db.postgres` environment files
@@ -55,20 +55,21 @@ You need to be able to run docker-compose inside your terminal. If you can't you
5555
* The value assigned to the variables `POSTGRES_DB`, `POSTGRES_USER`, `POSTGRES_PASSWORD` in `.envs/db.postgres` should match the ones of
5656
the variables `SQL_DATABASE`, `SQL_USER`, `SQL_PASSWORD` in `.envs/epa.postgres`, respectively
5757

58-
* Define an environment variable `MVS_HOST_API` in `.envs/epa.postgres` and set the url of the simulation server
58+
* Define an environment variable `MVS_API_HOST` in `.envs/epa.postgres` and set the url of the simulation server
5959
you wish to use for your models (for example `MVS_API_HOST="<url to your favorite simulation server>"`), you can deploy your own [simulation server](https://github.com/open-plan-tool/simulation-server) locally if you need
6060

6161
* Assign the domain of your website (including `http://` or `https://`) to `TRUSTED_HOST` , see https://docs.djangoproject.com/en/4.2/ref/settings/#csrf-trusted-origins for more information
6262

6363
Next you can either provide the following commands inside a terminal (with ubuntu you might have to prepend `sudo`)
64-
* `docker-compose --file=docker-compose-postgres.yml up -d --build`
65-
* `docker-compose --file=docker-compose-postgres.yml exec -u root app_pg sh initial_setup.sh` (this will also load a default testUser account with sample scenario).
64+
* `docker-compose --file=docker-compose-local.yml up -d --build`
65+
* `docker-compose --file=docker-compose-local.yml exec -u root app_pg sh initial_setup.sh` (this will also load a default testUser account with sample scenario).
66+
6667

6768
Or you can run a python script with the following command
6869
* `python deploy.py`
6970

7071
Finally
71-
* Open browser and navigate to http://localhost:8080: you should see the login page of the open_plan app
72+
* Open browser and navigate to http://localhost:8000: you should see the login page of the open_plan app
7273
* You can then login with `testUser` and `ASas12,.` or create your own account
7374

7475
### Proxy settings (optional)
@@ -85,7 +86,7 @@ If you use a proxy you will need to set `USE_PROXY=True` and edit `PROXY_ADDRESS
8586
## Tear down (uninstall) docker containers
8687
To remove the application (including relevant images, volumes etc.), one can use the following commands in terminal:
8788

88-
`docker-compose down --file=docker-compose-postgres.yml -v`
89+
`docker-compose down --file=docker-compose-local.yml -v`
8990

9091
you can add `--rmi local` if you wish to also remove the images (this will take you a long time to rebuild the docker containers from scratch if you want to redeploy the app later then)
9192

app/.babelrc.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

app/.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ package-lock.json
1212
Pipfile
1313
Pipfile.lock
1414
webpack.config.js
15-
.babelrc.json
1615
.dockerignore
1716

1817
# **

app/.pre-commit-config.yaml

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,45 @@
33

44
exclude: 'docs|node_modules|vendors|migrations|.git|.tox'
55
default_stages: [pre-commit]
6-
fail_fast: true
6+
minimum_pre_commit_version: "3.2.0"
7+
8+
default_language_version:
9+
python: python3.12
710

811
repos:
9-
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v3.2.0
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v5.0.0
1114
hooks:
12-
- id: trailing-whitespace
13-
- id: end-of-file-fixer
14-
- id: check-yaml
15-
- id: check-json
16-
- id: check-added-large-files
17-
- id: requirements-txt-fixer
15+
- id: trailing-whitespace
16+
- id: end-of-file-fixer
17+
- id: check-json
18+
- id: check-toml
19+
- id: check-xml
20+
- id: check-yaml
21+
- id: debug-statements
22+
- id: check-case-conflict
23+
- id: check-docstring-first
24+
- id: detect-private-key
1825

19-
- repo: https://github.com/pre-commit/mirrors-jshint
20-
rev: v2.13.6
26+
# Run the Ruff linter.
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.9.3
2129
hooks:
22-
- id: jshint
30+
# Linter
31+
# - id: ruff
32+
# args: [--fix, --exit-non-zero-on-fix]
33+
# Formatter
34+
- id: ruff-format
2335

24-
- repo: https://github.com/psf/black
25-
rev: 24.8.0
26-
hooks:
27-
- id: black
36+
## Run the djLint linter
37+
# - repo: https://github.com/djlint/djLint
38+
# rev: v1.36.4
39+
# hooks:
40+
# - id: djlint-reformat-django
41+
# - id: djlint-django
42+
43+
# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
44+
ci:
45+
autoupdate_schedule: monthly
46+
skip: []
47+
submodules: false

0 commit comments

Comments
 (0)