Skip to content

Commit

Permalink
Simplify Docker development setup with minimal configuration
Browse files Browse the repository at this point in the history
- Remove Redis, queue workers, and scheduler from development environment
- Update docker-compose.dev.yml with simplified service configurations
- Modify Dockerfile.api to support flexible dependency installation
- Update docker-setup.sh script to use single compose file
- Revise Docker development documentation to reflect new lightweight approach
  • Loading branch information
JhumanJ committed Jan 29, 2025
1 parent f7df6bc commit 44a4b98
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 80 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
push: true
build-args: |
APP_ENV=${{ env.VERSION == 'dev' && 'local' || 'production' }}
COMPOSER_FLAGS=${{ env.VERSION == 'dev' && '--optimize-autoloader --no-interaction' || '--no-dev --optimize-autoloader --no-interaction' }}
tags: ${{ env.API_TAGS }}
cache-from: type=registry,ref=${{secrets.DOCKER_API_REPO}}:dev
cache-to: type=inline
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ For a complete list of features and detailed documentation, visit our [Technical

The easiest way to get started with OpnForm is through our [official managed service in the Cloud](https://opnform.com/).

For self-hosted installations, please refer to our [Deployment Guides](https://docs.opnform.com/deployment). For detailed instructions on setting up a local environment, check out our [Local Deployment Documentation](https://docs.opnform.com/deployment/local-deployment).
For self-hosted installations, please refer to our [Deployment Guides](https://docs.opnform.com/deployment). For local development, we provide a minimal Docker-based setup - check out our [Docker Development Guide](https://docs.opnform.com/deployment/docker-development).

## Support & Community

Expand Down
69 changes: 34 additions & 35 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
version: "3.8"

services:
api: &api-base
api:
image: jhumanj/opnform-api:dev
container_name: opnform-api
build:
context: .
dockerfile: docker/Dockerfile.api
args:
- APP_ENV=local
volumes: &api-base-volumes
APP_ENV: local
COMPOSER_FLAGS: ""
volumes:
- ./api:/usr/share/nginx/html:delegated
- /usr/share/nginx/html/vendor # Exclude vendor directory from the mount
- ./api/storage:/usr/share/nginx/html/storage:delegated
environment: &api-base-env
environment:
APP_ENV: local
APP_DEV_CORS: "true"
IS_API_WORKER: "false"
APP_DEBUG: true
APP_DEV_CORS: true
# Database settings
DB_HOST: db
REDIS_HOST: redis
DB_DATABASE: ${DB_DATABASE:-forge}
DB_USERNAME: ${DB_USERNAME:-forge}
DB_PASSWORD: ${DB_PASSWORD:-forge}
DB_CONNECTION: ${DB_CONNECTION:-pgsql}
# Override production settings for minimal setup
CACHE_DRIVER: file
SESSION_DRIVER: file
QUEUE_CONNECTION: sync
# Storage settings
FILESYSTEM_DISK: local
LOCAL_FILESYSTEM_VISIBILITY: public
Expand All @@ -34,33 +40,6 @@ services:
depends_on:
db:
condition: service_healthy
redis:
condition: service_started

api-worker:
<<: *api-base
container_name: opnform-api-worker
command: ["php", "artisan", "queue:work"]
volumes: *api-base-volumes
environment:
<<: *api-base-env
APP_ENV: local
IS_API_WORKER: "true"

api-scheduler:
<<: *api-base
container_name: opnform-api-scheduler
command: ["php", "artisan", "schedule:work"]
volumes: *api-base-volumes
environment:
<<: *api-base-env
APP_ENV: local
IS_API_WORKER: "true"
AUTORUN_ENABLED: "false"
# Scheduler settings
CONTAINER_ROLE: scheduler
PHP_MEMORY_LIMIT: 512M
PHP_MAX_EXECUTION_TIME: 60

ui:
image: jhumanj/opnform-client:dev
Expand Down Expand Up @@ -91,6 +70,23 @@ services:
- "3000:3000" # Main dev server
- "24678:24678" # Vite HMR port

db:
image: postgres:16
container_name: opnform-db
environment:
POSTGRES_DB: ${DB_DATABASE:-forge}
POSTGRES_USER: ${DB_USERNAME:-forge}
POSTGRES_PASSWORD: ${DB_PASSWORD:-forge}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-forge}"]
interval: 5s
timeout: 5s
retries: 5
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data

ingress:
image: nginx:1
container_name: opnform-ingress
Expand All @@ -105,4 +101,7 @@ services:
api:
condition: service_started
ui:
condition: service_started
condition: service_started

volumes:
postgres-data:
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ services:
api: &api-environment
image: jhumanj/opnform-api:latest
container_name: opnform-api
build:
build: &api-build
context: .
dockerfile: docker/Dockerfile.api
args:
- APP_ENV=production
APP_ENV: production
COMPOSER_FLAGS: --no-dev
volumes: &api-environment-volumes
- ./api/storage:/usr/share/nginx/html/storage:rw
- ./api/bootstrap/cache:/usr/share/nginx/html/bootstrap/cache:rw
Expand Down Expand Up @@ -35,6 +36,7 @@ services:
api-worker:
<<: *api-environment
container_name: opnform-api-worker
build: *api-build
command: ["php", "artisan", "queue:work"]
volumes: *api-environment-volumes
environment:
Expand All @@ -47,6 +49,7 @@ services:
api-scheduler:
<<: *api-environment
container_name: opnform-api-scheduler
build: *api-build
command: ["php", "artisan", "schedule:work"]
volumes: *api-environment-volumes
environment:
Expand Down
10 changes: 5 additions & 5 deletions docker/Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ RUN mkdir -p storage/framework/sessions \
COPY api/composer.json api/composer.lock ./
COPY api/app/helpers.php ./app/helpers.php

# Default to production settings unless overridden during build
ARG APP_ENV=production
ARG COMPOSER_FLAGS=--no-dev --optimize-autoloader --no-interaction

# Install dependencies without running scripts
RUN if [ "$APP_ENV" = "production" ] ; then \
composer install --no-dev --no-scripts --ignore-platform-req=php --optimize-autoloader ; \
else \
composer install --no-scripts --ignore-platform-req=php --optimize-autoloader ; \
fi
RUN composer install ${COMPOSER_FLAGS} --no-scripts --ignore-platform-req=php

# Copy the rest of the application
COPY api/ .
Expand Down
66 changes: 34 additions & 32 deletions docs/deployment/docker-development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ import CloudVersion from "/snippets/cloud-version.mdx";

## Overview

OpnForm provides a Docker-based development environment that offers:
- Hot Module Replacement (HMR) for real-time frontend updates
- Vue DevTools integration for debugging
- PHP hot reload for backend changes
- Xdebug support for PHP debugging
- Automatic dependency management
- PostgreSQL database and Redis setup
- Nginx reverse proxy configuration

For details about the Docker architecture and components, see our [Docker Deployment](/deployment/docker) guide.
OpnForm provides a minimal Docker-based development environment optimized for local development. While the full architecture is detailed in our [Docker Deployment](/deployment/docker) guide, the development setup is intentionally lighter and focused on developer experience.

## Prerequisites

Expand Down Expand Up @@ -61,32 +52,43 @@ You will be prompted to change your email and password after your first login.

<Note>Public registration is disabled in the self-hosted version. Use the admin account to invite additional users.</Note>

## Development Features
## Architecture

While the full architecture is detailed in our [Docker Deployment](/deployment/docker) guide, the development setup is intentionally lighter and focused on developer experience.

### Differences from Production

- **No Redis**: Uses file-based caching and sessions instead
- Simpler setup
- No additional service to maintain
- Slightly slower but sufficient for development

- **No Queue Workers**: Uses synchronous job processing
- Jobs run immediately in the main process
- Easier debugging of background tasks
- No need to restart workers after code changes

- **No Scheduler**: Scheduled tasks don't run automatically
- Run scheduled tasks manually when needed
- Less resource usage
- Cleaner logs

### Frontend Development
### Development Features

The development setup includes advanced frontend features:
The development setup includes:

#### Frontend Development
- **Hot Module Replacement (HMR)**: Changes to Vue components and styles are instantly reflected without page reload
- **Vue DevTools**: Full integration for component inspection and state management debugging ([learn more](https://devtools.vuejs.org/))
- **Source Maps**: Enabled for easier debugging
- **Fast Refresh**: Preserves component state during updates
- **Error Overlay**: Displays errors directly in the browser

### Backend Development

The Laravel API service provides:
#### Backend Development
- **PHP Hot Reload**: Changes to PHP files are immediately available
- **Xdebug Integration**: Ready for step-by-step debugging
- **Laravel Telescope**: Available for request and queue monitoring
- **Artisan Commands**: Direct access to Laravel's CLI tools

<Note>
Queue workers require restart after code changes:
```bash
docker compose -f docker-compose.yml -f docker-compose.dev.yml restart api-worker
```
</Note>

### Development URLs

- **Frontend**: http://localhost:3000
Expand Down Expand Up @@ -120,13 +122,13 @@ To run commands in the containers:

```bash
# Laravel Artisan commands
docker compose -f docker-compose.yml -f docker-compose.dev.yml exec api php artisan [command]
docker compose -f docker-compose.dev.yml exec api php artisan [command]

# NPM commands
docker compose -f docker-compose.yml -f docker-compose.dev.yml exec ui npm [command]
docker compose -f docker-compose.dev.yml exec ui npm [command]

# Database commands
docker compose -f docker-compose.yml -f docker-compose.dev.yml exec db psql -U forge
docker compose -f docker-compose.dev.yml exec db psql -U forge
```

### Accessing Logs
Expand All @@ -135,10 +137,10 @@ View container logs:

```bash
# All containers
docker compose -f docker-compose.yml -f docker-compose.dev.yml logs -f
docker compose -f docker-compose.dev.yml logs -f

# Specific container (e.g., frontend)
docker compose -f docker-compose.yml -f docker-compose.dev.yml logs -f ui
docker compose -f docker-compose.dev.yml logs -f ui
```

### Database Access
Expand Down Expand Up @@ -168,10 +170,10 @@ If containers aren't starting properly:
If you encounter permission issues:
```bash
# Fix storage permissions
docker compose -f docker-compose.yml -f docker-compose.dev.yml exec api chmod -R 775 storage
docker compose -f docker-compose.dev.yml exec api chmod -R 775 storage

# Fix vendor permissions
docker compose -f docker-compose.yml -f docker-compose.dev.yml exec api chmod -R 775 vendor
docker compose -f docker-compose.dev.yml exec api chmod -R 775 vendor
```

### HMR Issues
Expand All @@ -180,5 +182,5 @@ If hot reload isn't working:
2. Ensure ports 3000 and 24678 are available
3. Try restarting the UI container:
```bash
docker compose -f docker-compose.yml -f docker-compose.dev.yml restart ui
docker compose -f docker-compose.dev.yml restart ui
```
12 changes: 7 additions & 5 deletions scripts/docker-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ echo -e "${BLUE}Starting OpnForm Docker setup...${NC}"
echo -e "${GREEN}Setting up environment files...${NC}"
bash "$SCRIPT_DIR/setup-env.sh" --docker

# Determine which compose files to use
COMPOSE_FILES="-f docker-compose.yml"
# Determine which compose file to use
if [ "$DEV_MODE" = true ]; then
echo -e "${YELLOW}Development mode enabled - using docker-compose.dev.yml${NC}"
COMPOSE_FILES="$COMPOSE_FILES -f docker-compose.dev.yml"
echo -e "${YELLOW}Development mode enabled - using minimal setup with docker-compose.dev.yml${NC}"
COMPOSE_FILE="docker-compose.dev.yml"
else
echo -e "${YELLOW}Production mode - using docker-compose.yml${NC}"
COMPOSE_FILE="docker-compose.yml"
fi

# Start Docker containers
echo -e "${GREEN}Starting Docker containers...${NC}"
docker compose $COMPOSE_FILES up -d
docker compose -f $COMPOSE_FILE up -d

# Display access instructions
if [ "$DEV_MODE" = true ]; then
Expand Down

0 comments on commit 44a4b98

Please sign in to comment.