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

Edit code while running #55

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 8 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,38 @@ name: CI - Ubuntu
on:
push:
branches:
- master
- main
pull_request:
branches:
- master

jobs:
webtests:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: x64
- name: Checkout head
uses: actions/checkout@v2
- name: Checkout head
uses: actions/checkout@v4
- name: Run webtests
run: chmod +x ./run_web_tests.sh && ./run_web_tests.sh
run: bash ./run_web_tests.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

flake8:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: x64
- name: Checkout head
uses: actions/checkout@v2
- name: Checkout head
uses: actions/checkout@v4
- name: Install flake8
run: pip install flake8
- name: Run flake8
run: cd web && flake8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

168 changes: 168 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,171 @@
# Environment files
.env

# Shared data directories for containers
pgdata/
webdata/

# Docker override files for local development options
docker-compose.override.yml

# Stanadard Python gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
4 changes: 0 additions & 4 deletions .test_env

This file was deleted.

29 changes: 25 additions & 4 deletions DevelopmentSetup.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,32 @@ Not removing this data will prevent you from running the Django Admin Account st
sudo rm -rf pgdata/
```

## Troubleshooting
## Enable live code editing

By default changes to the Python code are not reflected in the running version until
`bin/shutdown.sh` followed by `bin/boot.sh`. This is because the Python in `web`
is copied inside the Docker image at build time.

It is possible to configure the setup locally such that edits to the Python files
in `web` are shared with the running containers immediately. Add a file, alongside
`docker-compose.yml`, called `docker-compose.override.yml` with the following contents:

```yml
version: '3'

services:
web:
environment:
- DEBUG=true
volumes:
- ./web:/usr/src/app
- webdata:/static
```

If you are having problems connecting to the localhost with an obscure error code, try
add the ``DEBUG=True`` variable to your ``.env`` file. This will provide a better
error message to help you debug the problem.
This file is automatically registered by `docker-compose` and overrides the default
production configuration. **Do not add this file to the version control system!**.

## Troubleshooting

An error about invalid credentials could be caused by persisting data from a previous
time you have looked at this repo. To clear any persisting data, run the shutdown script.
Expand Down
20 changes: 18 additions & 2 deletions bin/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,27 @@ fi

# Create empty directories, so they are not owned by root
mkdir -p "$SOURCE_DIR/pgdata"
mkdir -p "$SOURCE_DIR/webdata"

# Start external network
create_external_net
# Build services
docker-compose --project-name ${PROJECT_NAME} build
# Bring up the stack and detach
docker-compose --project-name ${PROJECT_NAME} up -d
docker-compose --project-name ${PROJECT_NAME} up --detach

# Replace this loop with `--wait-timeout` when it is available
# with 'docker compose' v2
sleep_counter=0
while [ $(docker-compose ps --quiet --filter status=running | wc -l | xargs) -ne 4 ]
do
sleep 1
let counter++
if [[ $counter -eq 30 ]]; then
echo "Services have not come up to a running state."
exit 1
fi
echo "Waiting for all services to be running."
done


echo "Services up and running."
3 changes: 1 addition & 2 deletions bin/shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ docker-compose down
# the web data volume shouldn't really be persistent as all of the files
# come from an image
echo "Removing webdata volume so it is rebuilt on next startup"
rm -r "${SOURCE_DIR}/webdata"
docker volume rm errorreports_webdata
docker volume rm ${PROJECT_NAME}_webdata

echo "Removing external network nginx_net"
docker network rm nginx_net
11 changes: 4 additions & 7 deletions blank.env
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# Default config
DB_NAME=django
DEBUG=false
HOST_PORT=8083

# Django settings. Passwords are in the password management tool
DB_NAME=django
# Generate with pwgen -s 32 1
SECRET_KEY=<Not Set>

# These are located in the password management tool
DB_USER=<Not Set>
DB_PASS=<Not Set>

DB_SERVICE=postgres
DB_PORT=5432

# Can be found Slack settings
SLACK_WEBHOOK_URL=<Not Set>

HOST_PORT=8083
SLACK_ERROR_REPORTS_CHANNEL=#error-reports
SLACK_ERROR_REPORTS_USERNAME="Error Reporter"
SLACK_ERROR_REPORTS_EMOJI=:sadmantid:
Expand Down
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
restart: always
build: ./web
volumes:
- webdata:/usr/src/app
- webdata:/static
expose:
# Change the value in the nginx configuration if this is changed
- "8000"
Expand All @@ -46,9 +46,6 @@ services:
SECRET_KEY: ${SECRET_KEY}
# Define this in .env for development mode. DO NOT USE IN PRODUCTION
DEBUG: ${DEBUG}
MAIL_PASS: ${MAIL_PASS}
MAIL_PORT: ${MAIL_PORT}
ERROR_EMAIL: ${ERROR_EMAIL}

nginx-errorreports:
restart: always
Expand All @@ -57,7 +54,7 @@ services:
ports:
- "${HOST_PORT}:80"
volumes:
- webdata:/usr/src/app
- webdata:/static
networks:
- default
- nginx_net
Expand All @@ -66,6 +63,7 @@ volumes:
# This allows Nginx to serve static content, as Django won't...
webdata:


networks:
nginx_net:
external: true
2 changes: 1 addition & 1 deletion nginx/sites-enabled/errorreports
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ server {
}

location /static {
alias /usr/src/app/static;
root /;
}

location / {
Expand Down
Loading