Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
[email protected], [email protected]
[email protected]
SUMA_ANALYTICS_EMAIL_FROM=Suma Reports <[email protected]>
SUMA_ANALYTICS_EMAIL_SUBJECT=Suma Nightly Report:
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analysis/test/js/coverage
analysis/test/php/coverage
docs/site
/vendor
.env

# Configuration Files
service/config/config.ini
Expand Down
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
55 changes: 55 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
144 changes: 144 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
<VirtualHost *:80>
DocumentRoot ${WEB_DIR}

Alias /sumaserver ${SUMA_DIR}/service/web
Alias /suma/client ${SUMA_DIR}/web
Alias /suma/analysis ${SUMA_DIR}/analysis

<Location "/suma">
Options -Indexes +FollowSymLinks
Require all granted
</Location>

<Location "/sumaserver">
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
</Location>

ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
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" <<EOC
SUMA_SERVER_PATH: $SUMA_DIR/service
SUMA_CONTROLLER_PATH: $SUMA_DIR/service/controllers
SUMA_BASE_URL: /sumaserver
SUMA_DEBUG: true
EOC
fi

# Generate Suma config.yaml from env vars if not exists
ANALYSIS_CONFIG_PATH="${SUMA_DIR}/analysis/config/config.yaml"
if [ ! -f "$ANALYSIS_CONFIG_PATH" ]; then
echo "Generating Suma Analysis config.yaml..."
cat > "$ANALYSIS_CONFIG_PATH" <<EOC
showErrors: false
serverIO:
baseUrl: ${SERVICE_URL}/sumaserver/query
analysisBaseUrl: ${SERVICE_URL}/suma/analysis/reports
nightly:
timezone: ${SUMA_ANALYTICS_TIMEZONE}
displayFormat: Y-m-d
recipients: ${SUMA_ANALYTICS_RECIPIENTS}
errorRecipients: ${SUMA_ANALYTICS_ERROR_RECIPIENTS}
emailFrom: "${SUMA_ANALYTICS_EMAIL_FROM}"
emailSubj: "${SUMA_ANALYTICS_EMAIL_SUBJECT}"
EOC
fi

# Generate Suma Database config.yaml from env vars if not exists
DB_CONFIG_PATH="${SUMA_DIR}/service/config/config.yaml"
if [ ! -f "$DB_CONFIG_PATH" ]; then
echo "Generating Suma DB config.yaml..."
cat > "$DB_CONFIG_PATH" <<EOC
production:
sumaserver:
db:
host: ${DB_HOST}
platform: Pdo_Mysql
dbname: ${DB_NAME}
user: ${DB_USER}
pword: ${DB_PASS}
port: ${DB_PORT}
log:
path:
name: ${SUMA_LOG}
admin:
user: ${SUMA_ADMIN_USER}
pass: ${SUMA_ADMIN_PASS}
queryserver:
db:
limit: 10000

development:
_extends: production
sumaserver:
db:
dbname: sumadev
log:
path:
EOC
fi

SUMA_CLIENT_CONFIG_PATH="${SUMA_DIR}/web/config/spaceassessConfig.js"
if [ ! -f "$SUMA_CLIENT_CONFIG_PATH" ]; then
echo "Generating Suma spaceassessConfig.js..."
cp ${SUMA_DIR}/web/config/spaceassessConfig_example.js ${SUMA_CLIENT_CONFIG_PATH}
fi


# Install PHP dependencies if composer.json is present
if [ -f "${SUMA_DIR}/composer.json" ]; then
echo "Installing PHP dependencies via Composer..."
cd "${SUMA_DIR}"
composer install --no-interaction --prefer-dist --optimize-autoloader
chown -R www-data:www-data ${SUMA_DIR}
fi

# create suma.log file
echo "Touching suma.log..."
touch ${SUMA_LOG}
chown www-data:www-data ${SUMA_LOG}

# Chown of files for webserver
chown www-data:www-data ${SUMA_CLIENT_CONFIG_PATH} ${DB_CONFIG_PATH} ${CONFIG_PATH}

# Wait for MySQL to be ready before starting Apache
if [ -n "$DB_HOST" ]; then
echo "Waiting for MySQL at $DB_HOST:$DB_PORT..."
for i in {1..30}; do
if mysqladmin ping -h"$DB_HOST" -P"${DB_PORT:-3306}" --silent; then
echo "MySQL is up!"
break
fi
echo "Waiting for MySQL... retry $i/30"
sleep 2
done
fi

exec "$@"
4 changes: 4 additions & 0 deletions docs/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ For Suma Server Installation:
* Copy contents of `/SUMA_DOWNLOAD_DIR/service/web` to `/YOUR_WEB_DIR/sumaserver`


Suma Software Installation (Docker install)
-------------------------------------------
This is setup to bootstrap, configure and make Suma available at the documented endpoints. Provided are example `.env` and `docker-compose.yml` files that can be used to start the container. It will create a database if one has not already been initalized. The log file is stored in `/var/log/suma.log`.

Apache Configuration
---------------------

Expand Down