GitLab is a single application for the entire software development lifecycle. From project planning and source code management to CI/CD, monitoring, and security.
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
Building your own composer packages is a well-used practice in industry for internal modules or to build official ones but hosted in your local network.
First of all we need to have a Gitlab server running on-prem or using gitlab.com cloud. If you are using on-prem you need to make some changes in your server.
In file /etc/gitlab/gitlab.rb you need to un-comment the following 2 lines and then run command gitlab-ctl reconfigure.
gitlab_rails['packages_enabled'] = true
gitlab_rails['packages_storage_path'] = "/var/opt/gitlab/gitlab-rails/shared/packages"
With this done your gitlab on-prem instance is ready to host and build composer packages and in every project you create you will have the following options:

In your every project will need to configure your .gitlab-ci.yml file to build and push composer packages. It will look like the following one:
stages:
- deploy
deploy_composer:
stage: deploy
only:
- tags
image:
name: curlimages/curl
script:
- curl -sS --show-error --fail --data tag=${CI_COMMIT_TAG} "https://__token__:${DEPLOY_TOKEN}@gitlab.openthreat.ro/api/v4/projects/${CI_PROJECT_ID}/packages/composer"
Take care of settingDEPLOY_TOKEN variable in your project otherwise job will fail.
Need help building scalable PHP ecosystems or CI/CD workflows?
→ Explore our DevOps Services
0 Comments