User Tools

Site Tools


gitlab_satis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
gitlab_satis [2018/08/21 21:04] admingitlab_satis [2018/11/14 16:52] – [Optional] admin
Line 1: Line 1:
 ====== Using Gitlab and Satis to generate private composer Repository ====== ====== Using Gitlab and Satis to generate private composer Repository ======
  
-[[https://github.com/ochorocho/gitlab-pages-satis|This]] is mainly a wrapper for [[https://github.com/mborne/satis-gitlab|mborne/satis-gitlab]] intended to make it easy to use with minimal and simple configuration. Best used together with Gitlab. I'm using Gitlab Pages behind **Apache**, nginx is the default/recommended way to use Gitlab Pages with.+[[https://github.com/ochorocho/gitlab-pages-satis|This]] is mainly a wrapper for [[https://github.com/mborne/satis-gitlab|mborne/satis-gitlab]] intended to make it easy to use with minimal and simple configuration. Best used together with Gitlab. <del>I'm using Gitlab Pages behind **Apache**,</del> NGINX is the default/recommended way to use Gitlab Pages with.
  
 **Idea** **Idea**
Line 9: Line 9:
   * <del>Download zips in Satis ??? So no key auth is required??!?!?</del> add ''archive: true'' and *.tar-Files for Tags will be saved in ''./dist/'' Folder. Branches still point to Git Repo.   * <del>Download zips in Satis ??? So no key auth is required??!?!?</del> add ''archive: true'' and *.tar-Files for Tags will be saved in ''./dist/'' Folder. Branches still point to Git Repo.
   * <del>Multiple packages, which one is preferred?</del> Depends on the loading order of your defined repositories in composer.json   * <del>Multiple packages, which one is preferred?</del> Depends on the loading order of your defined repositories in composer.json
 +  * FIXME Run pipeline only if it is not already running, pile up all requests and run it only once.
  
 **Features** **Features**
Line 31: Line 32:
   image: ochorocho/gitlab-pages-satis:latest   image: ochorocho/gitlab-pages-satis:latest
   script:   script:
-    - mkdir public+    - mkdir satis-build
     - gitlab-pages-satis     - gitlab-pages-satis
 +    - mv satis-build public
   artifacts:   artifacts:
     paths:     paths:
Line 42: Line 44:
 ===== Configuration ===== ===== Configuration =====
  
-Go to User Settings -> Access Tokens, give it a name and allow api scope. Hit "Create personal access token" and copy it to your configuration (arguments -> gitlab-token). See below ...+Go to Project -> Settings -> CI/CD -> Pipeline Triggers, give it a name and allow api scope. Hit "Add Trigger" and copy it to your configuration (arguments -> gitlab-token). See below ...
 ==== Using Environment variable ==== ==== Using Environment variable ====
  
Line 61: Line 63:
   homepage: "https://satis.example.org"   homepage: "https://satis.example.org"
   output: "satis.json"   output: "satis.json"
-  use-file-to-include: '.satisinclude'+  include-if-has-file: '.satisinclude'
   template: '/path/to/satis-template.example.json'   template: '/path/to/satis-template.example.json'
   archive: true   archive: true
Line 69: Line 71:
   username: "admin"   username: "admin"
   password: "password"   password: "password"
 +build-dir: "satis-build"
 </code> </code>
  
Line 110: Line 113:
 <code ruby gitlab_pages_satis.rb> <code ruby gitlab_pages_satis.rb>
 #!/usr/bin/env ruby #!/usr/bin/env ruby
 +
 +#### Config begin
 +
 +# Trigger Token, see Project -> Settings -> CI/CD -> Pipeline triggers
 +trigger_token="XXXXXXXX"
 +
 +# Private Token, see User -> Access Tokens -> Personal Access Tokens
 +auth_token="XXXXXXXX"
 +
 +# GitLab install
 +gitlab_url="https://gitlab.example.org/"
 +
 +# Satis Project id
 +satis_project_id="XX"
 +
 +#### Config end
  
 require 'json' require 'json'
Line 122: Line 141:
  shaFile = "#{temp}/gitlab-trigger.sha"  shaFile = "#{temp}/gitlab-trigger.sha"
  
- # Get hash values to compare + # Get refs to compare 
- payloadHash = "#{payload['before']} #{payload['after']}" + payloadCurrent = "#{payload['ref']}" 
- payloadHashBefore = File.read(shaFile) if File.exist?(shaFile)+ payloadBefore = File.read(shaFile) if File.exist?(shaFile)
  
- # Save before and after hash to compare+ # Save refs to compare on next run ...
  File.delete(shaFile) if File.exist?(shaFile)  File.delete(shaFile) if File.exist?(shaFile)
- File.write(shaFile, "#{payload['before']} #{payload['after']}")+ File.write(shaFile, "#{payload['ref']}") 
 + 
 + # Check if composer files exists in project 
 + project_id="#{payload['project_id']}" 
 + composerExists = `curl -o /dev/null -s -w \"%{http_code}\" --request GET --header 'PRIVATE-TOKEN: #{auth_token}' '#{gitlab_url}/api/v4/projects/#{project_id}/repository/files/composer%2Ejson/raw?ref=master'`
  
  # Trigger Pipeline  # Trigger Pipeline
-  if payloadHashBefore != payloadHash +  if payloadBefore != payloadCurrent && composerExists == '200' 
-  exec('curl --request POST --form "token=XXXXXXX" --form ref=master https://gitlab.example.org/api/v4/projects/36/trigger/pipeline')+  exec("curl --request POST --form \"token=#{trigger_token}\" --form ref=master #{gitlab_url}/api/v4/projects/#{satis_project_id}/trigger/pipeline")
  end  end
 +
 end end
 </code> </code>
gitlab_satis.txt · Last modified: 2018/11/14 16:54 by admin