PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 7, 2022

[FIXED] Running "docker-compose run --rm composer update" not working in Jenkins pipeline

 January 07, 2022     composer-php, docker, docker-compose, jenkins, laravel     No comments   

Issue

I have a Jenkins pipeline just for learning purposes, which should build a Laravel app via docker-compose. The "docker-compose --build" step is working fine, but next it is running "docker-compose run --rm composer update", which then stops, no error or output. When I run the command manually after accessing the server via SSH, the command runs with no issues.

Composer service in docker-compose file:

composer:
build:
  context: .
  dockerfile: composer.dockerfile
container_name: composer
volumes:
  - ./src:/var/www/html
working_dir: /var/www/html
depends_on:
  - php
user: laravel
entrypoint: ['composer', '--ignore-platform-reqs']
networks:
  - laravel

Build step in jenkinsfile:

stage('Build') {
     steps {
         echo 'Building..'
         sh 'chmod +x scripts/jenkins-build.sh'
         sh './scripts/jenkins-build.sh'
     }
 }

Command in shell script:

print "Building docker app"
sudo docker-compose up -d --build site # works fine
sudo chown jenkins -R ./

print "Running composer"
sudo docker-compose run --rm composer update # hangs in jenkins but works in cmd?

View in Jenkins:

enter image description here

Same command working on same server, via cmd: enter image description here

I know there are some bad practices in here, but this is just for learning purposes. Jenkins server is running Ubuntu 20.04 on AWS EC2 instance.


Solution

In the end I resorted to installing composer directly into my PHP docker image. Therefore instead of running the composer service, I now use docker exec php composer update. From what I can see, any services that were used via docker-compose run did not work in the Jenkins pipeline. In my case, these were all services that were only running whilst performing some action (like composer update), so maybe that is why Jenkins did not like it.



Answered By - CST
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing