Skip to content

Instantly share code, notes, and snippets.

@hh
Last active Jul 10, 2018
Embed
What would you like to do?
Patching and Running GitLab with a Custom CI Config Path as a URL
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index a2126cffdc..adfb4ca9b0 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -346,17 +346,21 @@ module Ci
project.ci_config_path
end
end
-
+ require 'open-uri' #replace with another approach as desired
def ci_yaml_file
return @ci_yaml_file if defined?(@ci_yaml_file)
-
@ci_yaml_file = begin
- project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path)
- rescue Rugged::ReferenceError, GRPC::NotFound, GRPC::Internal
- self.yaml_errors =
- "Failed to load CI/CD config file at #{ci_yaml_file_path}"
- nil
- end
+ if ci_yaml_file_path =~ URI::regexp # if this is a URL
+ url_with_GITREF = ci_yaml_file_path.gsub('GITREF',@attributes['ref'].value)
+ open(url_with_GITREF).read() # open and read the contents
+ else # otherwise treat it as relative path within repo (at this commit)
+ project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path)
+ end
+ rescue Rugged::ReferenceError, GRPC::NotFound, GRPC::Internal
+ self.yaml_errors =
+ "Failed to load CI/CD config file at #{ci_yaml_file_path}"
+ nil
+ end
end
def has_yaml_errors?
version: '2'
services:
gitlab.my.coop:
# replace image with patched build from above
#image: gitlab/gitlab-ce:10.7.3-ce.0
build:
context: ./
# dockerfile: Dockerfile-patch-gitlab
# configure as normal
ports: # you'll need to run your hosts ssh on another port
- "22:22"
- "80:80"
- "443:443"
environment:
GITLAB_PROMETHEUS_METRICS_ENABLED: 'true'
GITLAB_OMNIBUS_CONFIG: |
# Configure gitlab here
FROM gitlab/gitlab-ce:10.7.3-ce.0
COPY *.patch /opt/gitlab/embedded/service/gitlab-rails/
RUN apt-get update ; apt-get install -y patch
# Allows http urls for .gitlab-ci.yml
# This patch may need some work cleanly apply with recent versions
RUN cd /opt/gitlab/embedded/service/gitlab-rails ; \
patch -p1 < ci_yaml_http.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment