Deployment: Docker
Relevant source files
The following files were used as context for generating this wiki page:
The PriceBuddy application is designed to be deployed using Docker, which is the easiest and recommended installation method. This approach encapsulates the application and its dependencies into a set of containerized services, ensuring a consistent and reproducible environment. The deployment is orchestrated using Docker Compose, which manages the application container, a database, and other required services.
The core of the deployment is a multi-stage Docker build process that compiles frontend assets and installs dependencies in a builder container before creating a lean final application image. This final image includes the Laravel application, a web server (Apache), and a cron daemon for running background tasks, all managed by Supervisor.
Service Architecture
The application's services are defined in docker-compose.yml. While the file itself is not provided in the context, its structure can be inferred from the README.md and container startup scripts. The primary services include the application itself, a database, and Redis for caching/queuing.
The following diagram illustrates the high-level service architecture as orchestrated by Docker Compose.
Sources: README.md:38-41, docker/php/start-app.sh:23-27
Services Overview
Based on the project's documentation and startup scripts, the following services are part of the Docker setup.
| Service | Image | Purpose |
|---|---|---|
app | Custom pricebuddy image | The main Laravel application container, including the Apache web server and cron jobs. |
database | mysql:8.0 | The MySQL database for storing application data. |
redis | redis:alpine | Used for caching and queue management. |
Sources: README.md:38-41, docker/php/start-app.sh:23-27
Docker Image Build Process
The application image is built using a multi-stage Dockerfile to optimize the final image size by excluding build-time dependencies.
Sources: docker/php.dockerfile
This diagram shows the multi-stage build process, starting from a base PHP image, building dependencies and assets in a builder stage, and finally assembling the lean production image.
Sources: docker/base.dockerfile, docker/php.dockerfile
Base Image (base.dockerfile)
The foundation of the application image is jez500/pricebuddy-base, which is built from docker/base.dockerfile. This image starts with a standard php-apache image and adds necessary system packages and PHP extensions.
- OS Packages: Installs
cron,supervisor,zip,unzip,netcat-traditional, and MySQL client tools. - PHP Extensions: Installs
exif,pcntl,posix,mysqli,pdo_mysql,pdo_pgsql,zip, andintl. - Composer: Installs Composer globally.
Sources: docker/base.dockerfile:5-22
Application Image (php.dockerfile)
This file defines a two-stage build to create the final pricebuddy image.
Builder Stage
This stage prepares all necessary dependencies and built assets.
- Source Code: Copies the entire application source code into the container.
- PHP Dependencies: Runs
composer install --no-devto install backend dependencies. - Frontend Assets: Runs
npm install && npm run buildto compile JavaScript and CSS assets. - Documentation: Builds the VuePress documentation site.
Sources: docker/php.dockerfile:4-14
Final Stage
This stage assembles the production-ready image.
- Base: Starts from the
jez500/pricebuddy-baseimage. - Copy Artifacts: Copies the application source code, along with the
vendordirectory,public/buildassets, andpublic/docsfrom thebuilderstage. - Configuration: Copies custom
php.ini,schedule-cronfor cron jobs, andsupervisord.conffor process management. - Scripts: Copies the
start-app.shandstart-cron.shscripts into the container. - Setup:
- Creates a symbolic link from
/app/publicto Apache's web root/var/www/html. - Enables Apache's
mod_rewrite. - Sets executable permissions on startup scripts.
- Creates required storage directories.
- Creates a symbolic link from
- Final Command: Sets the container's default command to execute
/start-app.sh.
Sources: docker/php.dockerfile:16-43
Container Initialization
When the app container starts, it executes the /start-app.sh script to initialize the application environment.
This diagram shows the sequence of commands executed by the start-app.sh script.
Sources: docker/php/start-app.sh
The key initialization steps are:
- Environment File: If an
.envfile does not exist, it is created from.env.exampleand an application key is generated. - Storage: Ensures all necessary
storagesubdirectories exist and sets their permissions to777. A symbolic link for public storage is also created. - Database Check: The script enters a loop, using
netcatto wait until the database service is available on the host and port defined byDB_HOSTandDB_PORT. - Database Initialization: Runs
php artisan buddy:init-db, which handles migrations and seeding. - Application Caching: A series of
artisancommands are run to optimize the application by caching configuration, routes, events, and icons. It also regenerates the price cache. - Process Management: Finally,
supervisordis started to manage the Apache web server and the cron daemon, making the application accessible and ensuring background tasks are run.
Sources: docker/php/start-app.sh:4-40
Background Tasks
Background tasks, such as fetching prices and sending notifications, are handled by a cron job running inside the app container.
- The
docker/php/schedule-cronfile is copied to/etc/cron.d/in the container. supervisordis configured viasupervisord.confto start thecronservice.- The
README.mdconfirms that the cron job handles background tasks automatically.
Sources: README.md:53-55, docker/php.dockerfile:26, docker/php.dockerfile:27, docker/php/start-app.sh:40