Issue
I'm taking a stab at doing an automatic deployment using GitLab's CI/CD.
My project has a couple dependencies managed through Composer and I read somewhere that these dependencies (vendor
directory) ideally should be added to the .gitignore
file so that they're not uploaded to the repository and that's what I did.
When I tested the automatic deployment, the modified files are getting uploaded but I received errors regarding missing vendor files which I expected - so now the question is how do I install these dependencies in the context of the remote server from the GitLab CI/CD environment?
My .gitlab-ci.yml
file looks like this:
staging:
stage: staging
before_script:
- apt-get update -qq && apt-get install -y -qq lftp
script:
- lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rev . /public_html --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
environment:
name: staging
url: http://staging.example.com
only:
- staging
Solution
If you look at GitLab's documentation for caching PHP dependencies you'll notice that it installs Composer through the CI. I think you could leverage this to download the project dependencies before uploading them through lftp
.
staging:
stage: staging
before_script:
# Install git since Composer usually requires this if installing from source
- apt-get update -qq && apt-get install -y -qq git
# Install lftp to upload files to remote server
- apt-get update -qq && apt-get install -y -qq lftp
# Install Composer
- curl --show-error --silent https://getcomposer.org/installer | php
# Install project dependencies through Composer (downloads the vendor directory)
- php composer.phar install
script:
# Upload files including the vendor directory
- lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rev . /public_html --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
environment:
name: staging
url: http://staging.example.com
only:
- staging
Answered By - bassicplays Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.