Skip to main content

Installation

Samurai Predictive Event Collector is a Dockerised application that's primarily intended to be deployed to your own cloud infrastructure. This guide will help you run your own deployment of the platform using Docker.

Table of contents

Docker guide

Introduction

The project repository you receive contains two files for deploying the application in a Docker container:

  • Local deployment: docker-compose.local.yml
  • Production deployment: docker-compose.yml

Before using locally, copy the .env.example file to .env and configure the environment variables:

cp .env.example .env

Quick start

To get started, you can use the following commands:

./installer.sh

By default, the script uses the docker-compose.yml file to set up the application. If you want to use a different Docker Compose file, provide it as an argument when running the script. For example, to use the docker-compose.local.yml file, run:

./installer.sh docker-compose.local.yml

The installer.sh file is a shell script that automates the setup and deployment of your Docker-based Samurai Predictive Event Collector application. It performs the following steps:

  • Accepts an optional argument specifying the Docker Compose file to use (defaults to docker-compose.yml).
  • Runs docker-compose up -d to start services defined in the Docker Compose file in detached mode.
  • Executes composer install inside the app service container to install PHP dependencies.
  • Runs php artisan migrate inside the app service container to apply new database migrations.
  • Creates a new admin user for the Orchid platform using php artisan orchid:admin.
  • Creates a symbolic link from public/storage to storage/app/public with php artisan storage:link.
  • Clears and optimizes the application cache.
  • Changes permissions of the ./storage/ directory to make it writable.
  • Ensures all services are up and running by running docker-compose up -d again.

This script simplifies the process of setting up and deploying your application, making it easy to get up and running with a single command.

Deployment

The docker-compose.yml file defines and manages multi-container Docker applications. Here's a brief description of the services defined in your Samurai Predictive Event Collector instance docker-compose.yml file:

  • app: This service is built from the Dockerfile located at ./docker/php/Dockerfile. It uses the api-center-opv2/app:latest image and depends on the pgsql and redis services. The application's code is mounted into the container at /var/www/html.

  • nginx: This service uses the nginx:alpine image and depends on the app service. It exposes ports 80 and 443. The Nginx configuration files and the application's public and storage directories are mounted into the container.

  • worker: This service is similar to the app service but is built from the Dockerfile located at ./docker/php/dev.Dockerfile. It runs the supervisord command to manage processes.

  • schedule: This service is similar to the worker service but runs the crond command to manage cron jobs.

  • pgsql: This service uses the postgres:16-alpine image and sets up a PostgreSQL database with the specified environment variables. The database data is persisted in a Docker volume.

  • redis: This service uses the redis:alpine image and sets up a Redis server. The Redis data is persisted in a Docker volume.

The networks section defines a network named api-center-opv2 that is used by all services. The volumes section defines two volumes, pgsql and redis, used by the pgsql and redis services respectively.

Dockerfile

The Dockerfile is used to build a Docker image for a PHP application. Here's a brief description of what this file does:

  • Starts from the php:8.2-fpm-alpine base image, which includes PHP 8.2 running on the Alpine Linux distribution with FastCGI Process Manager (FPM) pre-installed.
  • Sets the timezone and installs Composer.
  • Updates the package list of the Alpine Linux distribution and installs several necessary packages, including curl, libpq-dev, icu-dev, zip, unzip, bash, gmp-dev, and PHP development dependencies.
  • Installs supervisor and busybox-suid. Supervisor is a process control system that allows you to monitor and control UNIX processes, and busybox-suid provides several stripped-down Unix tools in a single executable.
  • Installs and configures the zip extension for PHP.
  • Installs and enables the redis extension for PHP.
  • Installs several other PHP extensions, including pdo_pgsql, intl, bcmath, opcache, exif, pcntl, and gmp.
  • Sets up the GD extension for PHP.
  • Cleans up temporary files and deletes PHP source files to reduce the size of the image.
  • Creates a new user and group for running the application.
  • Sets the working directory to /var/www/html.
  • Switches to the newly created user.

This Dockerfile creates a Docker image that is ready to run a PHP application with all necessary extensions and configurations.