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
11 changes: 10 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# CodeIgniter environment: development | testing | production (developer UI / error display)
CLOUDLOG_ENV=development

MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=cloudlog
MYSQL_USER=cloudlog
Expand All @@ -6,4 +9,10 @@ MYSQL_HOST=db
MYSQL_PORT=3306
BASE_LOCATOR=IO91WM
WEBSITE_URL=http://localhost
DIRECTORY=/var/www/html
DIRECTORY=/var/www/html

# Docker images (GitHub Container Registry). Override for forks, e.g. ghcr.io/yourusername
# CLOUDLOG_IMAGE_REGISTRY=ghcr.io/magicbug
# CLOUDLOG_IMAGE_TAG=latest
#
# Compose: development uses docker-compose.yml (default); production uses docker-compose.prod.yml
2 changes: 1 addition & 1 deletion .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
sudo chmod +x /usr/local/bin/docker-compose

- name: Build Docker services
run: docker-compose up -d
run: docker-compose up -d --build

- name: Wait for services to start
run: |
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Publish Docker images

on:
push:
tags:
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: Dockerfile
image: cloudlog-web
- dockerfile: Dockerfile-db
image: cloudlog-db

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}
tags: |
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable=${{ github.ref_type == 'tag' }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
52 changes: 24 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
# Use the official image for PHP and Apache
FROM php:7.4-apache

# Set the working directory to /var/www/html
WORKDIR /var/www/html

# Install system dependencies, including git and libxml2
RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libxml2-dev \
libzip-dev \
zlib1g-dev \
libpng-dev \
libonig-dev \
default-mysql-client \
curl \
&& apt-get clean \
# Single layer: APT cleanup + PHP extensions (curl used by application PHP code)
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libcurl4-openssl-dev \
libxml2-dev \
libzip-dev \
zlib1g-dev \
libpng-dev \
libonig-dev \
default-mysql-client \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install gd \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install zip \
&& docker-php-ext-install xml \
&& docker-php-ext-install -j"$(nproc)" curl pdo_mysql mysqli gd mbstring zip xml \
&& a2enmod rewrite

# Copy script.sh and make it executable
COPY . /var/www/html/

# Duplicate for seeding an empty Docker volume mounted over /var/www/html (Compose cloudlog_html)
RUN cp -a /var/www/html /usr/local/share/cloudlog-stock

COPY script.sh /usr/local/bin/startup.sh
RUN sed -i 's/\r$//' /usr/local/bin/startup.sh && chmod +x /usr/local/bin/startup.sh

# Configure PHP for larger file uploads (30MB)
RUN echo "upload_max_filesize = 30M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size = 35M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "memory_limit = 64M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "max_execution_time = 300" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "max_input_time = 300" >> /usr/local/etc/php/conf.d/uploads.ini
RUN printf '%s\n' \
'upload_max_filesize = 30M' \
'post_max_size = 35M' \
'memory_limit = 64M' \
'max_execution_time = 300' \
'max_input_time = 300' \
> /usr/local/etc/php/conf.d/uploads.ini

# Expose port 80
EXPOSE 80
EXPOSE 80
10 changes: 7 additions & 3 deletions Dockerfile-db
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ FROM mariadb:latest
# Add the install.sql file to the docker image
ADD install/assets/install.sql /docker-entrypoint-initdb.d

# Create a healthcheck script that uses mariadb-admin
RUN echo '#!/bin/bash\nmariadb-admin ping -h "localhost" --silent' > /usr/local/bin/healthcheck.sh \
# Healthcheck: must use DB credentials (MariaDB 12 rejects anonymous/root-without-password probes → log spam)
RUN printf '%s\n' \
'#!/bin/bash' \
'set -e' \
'exec mariadb-admin ping -h localhost --silent -u"${MYSQL_USER}" -p"${MYSQL_PASSWORD}"' \
> /usr/local/bin/healthcheck.sh \
&& chmod +x /usr/local/bin/healthcheck.sh

# Expose port 3306
EXPOSE 3306
EXPOSE 3306
13 changes: 8 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@

networks:
mynet:

services:
web:
build: .
image: ghcr.io/magicbug/cloudlog-web:latest
build:
context: .
dockerfile: Dockerfile
env_file:
- .env
ports:
- "80:80"
volumes:
- ./:/var/www/html:rw
- ./web:/var/www/html
command: ["/usr/local/bin/startup.sh"]
depends_on:
db:
Expand All @@ -19,13 +23,14 @@ services:
restart: on-failure

db:
image: ghcr.io/magicbug/cloudlog-db:latest
build:
context: .
dockerfile: Dockerfile-db
env_file:
- .env
volumes:
- db_data:/var/lib/mysql
- ./db_data:/var/lib/mysql
networks:
- mynet
healthcheck:
Expand All @@ -35,5 +40,3 @@ services:
interval: 10s
start_period: 40s

volumes:
db_data: {}
46 changes: 44 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@
* @filesource
*/

/*
*---------------------------------------------------------------
* Optional .env next to this file (existing getenv/$_SERVER values are not overwritten — Docker/OS wins)
*---------------------------------------------------------------
*/
$cloudlogEnvFile = __DIR__ . DIRECTORY_SEPARATOR . '.env';
if (is_readable($cloudlogEnvFile)) {
foreach (file($cloudlogEnvFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
$line = trim($line);
if ($line === '' || (isset($line[0]) && $line[0] === '#')) {
continue;
}
$eq = strpos($line, '=');
if ($eq === false) {
continue;
}
$name = trim(substr($line, 0, $eq));
$value = trim(substr($line, $eq + 1));
if ($name === '') {
continue;
}
if (strlen($value) >= 2
&& (($value[0] === '"' && substr($value, -1) === '"')
|| ($value[0] === "'" && substr($value, -1) === "'"))) {
$value = substr($value, 1, -1);
}
if (getenv($name) === false) {
putenv($name . '=' . $value);
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}

/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
Expand All @@ -51,10 +85,18 @@
* testing
* production
*
* Set CLOUDLOG_ENV or CI_ENV in .env (or in the server environment). Defaults to development.
*
* NOTE: If you change these, also change the error_reporting() code below
*/
#define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
define('ENVIRONMENT', 'development');
$cloudlog_environment = getenv('CLOUDLOG_ENV');
if ($cloudlog_environment === false || $cloudlog_environment === '') {
$cloudlog_environment = getenv('CI_ENV');
}
if ($cloudlog_environment === false || $cloudlog_environment === '') {
$cloudlog_environment = 'development';
}
define('ENVIRONMENT', $cloudlog_environment);

/*
*---------------------------------------------------------------
Expand Down
Loading