I’m starting to lose hope. I want to create a GitHub Actions pipeline to run my Laravel tests using ‘php artisan test’.
My project is Dockerized and allows local code modification.
Here’s my pipeline script:
`name: Laravel Run Tests
on:
push:
branches:
– main
pull_request:
types: [opened, reopened, synchronize]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- name: Install PHP dependencies
run: |
cp .env.example .env
cp nginx/conf.d/laravel.conf.example nginx/conf.d/laravel.conf
sudo chown -R www-data:www-data .
sudo chmod -R 777 .
pwd
ls -l
ls -a
ls -a ./nginx/conf.d
cat ./nginx/conf.d/laravel.conf
composer install --no-ansi --no-interaction --no-progress --no-scripts --optimize-autoloader
php artisan key:generate
php artisan config:cache
- name: Install npm dependencies
run: |
npm install
- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.27.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Set up Docker Compose
run: |
docker-compose up -d
sleep 40
docker-compose exec -T app php artisan migrate --force
docker ps
- name: Check file permissions
run: docker-compose exec -T app ls -l /var/www
- name: Check logs of app container
run: docker logs laravel_app
- name: Check logs of webserver container
run: docker logs nginx
- name: Run tests inside Docker container
run: docker-compose exec -T app php artisan test
`
I also have the docker-compose.yml:
`services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: laravel_app
working_dir: /var/www
volumes:
– ./:/var/www
networks:
– laravel
env_file:
– .env
depends_on:
– db
healthcheck:
test: [ “CMD-SHELL”, “curl -f http://localhost || exit 1” ]
interval: 30s
timeout: 10s
retries: 5
restart: unless-stopped
webserver:
image: nginx:1.26.0-alpine
container_name: nginx
ports:
- "8081:80"
volumes:
- ./:/var/www
- ./nginx/conf.d:/etc/nginx/conf.d
depends_on:
- app
networks:
- laravel
restart: unless-stopped
db:
image: mariadb:latest
container_name: mariadb
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
volumes:
- dbdata:/var/lib/mysql
ports:
- "3307:3306"
networks:
- laravel
healthcheck:
test: [ "CMD-SHELL", "mysqladmin ping -h localhost -u ${DB_USERNAME} -p${DB_PASSWORD} || exit 1" ]
interval: 30s
timeout: 10s
retries: 5
restart: unless-stopped
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
ports:
- "8082:80"
depends_on:
- db
networks:
- laravel
restart: unless-stopped
networks:
laravel:
volumes:
dbdata:
`
The Dockerfile:
`FROM php:8.3.7-fpm
RUN apt-get update && apt-get install -y
git
unzip
zip
nodejs
netcat-openbsd
RUN docker-php-ext-install pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin –filename=composer
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash –
RUN apt-get install -y nodejs
RUN apt-get update && apt-get install -y netcat-openbsd
WORKDIR /var/www
COPY . /var/www
RUN composer install –no-interaction –no-plugins –no-scripts
RUN npm i
COPY init.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/init.sh
CMD [“sh”, “/usr/local/bin/init.sh”]
`
And the init.sh file:
`#!/bin/sh
chown -R www-data:www-data /var/www
until nc -z -v -w30 db 3306; do
echo ‘Waiting for database connection…’
sleep 1
done
php artisan migrate
exec php-fpm`
Currently, my .env and laravel.conf files are exact copies of the example files.
On my local machine, I can run tests and pass them with the command:
docker-compose exec -T app php artisan test
But in my GitHub Action, I’m getting a 500 error on a test that expects only a 200 response.
I’ve made a lot of changes, consulting documentation and even using AI.
Many instructions in my pipeline script are part of my research efforts.
I’m a novice, so I’m probably missing something, but I’m out of ideas.
I’m new to this platform and I’m not sure if it’s appropriate to share the link to my repository, but here it is: https://github.com/Green-Blind/PhoenixPedia
I’ve tried several times to modify the script of my GitHub Actions pipeline.
Firstly, I tried using services instead of my docker-compose setup.
Then, I ensured that the .env.example and laravel.conf.example files were correctly copied to .env and laravel.conf.
I used ‘cat’ to verify the information that was present.
I modified the script to display container logs and also experimented with file read and write permissions.
I tried using the same version of docker-compose as on my computer.
I also attempted to force migration in case it hadn’t been applied properly.
I added various pauses to ensure that my init.sh file could finish.
I’m really stuck on this issue.
user26055514 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.