From 44a4b983d514ab92983825cd939943bfa5f8c0f0 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Wed, 29 Jan 2025 18:20:19 +0100 Subject: [PATCH] Simplify Docker development setup with minimal configuration - 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 --- .github/workflows/dockerhub.yml | 1 + README.md | 2 +- docker-compose.dev.yml | 69 +++++++++++++------------- docker-compose.yml | 7 ++- docker/Dockerfile.api | 10 ++-- docs/deployment/docker-development.mdx | 66 ++++++++++++------------ scripts/docker-setup.sh | 12 +++-- 7 files changed, 87 insertions(+), 80 deletions(-) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 49c45655..4ab7a210 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -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 diff --git a/README.md b/README.md index d1e4937c..17c70e98 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 1c173ec0..36084769 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -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 @@ -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 @@ -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 @@ -105,4 +101,7 @@ services: api: condition: service_started ui: - condition: service_started \ No newline at end of file + condition: service_started + +volumes: + postgres-data: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 55ffa7ef..8453a4ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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: @@ -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: diff --git a/docker/Dockerfile.api b/docker/Dockerfile.api index 039aa9fc..7a81cd13 100644 --- a/docker/Dockerfile.api +++ b/docker/Dockerfile.api @@ -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/ . diff --git a/docs/deployment/docker-development.mdx b/docs/deployment/docker-development.mdx index bff6f4ef..bb473d60 100644 --- a/docs/deployment/docker-development.mdx +++ b/docs/deployment/docker-development.mdx @@ -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 @@ -61,32 +52,43 @@ You will be prompted to change your email and password after your first login. Public registration is disabled in the self-hosted version. Use the admin account to invite additional users. -## Development Features +## Architecture -### Frontend 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. -The development setup includes advanced frontend features: +### 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 + +### Development 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 - -Queue workers require restart after code changes: -```bash -docker compose -f docker-compose.yml -f docker-compose.dev.yml restart api-worker -``` - - ### Development URLs - **Frontend**: http://localhost:3000 @@ -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 @@ -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 @@ -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 @@ -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 ``` \ No newline at end of file diff --git a/scripts/docker-setup.sh b/scripts/docker-setup.sh index dfb6ee42..1f3b765f 100755 --- a/scripts/docker-setup.sh +++ b/scripts/docker-setup.sh @@ -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