diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..5c810383 --- /dev/null +++ b/.env.example @@ -0,0 +1,15 @@ +DB_HOST=db +DB_NAME=suma +DB_PASS=password +DB_PORT=3306 +DB_ROOT_PASSWORD=rootpassword +DB_USER=suma +SERVICE_URL=http://YOUR_SERVER +SUMA_ADMIN_USER=admin +SUMA_ADMIN_PASS=admin +SUMA_ANALYTICS_TIMEZONE=America/New_York +SUMA_ANALYTICS_DISPLAY_FORMAT=m-d-Y +SUMA_ANALYTICS_RECIPIENTS=you@example.com, your_friend@example.com +SUMA_ANALYTICS_ERROR_RECIPIENTS=you@example.com +SUMA_ANALYTICS_EMAIL_FROM=Suma Reports +SUMA_ANALYTICS_EMAIL_SUBJECT=Suma Nightly Report: diff --git a/.gitignore b/.gitignore index 27e363d9..bd483a55 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ analysis/test/js/coverage analysis/test/php/coverage docs/site /vendor +.env # Configuration Files service/config/config.ini diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..349adcfb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM php:8.1-apache + +# Install dependencies +RUN apt-get update && apt-get install -y \ + libzip-dev libonig-dev zip unzip curl default-mysql-client && \ + docker-php-ext-install pdo_mysql mbstring zip && \ + a2enmod rewrite && \ + curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \ + rm -rf /var/lib/apt/lists/* + +# Copy local suma code into image at /app/suma +COPY --chown=www-data:www-data . /app/suma + +# Set working dir +WORKDIR /app/suma + +# Create web root dirs (will be symlinked) +RUN mkdir -p /var/www/html/suma/ + +# Entrypoint & startup script +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +EXPOSE 80 + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1be4e55a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,55 @@ +# version: '3.8' + +services: + db: + image: mysql:8.4 + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} + MYSQL_DATABASE: ${DB_NAME} + MYSQL_USER: ${DB_USER} + MYSQL_PASSWORD: ${DB_PASS} + volumes: + - db_data:/var/lib/mysql + + init-db: + image: mysql:8.4 + depends_on: + - db + entrypoint: ["/bin/sh", "-c"] + command: > + " + for i in {1..30}; do + mysqladmin ping -h db --silent && break || sleep 2; + done; + if ! mysql -h db -u root -p${DB_ROOT_PASSWORD} -e 'SELECT 1 FROM location LIMIT 1;' ${DB_NAME}; then + echo 'Initializing database...'; + mysql -h db -u root -p${DB_ROOT_PASSWORD} ${DB_NAME} < /docker-entrypoint-initdb.d/schema.sql; + else + echo 'Schema already initialized, skipping.'; + fi + " + volumes: + - ./service/config/schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro + environment: + MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} + + suma: + build: . + ports: + - "80:80" + depends_on: + - db + - init-db + environment: + DB_HOST: db + DB_PORT: 3306 + DB_NAME: ${DB_NAME} + DB_USER: ${DB_USER} + DB_PASS: ${DB_PASS} + restart: unless-stopped + env_file: + - .env + +volumes: + db_data: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..6c757514 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,144 @@ +#!/bin/bash +set -e + +# Paths +WEB_DIR="/var/www/html" +SUMA_DIR="/app/suma" +SUMA_LOG="/var/log/suma.log" + +# Generate Apache config with environment variables +cat > /etc/apache2/sites-available/000-default.conf < + DocumentRoot ${WEB_DIR} + + Alias /sumaserver ${SUMA_DIR}/service/web + Alias /suma/client ${SUMA_DIR}/web + Alias /suma/analysis ${SUMA_DIR}/analysis + + + Options -Indexes +FollowSymLinks + Require all granted + + + + Options -Indexes +FollowSymLinks + AllowOverride All + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} -s [OR] + RewriteCond %{REQUEST_FILENAME} -l [OR] + RewriteCond %{REQUEST_FILENAME} -d + RewriteRule ^.*$ - [NC,L] + RewriteRule ^.*$ index.php [NC,L] + Require all granted + + + ErrorLog \${APACHE_LOG_DIR}/error.log + CustomLog \${APACHE_LOG_DIR}/access.log combined + +EOF + +# Enable rewrite module (already enabled in Dockerfile but safe here) +a2enmod rewrite + +# Generate Suma config.yaml from env vars if not exists +CONFIG_PATH="${SUMA_DIR}/service/web/config/config.yaml" +if [ ! -f "$CONFIG_PATH" ]; then + echo "Generating Suma config.yaml..." + cat > "$CONFIG_PATH" < "$ANALYSIS_CONFIG_PATH" < "$DB_CONFIG_PATH" <