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

Rename api to backend #963

Merged
merged 3 commits into from
Mar 27, 2024
Merged
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
32 changes: 16 additions & 16 deletions .github/workflows/api_pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: API Pipeline
name: Backend Pipeline

on:
push:
branches:
- '*'
- 'main'
paths:
- 'api/**.py'
- 'api/requirements*.*'
- 'backend/**.py'
- 'backend/requirements*.*'
- 'docker/dockerfiles/Dockerfile.backend*'
- 'docker-compose.yml'
- '.github/workflows/api_pipeline.yml'
- '.github/workflows/backend_pipeline.yml'
pull_request:
branches:
- 'main'
paths:
- 'api/**.py'
- 'api/requirements*.*'
- 'backend/**.py'
- 'backend/requirements*.*'
- 'docker/dockerfiles/Dockerfile.backend*'
- 'docker-compose.yml'
- '.github/workflows/api_pipeline.yml'
- '.github/workflows/backend_pipeline.yml'

jobs:

Expand All @@ -39,11 +39,11 @@ jobs:

- name: Install Black with latest pip
run: |
cat ./api/requirements-dev.txt | grep black== | cut -d' ' -f1 | xargs pip install
cat ./backend/requirements-dev.txt | grep black== | cut -d' ' -f1 | xargs pip install

- name: Check formatting with Black
run: |
black --check ./api
black --check ./backend

linting_with_ruff:
name: Run Ruff linting check
Expand All @@ -61,11 +61,11 @@ jobs:

- name: Install Black & Ruff with latest pip
run: |
cat ./api/requirements-dev.txt | grep ruff== | cut -d' ' -f1 | xargs pip install
cat ./backend/requirements-dev.txt | grep ruff== | cut -d' ' -f1 | xargs pip install

- name: Lint files using Ruff
run: |
ruff check ./api
ruff check ./backend

checking_migrations:
name: Check for migrations
Expand All @@ -83,17 +83,17 @@ jobs:

- name: Install dependencies
run: |
pip install -r ./api/requirements-dev.txt
pip install -r ./backend/requirements-dev.txt

- name: Check for migrations
run: |
set -a
. ./.env.example.dev
python ./api/manage.py makemigrations --check --dry-run
python ./backend/manage.py makemigrations --check --dry-run
set +a

tests:
name: Run api tests
name: Run backend tests
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
Expand All @@ -107,8 +107,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./api/requirements-dev.txt
pip install -r ./backend/requirements-dev.txt

- name: Run tests
run: |
ENVIRONMENT=test DJANGO_SETTINGS_MODULE=seismic_site.settings.test ./api/manage.py test
ENVIRONMENT=test DJANGO_SETTINGS_MODULE=seismic_site.settings.test ./backend/manage.py test
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ on:
pull_request:
branches: [develop]
paths:
- 'api/**.py'
- 'api/requirements*.*'
- 'backend/**.py'
- 'backend/requirements*.*'
- 'docker/dockerfiles/Dockerfile.backend*'
- 'docker-compose.yml'
- '.github/workflows/api_pipeline.yml'
- '.github/workflows/backend_pipeline.yml'
- '.github/workflows/code-analysis-py.yml'

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
api/static/*
api/public/*
backend/public/*
backend/static/*

# dotenv environment variables file
.env
Expand Down
46 changes: 23 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,29 @@ logs-prod: ## show the logs of the containers

## [Django operations]
makemigrations: ## generate migrations in a clean container
docker exec seismic_backend_dev sh -c "python3 -Wd ./api/manage.py makemigrations $(apps)"
docker exec seismic_backend_dev sh -c "python3 -Wd ./backend/manage.py makemigrations $(apps)"

migrate: ## apply migrations in a clean container
docker exec seismic_backend_dev sh -c "python3 -Wd ./api/manage.py migrate $(apps)"
docker exec seismic_backend_dev sh -c "python3 -Wd ./backend/manage.py migrate $(apps)"

migrations: makemigrations migrate ## generate and apply migrations

makemessages: ## generate the strings marked for translation
docker exec seismic_backend_dev sh -c "python3 -Wd ./api/manage.py makemessages -a"
docker exec seismic_backend_dev sh -c "python3 -Wd ./backend/manage.py makemessages -a"

compilemessages: ## compile the translations
docker exec seismic_backend_dev sh -c "python3 -Wd ./api/manage.py compilemessages"
docker exec seismic_backend_dev sh -c "python3 -Wd ./backend/manage.py compilemessages"

messages: makemessages compilemessages ## generate and compile the translations

collectstatic: ## collect the static files
docker exec seismic_backend_dev sh -c "python3 -Wd ./api/manage.py collectstatic --no-input"
docker exec seismic_backend_dev sh -c "python3 -Wd ./backend/manage.py collectstatic --no-input"

format: ## format the code with black & ruff
docker exec seismic_backend_dev sh -c "black ./api && ruff check --fix ./api"
docker exec seismic_backend_dev sh -c "black ./backend && ruff check --fix ./backend"

pyshell: ## start a django shell
docker exec -it seismic_backend_dev sh -c "python3 -Wd ./api/manage.py shell"
docker exec -it seismic_backend_dev sh -c "python3 -Wd ./backend/manage.py shell"

sh: ## start a sh shell
docker exec -it seismic_backend_dev sh -c "sh"
Expand Down Expand Up @@ -171,10 +171,10 @@ requirements-update: ## run pip compile and rebuild the requirement

## [Tests]
tests: ## run the tests
docker exec seismic_backend_dev sh -c "cd ./api && pytest -Wd $(apps)"
docker exec seismic_backend_dev sh -c "cd ./backend && pytest -Wd $(apps)"

tests-cover: ## run the tests with coverage
docker exec seismic_backend_dev sh -c "cd ./api && pytest -Wd --cov --cov-report=xml --cov-report=term-missing --cov-fail-under=60 $(apps)"
docker exec seismic_backend_dev sh -c "cd ./backend && pytest -Wd --cov --cov-report=xml --cov-report=term-missing --cov-fail-under=60 $(apps)"


## [Clean-up]
Expand All @@ -184,25 +184,25 @@ clean-docker: ## stop docker containers and remove orphaned
docker system prune -f

clean-extras: ## remove test, coverage, file artifacts, and compiled message files
find ./api -name '*.mo' -delete
find ./api -name '*.pyc' -delete
find ./api -name '*.pyo' -delete
find ./api -name '.coverage' -delete
find ./api -name '.pytest_cache' -delete
find ./api -name '.ruff_cache' -delete
find ./api -name '__pycache__' -delete
find ./api -name 'htmlcov' -delete
find ./backend -name '*.mo' -delete
find ./backend -name '*.pyc' -delete
find ./backend -name '*.pyo' -delete
find ./backend -name '.coverage' -delete
find ./backend -name '.pytest_cache' -delete
find ./backend -name '.ruff_cache' -delete
find ./backend -name '__pycache__' -delete
find ./backend -name 'htmlcov' -delete

clean-db: ## remove the database files
rm -rf ./api/media ./api/static ./frontend/dist
rm -rf ./backend/media ./backend/static ./frontend/dist

clean: clean-docker clean-extras clean-db ## remove all build, test, coverage and Python artifacts


## [Project-specific operations]
mock-data: ## generate fake data
docker exec seismic_backend_dev python3 -Wd ./api/manage.py generate_editions 5
docker exec seismic_backend_dev python3 -Wd ./api/manage.py generate_users 20 --type U
docker exec seismic_backend_dev python3 -Wd ./api/manage.py generate_projects 40
docker exec seismic_backend_dev python3 -Wd ./api/manage.py generate_marketplace 10
docker exec seismic_backend_dev python3 -Wd ./api/manage.py generate_users 2 --type J
docker exec seismic_backend_dev python3 -Wd ./backend/manage.py generate_editions 5
docker exec seismic_backend_dev python3 -Wd ./backend/manage.py generate_users 20 --type U
docker exec seismic_backend_dev python3 -Wd ./backend/manage.py generate_projects 40
docker exec seismic_backend_dev python3 -Wd ./backend/manage.py generate_marketplace 10
docker exec seismic_backend_dev python3 -Wd ./backend/manage.py generate_users 2 --type J
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ you can use [Google's style guide](http://google.github.io/styleguide/pyguide.ht

### Frameworks

**API:** [Django](https://www.djangoproject.com)
**Backend:** [Django](https://www.djangoproject.com)
**Client:** [React](https://reactjs.org/)

### Package managers

**API:** [pip](https://pypi.org/)
**Backend:** [pip](https://pypi.org/)
**Client:** [npm](https://www.npmjs.com/)

### Code styling

**API:** [Black](https://black.readthedocs.io/en/stable/)
**Backend:** [Black](https://black.readthedocs.io/en/stable/)
**Client:** [Prettier](https://prettier.io/) + [ESLint](https://eslint.org/) + [Airbnb style guide](https://github.com/airbnb/javascript)

### Database technology & provider
Expand All @@ -149,7 +149,7 @@ you can use [Google's style guide](http://google.github.io/styleguide/pyguide.ht

## Getting started

Risc Seismic API is a Django application, built on top of Python 3.9+ with a PostgreSQL database. The Client is a React
Risc Seismic backend is a Django application, built on top of Python 3.9+ with a PostgreSQL database. The Client is a React
single page application.

### Pre-requisites
Expand Down Expand Up @@ -235,7 +235,7 @@ docker-compose exec api ./manage.py createsuperuser

#### Deployment variables

The following variables change the way the API is deployed.
The following variables change the way the backend is deployed.

`RUN_MIGRATIONS`
Run the initial migrations (sets up the data models from the database).
Expand Down Expand Up @@ -331,7 +331,7 @@ make help
```shell
python -m venv .venv
.venv\Scripts\activate.bat
pip install -r ./api/requirements-dev.txt
pip install -r ./backend/requirements-dev.txt
copy .env.dev .env
```

Expand All @@ -348,27 +348,27 @@ make help
4. Check database connection. If this fails double check database configuration.

```shell
python api/wait_for_db.py
python backend/wait_for_db.py
```

5. Run migrations:

```shell
python api/manage.py migrate --no-input
python backend/manage.py migrate --no-input
```

6. Create admin user (user to login into admin panel):

```shell
python api/manage.py createsuperuser
python backend/manage.py createsuperuser
```

7. Load dummy data in database:

```shell
python api/manage.py loaddata statistics
python api/manage.py loaddata buildings
python api/manage.py loaddata pages
python backend/manage.py loaddata statistics
python backend/manage.py loaddata buildings
python backend/manage.py loaddata pages
```

8. Install node modules.
Expand All @@ -380,14 +380,14 @@ make help

#### Steps needed to start development servers

*1. Start API server.*
*1. Start backend server.*

Open terminal in the project directory and run environment activation script, then start the server.

```shell
.venv\Scripts\activate.bat
activate_dev_env.bat
python api\manage.py runserver 0.0.0.0:8030
python backend\manage.py runserver 0.0.0.0:8030
```

Check functionality at http://localhost:8030 you should get a 404 page.
Expand Down Expand Up @@ -499,7 +499,7 @@ make test
To get the container ready for production use, we need to first build it:

```shell
docker build -t seismic-risc:latest ./api
docker build -t seismic-risc:latest ./backend
```

Use the `prod.env.dist` template file and create a `prod.env` file with the correct environment variables and run like
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
context: .
dockerfile: ./docker/dockerfiles/Dockerfile.backend
volumes:
- ./api/media:/var/www/seismic/api/media
- ./backend/media:/var/www/seismic/backend/media
depends_on:
- db

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
context: .
dockerfile: ./docker/dockerfiles/Dockerfile.backend.dev
volumes:
- ./api:/var/www/seismic/api
- ./backend:/var/www/seismic/backend
depends_on:
- db

Expand Down
6 changes: 3 additions & 3 deletions docker/dockerfiles/Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN python3 -m venv ${VIRTUAL_ENV}
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"

WORKDIR /build
COPY ./api/requirements.txt ./api/pyproject.toml ./
COPY ./backend/requirements.txt ./backend/pyproject.toml ./
RUN python3 -m pip install --upgrade pip setuptools && \
python3 -m pip install -r ./requirements.txt

Expand Down Expand Up @@ -68,8 +68,8 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# copy the backend source code and libraries from the build stage:
COPY --from=build "${VIRTUAL_ENV}" "${VIRTUAL_ENV}"

WORKDIR /var/www/seismic/api/
COPY ./api .
WORKDIR /var/www/seismic/backend/
COPY ./backend .

# Make sure scripts in .local are usable:
ENV PATH=/root/.local/bin:$PATH
Expand Down
6 changes: 3 additions & 3 deletions docker/dockerfiles/Dockerfile.backend.dev
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH"


# install the backend libraries:
COPY ./api/pyproject.toml ./api/requirements-dev.txt /var/www/seismic/api/
WORKDIR /var/www/seismic/api/
COPY ./backend/pyproject.toml ./backend/requirements-dev.txt /var/www/seismic/backend/
WORKDIR /var/www/seismic/backend/
RUN python3 -m pip install --upgrade pip setuptools && \
python3 -m pip install -r ./requirements-dev.txt

# Copy the back-end source code and install the backend libraries:
COPY ./api/ .
COPY ./backend/ .

# Make sure scripts in .local are usable:
ENV PATH=/root/.local/bin:$PATH
Expand Down
2 changes: 1 addition & 1 deletion docker/s6-rc.d/api/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/command/with-contenv sh
cd /var/www/seismic/api/ || exit 1
cd /var/www/seismic/backend/ || exit 1

# if ENVIRONMENT="production", then run with gunicorn
if [ "${ENVIRONMENT}" = "production" ]; then
Expand Down
2 changes: 1 addition & 1 deletion docker/s6-rc.d/init/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ is_enabled() {
fi
}

cd "${BACKEND_ROOT:-/var/www/seismic/api}" || exit 1
cd "${BACKEND_ROOT:-/var/www/seismic/backend}" || exit 1

echo "Running Django self-checks"
python3 manage.py check
Expand Down
2 changes: 1 addition & 1 deletion docker/s6-rc.d/qcluster/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/command/with-contenv sh
cd /var/www/seismic/api/ || exit 1
cd /var/www/seismic/backend/ || exit 1

python3 manage.py qcluster
Loading