Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*
!*.sh
!*.py
!Pipfile
!Pipfile.lock
!pyproject.toml
!uv.lock
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# VOKO Development Environment Variables
# Copy this file to .env and modify as needed

# Database configuration
POSTGRES_NAME=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=db

# Django settings
DJANGO_SETTINGS_MODULE=vokou.settings.development

# Auto-created superuser configuration
[email protected]
DJANGO_SUPERUSER_FIRST_NAME=Admin
DJANGO_SUPERUSER_LAST_NAME=User
DJANGO_SUPERUSER_PASSWORD=admin123
19 changes: 7 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
---
name: Deployment
name: CI
on:
push:
branches:
- feature/*
- develop
- release/*
- master
pull_request:
types: [opened, synchronize, reopened]

jobs:
tests:
Expand All @@ -19,11 +15,10 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: '3.8'
- name: Install pipenv
run: python -m pip install --upgrade pipenv wheel
- name: Install uv
run: python -m pip install --upgrade uv
- name: Install dependencies
run: pipenv install --system --dev
run: uv sync --dev
- name: Run tests
working-directory: webapp
run: |
./runtests.sh
run: uv run python manage.py test --settings=vokou.settings.testing
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,31 @@ ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
ENV TZ="Europe/Amsterdam"

# Install pipenv
RUN pip install pipenv
# Install system dependencies including PostgreSQL client and timezone data
RUN apt-get update && apt-get install -y \
postgresql-client \
tzdata \
&& rm -rf /var/lib/apt/lists/*

# Configure timezone
RUN ln -snf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime && echo Europe/Amsterdam > /etc/timezone

# Install uv
RUN pip install uv

# Set work directory
WORKDIR /code

# Copy dependencies & files
COPY ./Pipfile /code/
COPY ./pyproject.toml /code/

ARG CACHEBUST=1
# Recreate lock file
RUN pipenv lock
RUN uv lock
# Install dependencies
RUN pipenv install --dev
RUN uv sync --dev

# Install application into container
COPY . .
Expand Down
117 changes: 117 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
.PHONY: help setup build up down restart logs logs-web logs-db shell db-shell clean test migrate superuser runserver validate reset

# Default target
help:
@echo "VOKO Development Environment"
@echo "============================"
@echo "Available commands:"
@echo " setup - Complete setup of development environment (recommended)"
@echo " build - Build Docker images"
@echo " up - Start all services"
@echo " down - Stop all services"
@echo " restart - Restart all services"
@echo " logs - View all logs"
@echo " logs-web - View web application logs"
@echo " logs-db - View database logs"
@echo " shell - Access web container shell"
@echo " db-shell - Access database shell"
@echo " clean - Clean up containers and volumes"
@echo " test - Run tests"
@echo " migrate - Run database migrations"
@echo " superuser - Create Django superuser"
@echo " validate - Validate setup is working correctly"
@echo " reset - Reset database (WARNING: deletes all data)"

# Complete setup - simplified one-command setup
setup:
@echo "Starting VOKO development environment..."
@echo "This will build and start all services with automatic setup."
docker-compose up --build

# Build Docker images
build:
docker-compose build

# Start services
up:
docker-compose up -d

# Stop services
down:
docker-compose down

# Restart services
restart:
docker-compose restart

# View logs
logs:
docker-compose logs -f

# View web logs
logs-web:
docker-compose logs -f web

# View database logs
logs-db:
docker-compose logs -f db

# Access web container shell
shell:
docker exec -it voko_web bash

# Access database shell
db-shell:
docker exec -it voko_db psql -U postgres

# Clean up
clean:
docker-compose down -v
docker system prune -f

# Run tests
test:
docker exec voko_web uv run python manage.py test --settings=vokou.settings.testing

# Run migrations
migrate:
docker exec voko_web uv run python manage.py makemigrations --settings=vokou.settings.development
docker exec voko_web uv run python manage.py migrate --settings=vokou.settings.development

# Create superuser
superuser:
docker exec -it voko_web uv run python manage.py createsuperuser --noinput --settings=vokou.settings.development

# Run crons
crons:
docker exec voko_web uv run python manage.py runcrons --settings=vokou.settings.development

# Start development server (if not using docker-compose)
runserver:
docker exec voko_web uv run python manage.py runserver 0.0.0.0:8000 --settings=vokou.settings.development

# Reset database (WARNING: deletes all data)
reset:
@echo "WARNING: This will delete all data!"
@read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker-compose down -v; \
docker-compose up --build; \
else \
echo "Reset cancelled."; \
fi

# Flush sqlite database (if using sqlite)
flush:
@echo "Flushing SQLite database..."
uv run python webapp/manage.py flush --no-input --settings=vokou.settings.development

flush-docker:
@echo "Flushing SQLite database in Docker..."
docker exec voko_web uv run python manage.py flush --no-input --settings=vokou.settings.development

# start webapp
start-webapp:
@echo "Starting web application..."
uv run python webapp/manage.py runserver --settings=vokou.settings.development
127 changes: 85 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,102 @@ Django based custom web application for food collective www.vokoutrecht.nl.


# Development environment using Docker
### Get the code
1. Run: `git clone https://github.com/VOKO-Utrecht/voko.git`
2. Run: cd voko

### Initiate the database
1. Run: docker-compose up db
2. Wait until db is ready to accept connections
3. Press CTRL-C to stop the db container again
_first time postgress restarts which confuses Django_

### Start voko website and run migrations
1. Run: docker-compose up -d
2. Run: docker exec -it voko_web_1 bash
3. Run: ./manage.py makemigrations --settings=vokou.settings.development
4. Run: ./manage.py migrate --settings=vokou.settings.development
5. Run: exit

### Create superuser in the voko web container
1. Run: docker exec -it voko_web_1 bash
2. Run: ./manage.py createsuperuser --settings=vokou.settings.development
3. _follow the prompts_
4. Run: exit

In your browser go to: http://127.0.0.1:8000/admin/ordering/orderround/

Login as the super user just created \
Use the admin site to create an order round (otherwise you get an ugly error going to the main site --FIXTHIS)

### Quick Setup (Recommended)
**Option 1: Using make (if you have make installed)**
```bash
git clone https://github.com/VOKO-Utrecht/voko.git
cd voko
make setup
```

**Option 2: Using docker-compose directly**
```bash
git clone https://github.com/VOKO-Utrecht/voko.git
cd voko
docker-compose up
```

Then:
4. Wait for the setup to complete (you'll see "Starting development server...")
5. Go to: http://127.0.0.1:8000
6. Login with: `[email protected]` / `admin123`

That's it! The setup automatically:
- Creates and initializes the database
- Runs all migrations
- Creates a superuser account if it does not exist
- Starts the development server

You can also visit the main site at: http://127.0.0.1:8000/

### Common Commands
If you have make installed, you can use these convenient commands:
- `make setup` - Complete setup (build and start)
- `make up` - Start services
- `make down` - Stop services
- `make logs` - View logs
- `make shell` - Access Django shell
- `make test` - Run tests
- `make validate` - Check if setup is working
- `make reset` - Reset database (deletes all data)
- `make help` - Show all available commands

#### Customizing the auto-setup
You can customize the automatically created superuser by setting environment variables:
- `DJANGO_SUPERUSER_EMAIL` (default: [email protected])
- `DJANGO_SUPERUSER_FIRST_NAME` (default: Admin)
- `DJANGO_SUPERUSER_LAST_NAME` (default: User)
- `DJANGO_SUPERUSER_PASSWORD` (default: admin123)

For convenience, you can copy `.env.example` to `.env` and modify the values there:
```bash
cp .env.example .env
# Edit .env file with your preferred values
```

Or set them directly when starting:
```bash
[email protected] DJANGO_SUPERUSER_PASSWORD=mypassword docker-compose up
```

### Troubleshooting
- If you get database connection errors, make sure the database is fully started by running `docker-compose up db` first, waiting for it to be ready, then stopping it and running `docker-compose up` again.
- If you need to reset the database, run: `docker-compose down -v` (this will delete all data)
- To access the Django shell: `docker exec -it voko_web bash` then `./manage.py shell --settings=vokou.settings.development`
- To view logs: `docker-compose logs web` or `docker-compose logs db`
- To validate your setup is working: `./validate_setup.sh`

## What's New in This Setup?
This improved Docker setup includes:
- **Automated superuser creation**: No need to manually create admin accounts
- **Automatic sample data creation**: Creates a sample supplier and order round
- **One-command setup**: Just run `docker-compose up` or `make setup`
- **Health checks**: Ensures database is ready before starting the web server
- **Validation script**: Check if everything is working correctly
- **Convenient Make commands**: Easy-to-use shortcuts for common tasks
- **Environment variable support**: Customize superuser credentials and other settings
- **Better error handling**: More robust startup process


# Development environment without Docker
1. Run: pip install --user pipenv
1. Run: pip install --user uv
2. Run: `git clone https://github.com/VOKO-Utrecht/voko.git`
3. Run: `cd voko`
4. Run: `pipenv install --dev`
5. Run: `pipenv shell`
6. In vokou/settings/development.py: \
- Uncomment config for sqlite3 \
- Comment the config for postgresql
4. Run: `uv sync --dev`
6. Run: `cd webapp`


### Set up sqlite database
cd webapp
./manage.py migrate --settings=vokou.settings.development
./manage.py createsuperuser --settings=vokou.settings.development
### Set up sqlite database, create superuser and automatically create first order round
uv run python manage.py makemigrations --settings=vokou.settings.development
uv run python manage.py migrate --settings=vokou.settings.development
uv run python manage.py createsuperuser --settings=vokou.settings.development
uv run python manage.py runcrons --force --settings=vokou.settings.development

### Run tests
cd webapp
./runtests.sh
uv run python manage.py test --settings=vokou.settings.testing

### Run development server
cd webapp
./manage.py runserver --settings=vokou.settings.development
uv run python manage.py runserver --settings=vokou.settings.development

### Adding user
1. Register as new user at: http://localhost:8000/accounts/register/
Expand Down
Loading