I have the following setup in GitLab CI. I have a script which I use to build my application using php, composer and npm commands.
I want to replace the script with a single Dockerfile
.
Here is the script:
#!/bin/bash
if [ "$APP" = "webapp" ]; then
docker exec -t cozact_app composer install &&
docker exec -t cozact_app php artisan down &&
docker exec -t cozact_app php artisan migrate --force &&
docker exec -t cozact_app php artisan storage:link &&
docker exec -t cozact_app php artisan droit:run &&
docker exec -t cozact_app npm install;
fi
if [ "$APP" = "webapp" ] && [ "$ENV" = "test" ]; then
docker exec -t cozact_app npm run dev &&
docker exec -t cozact_app php artisan up;
fi
if [ "$APP" = "webapp" ] && [ "$ENV" = "preprod" ]; then
docker exec -t cozact_app npm run production &&
docker exec -t cozact_app php artisan up;
fi
if [ "$APP" = "webapp" ] && [ "$ENV" = "prod" ]; then
docker exec -t cozact_app npm run production &&
docker exec -t cozact_app php artisan up;
fi
#!/bin/sh
composer install &&
php artisan down &&
php artisan migrate --force &&
php artisan storage:link &&
php artisan droit:run &&
npm install
if [ "$var" = "test" ] ; then
npm run dev &&
php artisan up;
else
npm run production &&
php artisan up;
fi
2
Answers
Here is the issue composer install shows within gitlab-ci
This issue is related to a part that is mentionned in the composer.json file, I did comment it to make it work for me, but I don't know if there will be any further issues due to this omit
You can use the following Multi-stage
Dockerfile
, and adapt it to your usecase.This Dockerfile is composed of 3 stages:
php artisan
commands that should run during the build and not during the run.php artisan
commands that needs to run during the run should go in aCMD
orENTRYPOINT
in the last stage)In you
gitlab-ci.yml
you’ll have something like the following: