Various changes to make staging work

This commit is contained in:
Karl Cordes 2025-08-08 11:22:06 +10:00
parent dc2b67d300
commit 6f538e3e4d
3 changed files with 148 additions and 8 deletions

75
Dockerfile.ubuntu-php Normal file
View file

@ -0,0 +1,75 @@
# Simple working PHP setup using Ubuntu
FROM ubuntu:20.04
# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Australia/Sydney
# Install Apache, PHP and required extensions
RUN apt-get update && apt-get install -y \
apache2 \
libapache2-mod-php7.4 \
php7.4 \
php7.4-mysql \
php7.4-gd \
php7.4-curl \
php7.4-mbstring \
php7.4-xml \
php7.4-zip \
php7.4-imap \
php7.4-intl \
php7.4-bcmath \
curl \
&& rm -rf /var/lib/apt/lists/*
# Enable Apache modules
RUN a2enmod rewrite headers php7.4
# Configure PHP for CakePHP
RUN { \
echo 'error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_WARNING'; \
echo 'display_errors = On'; \
echo 'display_startup_errors = On'; \
echo 'log_errors = On'; \
echo 'max_execution_time = 300'; \
echo 'memory_limit = 256M'; \
echo 'post_max_size = 50M'; \
echo 'upload_max_filesize = 50M'; \
} > /etc/php/7.4/apache2/conf.d/99-cakephp.ini
# Set up Apache virtual host
RUN echo '<VirtualHost *:80>\n\
ServerName localhost\n\
DocumentRoot /var/www/cmc-sales/app/webroot\n\
<Directory /var/www/cmc-sales/app/webroot>\n\
Options FollowSymLinks\n\
AllowOverride All\n\
Require all granted\n\
</Directory>\n\
ErrorLog ${APACHE_LOG_DIR}/error.log\n\
CustomLog ${APACHE_LOG_DIR}/access.log combined\n\
</VirtualHost>' > /etc/apache2/sites-available/000-default.conf
# Create app directory structure
RUN mkdir -p /var/www/cmc-sales/app/tmp/{cache,logs,sessions} \
&& mkdir -p /var/www/cmc-sales/app/webroot/{pdf,attachments_files}
# Set permissions
RUN chown -R www-data:www-data /var/www/cmc-sales \
&& chmod -R 777 /var/www/cmc-sales/app/tmp
# Copy ripmime if it exists
# COPY conf/ripmime* /usr/local/bin/ || true
# RUN chmod +x /usr/local/bin/ripmime* 2>/dev/null || true
# Set working directory
WORKDIR /var/www/cmc-sales
# Copy application (will be overridden by volume mount)
COPY app/ /var/www/cmc-sales/app/
# Expose port 80
EXPOSE 80
# Start Apache in foreground
CMD ["apache2ctl", "-D", "FOREGROUND"]

View file

@ -35,21 +35,21 @@ help:
# Staging environment # Staging environment
staging: staging:
@echo "Starting staging environment..." @echo "Starting staging environment..."
docker compose -f docker-compose.caddy-staging.yml up -d docker compose -f docker-compose.caddy-staging-ubuntu.yml up -d
@echo "Staging environment started" @echo "Staging environment started"
@echo "Access at: https://staging.cmc.springupsoftware.com" @echo "Access at: https://staging.cmc.springupsoftware.com"
staging-down: staging-down:
docker compose -f docker-compose.caddy-staging.yml down docker compose -f docker-compose.caddy-staging-ubuntu.yml down
staging-logs: staging-logs:
docker compose -f docker-compose.caddy-staging.yml logs -f docker compose -f docker-compose.caddy-staging-ubuntu.yml logs -f
restart-staging: restart-staging:
@echo "Restarting staging environment..." @echo "Restarting staging environment..."
docker compose -f docker-compose.caddy-staging.yml down docker compose -f docker-compose.caddy-staging-ubuntu.yml down
docker compose -f docker-compose.caddy-staging.yml build --no-cache docker compose -f docker-compose.caddy-staging-ubuntu.yml build --no-cache
docker compose -f docker-compose.caddy-staging.yml up -d docker compose -f docker-compose.caddy-staging-ubuntu.yml up -d
@echo "Staging environment restarted" @echo "Staging environment restarted"
# Production environment # Production environment
@ -124,7 +124,7 @@ logs:
@echo "Which logs? [staging/production/caddy]" @echo "Which logs? [staging/production/caddy]"
@read env; \ @read env; \
case $$env in \ case $$env in \
staging) docker compose -f docker-compose.caddy-staging.yml logs -f ;; \ staging) docker compose -f docker-compose.caddy-staging-ubuntu.yml logs -f ;; \
production) docker compose -f docker-compose.caddy-production.yml logs -f ;; \ production) docker compose -f docker-compose.caddy-production.yml logs -f ;; \
caddy) sudo journalctl -u caddy -f ;; \ caddy) sudo journalctl -u caddy -f ;; \
*) echo "Invalid option" ;; \ *) echo "Invalid option" ;; \
@ -134,7 +134,7 @@ logs:
clean: clean:
@echo "WARNING: This will stop and remove ALL CMC containers!" @echo "WARNING: This will stop and remove ALL CMC containers!"
@read -p "Are you sure? (yes/no): " confirm && [ "$$confirm" = "yes" ] @read -p "Are you sure? (yes/no): " confirm && [ "$$confirm" = "yes" ]
docker compose -f docker-compose.caddy-staging.yml down --volumes --remove-orphans docker compose -f docker-compose.caddy-staging-ubuntu.yml down --volumes --remove-orphans
docker compose -f docker-compose.caddy-production.yml down --volumes --remove-orphans docker compose -f docker-compose.caddy-production.yml down --volumes --remove-orphans
docker system prune -f docker system prune -f
@echo "Cleanup completed" @echo "Cleanup completed"

View file

@ -0,0 +1,65 @@
version: '3.8'
services:
cmc-php-staging:
build:
context: .
dockerfile: Dockerfile.ubuntu-php
platform: linux/amd64
container_name: cmc-php-staging
depends_on:
- db-staging
ports:
- "127.0.0.1:8091:80"
volumes:
- ./app:/var/www/cmc-sales/app
- staging_pdf_data:/var/www/cmc-sales/app/webroot/pdf
- staging_attachments_data:/var/www/cmc-sales/app/webroot/attachments_files
restart: unless-stopped
environment:
- APP_ENV=staging
- DB_HOST=db-staging
- DB_NAME=cmc_staging
- DB_USER=cmc_staging
- DB_PASSWORD=${DB_PASSWORD_STAGING:-staging_password}
db-staging:
image: mariadb:10.11
container_name: cmc-db-staging
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD_STAGING:-root_password}
MYSQL_DATABASE: cmc_staging
MYSQL_USER: cmc_staging
MYSQL_PASSWORD: ${DB_PASSWORD_STAGING:-staging_password}
volumes:
- staging_db_data:/var/lib/mysql
restart: unless-stopped
ports:
- "127.0.0.1:3307:3306"
cmc-go-staging:
build:
context: .
dockerfile: Dockerfile.go.staging
container_name: cmc-go-staging
environment:
DB_HOST: db-staging
DB_PORT: 3306
DB_USER: cmc_staging
DB_PASSWORD: ${DB_PASSWORD_STAGING:-staging_password}
DB_NAME: cmc_staging
PORT: 8080
APP_ENV: staging
depends_on:
- db-staging
ports:
- "127.0.0.1:8092:8080"
volumes:
- staging_pdf_data:/root/webroot/pdf
- ./credentials/staging:/root/credentials:ro
restart: unless-stopped
volumes:
staging_db_data:
staging_pdf_data:
staging_attachments_data: