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 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 GitLab and require all of them

php/satis-gitlab/satis.json (Source)

{
    "name": "My Satis Repo",
    "homepage": "https://sandfox.gitlab.io/satis/",
    "repositories": [{
        "type": "vcs",
        "url": "https://gitlab.com/sandfox/bencode"
    }, {
        "type": "vcs",
        "url": "https://gitlab.com/sandfox/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 COMPOSER_AUTH 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)

php/satis-gitlab/gitlab-ci.yml (Source)

# Docker image
image: docker:latest

# 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
  # run satis from docker image
  - docker run --rm -i -v `pwd`:/build -v `pwd`/composer:/composer -e COMPOSER_AUTH="$COMPOSER_AUTH" composer/satis
  # gitlab requires directory to be named public for whatever reason
  - mv output public
  # artifacts for Pages
  artifacts:
    paths:
    - public
    # I don't like any garbage stored in the ci
    expire_in: 1w
  # 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 at https://sandfox.gitlab.io/satis/

Comments

Comments powered by Disqus