Skip to content

Commit

Permalink
Overhaul setup instructions
Browse files Browse the repository at this point in the history
Should make onboarding easier.
  • Loading branch information
francoisfreitag committed Jan 24, 2025
1 parent dfd7752 commit 0635221
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 46 deletions.
13 changes: 7 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ DEBUG=False
MOCK_EXTERNAL_API=True
HOST_PROTO=http

DATABASE_NAME=postgres
DATABASE_NAME=giw
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DATABASE_PASSWORD=chummy
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_URL=postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}

S3_HOST=
S3_KEY_ID=
S3_KEY_SECRET=
S3_BUCKET_NAME=
S3_HOST=localhost:9000
S3_KEY_ID=minioadmin
S3_KEY_SECRET=minioadmin
S3_BUCKET_NAME=giw-dev
S3_BUCKET_REGION=eu-west-3
S3_PROTOCOL=http
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
uses: astral-sh/setup-uv@v5
- name: Setup virtual environment
run: |
uv venv venv
echo "venv/bin" >> $GITHUB_PATH
uv venv
echo ".venv/bin" >> $GITHUB_PATH
- name: 🌍 Install dependencies
run: uv pip sync requirements.txt
- name: 📄 Copy empty .env.test to .env
Expand All @@ -38,7 +38,7 @@ jobs:
- name: 🚧 Check pending migrations
run: |
django-admin makemigrations --check --dry-run --noinput
- name: 🤹Run the unit tests
- name: 🤹Run the unit tests
run: |
make test-unit
env:
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ test: test-e2e test-unit

.PHONY: quality
quality:
$(EXEC_CMD) black --check --exclude=venv .
$(EXEC_CMD) isort --check --skip-glob="**/migrations" --extend-skip-glob="venv" .
$(EXEC_CMD) flake8 --count --show-source --statistics --exclude=venv .
$(EXEC_CMD) black --check --exclude=.venv .
$(EXEC_CMD) isort --check --skip-glob="**/migrations" --extend-skip-glob=".venv" .
$(EXEC_CMD) flake8 --count --show-source --statistics --exclude=.venv .

.PHONY: fix
fix:
$(EXEC_CMD) black --exclude=venv .
$(EXEC_CMD) isort --skip-glob="**/migrations" --extend-skip-glob="venv" .
$(EXEC_CMD) black --exclude=.venv .
$(EXEC_CMD) isort --skip-glob="**/migrations" --extend-skip-glob=".venv" .
$(EXEC_CMD) djhtml $(shell find templates -name "*.html")
$(EXEC_CMD) flake8 --exclude=venv .
$(EXEC_CMD) flake8 --exclude=.venv .
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
## Prérequis

- Python [(version)](./python-version)
- Postgreql 14.x.
- [docker](https://docs.docker.com/get-started/get-docker/)
- [docker-compose](https://docs.docker.com/compose/install/)
- [uv](https://docs.astral.sh/uv/getting-started/installation/)

## Installer les pre-commit hooks

```
```sh
pre-commit install
```

On peut faire un premier test en faisant tourner :

```
```sh
pre-commit run --all-files
```

Expand All @@ -23,42 +25,54 @@ Le projet peut se lancer en local ou avec Docker.

### En local

#### Créer un environnement virtuel
#### Lancer les containers

```sh
docker-compose up
```

#### Définir les variables d'environnement

```sh
cp .env.example .env
$EDITOR .env
```

#### Créer un environnement virtuel

```sh
# Configurer et activer l'environnement virtuel
python -m venv venv
. venv/bin/activate
pip install uv
uv venv
. .venv/bin/activate
uv pip sync --require-hashes requirements.txt
```

#### Copier les variables d'environnement

```
```sh
cp .env.example .env
```

#### Lancer le serveur
#### Configurer le bucket

```sh
python manage.py configure_bucket
```

#### Lancer le serveur

```sh
python manage.py runserver
```

#### Lancer les migrations

```
```sh
python manage.py migrate
```

#### Effectuer les tests

D'abord installer les dépendances de test :

```sh
pip install -r requirements.txt
```

Les tests unitaires peuvent être lancés avec `make test-units`, les
tests E2E avec `make test-e2e`, les deux avec `make test`.

Expand All @@ -79,20 +93,6 @@ coverage run manage.py test --settings config.settings_test
uv pip compile --generate-hashes requirements.in -o requirements.txt
```

### via Docker

#### Copier les variables d'environnement

```sh
cp .env.example .env
```

#### Lancer les containers

```sh
docker-compose up
```

### Premier lancement

Pour initialiser le site avec notamment la page d'accueil au bon format :
Expand Down
1 change: 1 addition & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"markdownify",
"cms",
"services",
"files",
]

MIDDLEWARE = [
Expand Down
17 changes: 16 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
- postgres_data:/var/lib/postgresql/data

web:
profiles: ["web"]
build: .
environment:
DATABASE_URL: postgres://postgres:chummy@db:5432/giw
Expand All @@ -21,5 +22,19 @@ services:
depends_on:
- db

minio:
image: bitnami/minio
container_name: giw_minio
restart: unless-stopped
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
ports:
- "127.0.0.1:9000:9000"
- "127.0.0.1:9001:9001"
volumes:
- giw_minio:/bitnami/minio/data

volumes:
postgres_data:
postgres_data:
giw_minio:
Empty file added files/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions files/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class FilesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "files"
Empty file added files/management/__init__.py
Empty file.
Empty file.
39 changes: 39 additions & 0 deletions files/management/commands/configure_bucket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

import boto3
from django.conf import settings
from django.core.management import BaseCommand


class Command(BaseCommand):
def handle(self, *args, **options):
client = boto3.client(
"s3",
endpoint_url=settings.AWS_S3_ENDPOINT_URL,
aws_access_key_id=settings.AWS_S3_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_S3_SECRET_ACCESS_KEY,
region_name=settings.AWS_S3_STORAGE_BUCKET_REGION,
)
bucket = settings.AWS_STORAGE_BUCKET_NAME
try:
client.create_bucket(Bucket=bucket)
except client.exceptions.BucketAlreadyOwnedByYou:
pass

client.put_bucket_policy(
Bucket=bucket,
Policy=json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:GetObject",
"Resource": f"arn:aws:s3:::{bucket}/*",
},
],
}
),
)

0 comments on commit 0635221

Please sign in to comment.