CodexBloom - Programming Q&A Platform

Integrating PHP PHPUnit Tests in AWS CI/CD Pipeline with Docker

👀 Views: 2 💬 Answers: 1 📅 Created: 2025-09-12
php docker aws ci-cd phpunit

I'm trying to debug I'm relatively new to this, so bear with me. I'm having a hard time understanding Currently developing a CI/CD pipeline for a PHP application using AWS services. Part of this process involves running PHPUnit tests inside a Docker container during the build stage. I have set up a basic Dockerfile like this: ```Dockerfile FROM php:8.1-cli WORKDIR /app COPY . . RUN apt-get update && apt-get install -y unzip RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN composer install CMD ["vendor/bin/phpunit"] ``` However, tests fail intermittently, particularly due to memory limits. I tried increasing the PHP memory limit in the Dockerfile by adding: ```Dockerfile RUN echo "memory_limit = 512M" >> /usr/local/etc/php/conf.d/memory-limit.ini ``` But this hasn’t resolved the problem. The error logs indicate: ``` PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) ``` Additionally, I’m using AWS CodeBuild and have the following buildspec.yml configuration: ```yaml version: 0.2 phases: install: runtime-versions: php: 8.1 commands: - composer install build: commands: - docker build -t my-php-app . - docker run my-php-app artifacts: files: - '**/*' ``` I've also experimented with running the tests directly on the host machine instead of within Docker, and they pass without issues. Is there a better way to manage memory limits in Docker for PHP applications? Any insights into optimizing the Docker environment for running PHPUnit in a CI/CD pipeline would be greatly appreciated. I'm developing on Ubuntu 20.04 with Php. Am I approaching this the right way? My team is using Php for this web app. I appreciate any insights! My team is using Php for this CLI tool. How would you solve this?