Skip to main content



Private Composer Repo with Gitlab and Satis
You can easily create your own composer repository using Satis and Gitlab. I will use global https://gitlab.com/feed.xml but it should be most useful for private corporate Gitlab installations. You will need CI and Pages

Our repo should contain only 2 files: satis.json and .gitlab-ci.yml

satis.json


satis.json should describe the repo you want. It is very close by structure to composer.json. Refer to Satis documentation for advanced use cases, I will go with the simplest one: add some packages from Github and require all of them

{
"name": "My Satis Repo",
"homepage": "https://sandfox.gitlab.io/satis/",
"repositories": [{
"type": "vcs",
"url": "https://github.com/sandfoxme/bencode"
}, {
"type": "vcs",
"url": "https://github.com/sandfoxme/composer-viz"
}],
"require-all": true
}

.gitlab-ci.yml


Now the tricky part that took me quite some time to debug, but you probably can just copy-paste my solution. You need to set a private variable AUTH_JSON which should contain the content of your auth.json like Github Oauth Token or access data for your private Gitlab instance. (Set it to {} if you need none of it)

Note

Jan 19, 2019: code has been updated to create auth.json in base path not in composer path

# The only image where dind works on GitLab.com
image: gitlab/dind

# So we can use Docker inside build script
services:
- docker:dind

# Task for GitHub Pages
pages:
stage: deploy
# cache composer data (especially useful if you set up Satis to download packages)
cache:
paths:
- composer
script:
- if [ ! -d composer ]; then mkdir composer; fi
# create auth.json from variable
- echo "$AUTH_JSON" > auth.json
# run satis from docker image
- docker run --rm -i -v `pwd`:/build -v `pwd`/composer:/composer composer/satis
# gitlab requires directory to be named public for whatever reason
- mv output public
# artifacts for Pages
artifacts:
paths:
- public
# do this only on master branch
only:
- master

Result


You can find my example repo project at https://gitlab.com/sandfox/satis/ and generated Satis repo athttps://sandfox.gitlab.io/satis/
https://sandfox.me/2018/03/09/satis-gitlab.html