Commit 6970c1f3 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Luke "Jared" Bennett

Allow to use Dockerfile templates

parent 35142a09
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
licensePath: "/api/:version/templates/licenses/:key", licensePath: "/api/:version/templates/licenses/:key",
gitignorePath: "/api/:version/templates/gitignores/:key", gitignorePath: "/api/:version/templates/gitignores/:key",
gitlabCiYmlPath: "/api/:version/templates/gitlab_ci_ymls/:key", gitlabCiYmlPath: "/api/:version/templates/gitlab_ci_ymls/:key",
dockerfilePath: "/api/:version/dockerfiles/:key",
issuableTemplatePath: "/:namespace_path/:project_path/templates/:type/:key", issuableTemplatePath: "/:namespace_path/:project_path/templates/:type/:key",
group: function(group_id, callback) { group: function(group_id, callback) {
var url = Api.buildUrl(Api.groupPath) var url = Api.buildUrl(Api.groupPath)
...@@ -119,6 +120,10 @@ ...@@ -119,6 +120,10 @@
return callback(file); return callback(file);
}); });
}, },
dockerfileYml: function(key, callback) {
var url = Api.buildUrl(Api.dockerfilePath).replace(':key', key);
$.get(url, callback);
},
issueTemplate: function(namespacePath, projectPath, key, type, callback) { issueTemplate: function(namespacePath, projectPath, key, type, callback) {
var url = Api.buildUrl(Api.issuableTemplatePath) var url = Api.buildUrl(Api.issuableTemplatePath)
.replace(':key', key) .replace(':key', key)
......
...@@ -38,4 +38,40 @@ ...@@ -38,4 +38,40 @@
global.BlobCiYamlSelectors = BlobCiYamlSelectors; global.BlobCiYamlSelectors = BlobCiYamlSelectors;
class BlobDockerfileSelector extends gl.TemplateSelector {
requestFile(query) {
return Api.dockerfileYml(query.name, this.requestFileSuccess.bind(this));
}
requestFileSuccess(file) {
return super.requestFileSuccess(file);
}
}
global.BlobDockerfileSelector = BlobDockerfileSelector;
class BlobDockerfileSelectors {
constructor({ editor, $dropdowns } = {}) {
this.editor = editor;
this.$dropdowns = $dropdowns || $('.js-dockerfile-selector');
this.initSelectors();
}
initSelectors() {
const editor = this.editor;
this.$dropdowns.each((i, dropdown) => {
const $dropdown = $(dropdown);
return new BlobDockerfileSelector({
editor,
pattern: /(Dockerfile)/,
data: $dropdown.data('data'),
wrapper: $dropdown.closest('.js-dockerfile-selector-wrap'),
dropdown: $dropdown
});
});
}
}
global.BlobDockerfileSelectors = BlobDockerfileSelectors;
})(window.gl || (window.gl = {})); })(window.gl || (window.gl = {}));
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
new gl.BlobCiYamlSelectors({ new gl.BlobCiYamlSelectors({
editor: this.editor editor: this.editor
}); });
new gl.BlobDockerfileSelectors({
editor: this.editor
});
} }
EditBlob.prototype.initModePanesAndLinks = function() { EditBlob.prototype.initModePanesAndLinks = function() {
......
...@@ -67,7 +67,8 @@ ...@@ -67,7 +67,8 @@
.soft-wrap-toggle, .soft-wrap-toggle,
.license-selector, .license-selector,
.gitignore-selector, .gitignore-selector,
.gitlab-ci-yml-selector { .gitlab-ci-yml-selector,
.dockerfile-selector {
display: inline-block; display: inline-block;
vertical-align: top; vertical-align: top;
font-family: $regular_font; font-family: $regular_font;
...@@ -97,7 +98,8 @@ ...@@ -97,7 +98,8 @@
.gitignore-selector, .gitignore-selector,
.license-selector, .license-selector,
.gitlab-ci-yml-selector { .gitlab-ci-yml-selector,
.dockerfile-selector {
.dropdown { .dropdown {
line-height: 21px; line-height: 21px;
} }
......
...@@ -191,6 +191,10 @@ module BlobHelper ...@@ -191,6 +191,10 @@ module BlobHelper
@gitlab_ci_ymls ||= Gitlab::Template::GitlabCiYmlTemplate.dropdown_names @gitlab_ci_ymls ||= Gitlab::Template::GitlabCiYmlTemplate.dropdown_names
end end
def dockerfile_names
@dockerfile_names ||= Gitlab::Template::DockerfileTemplate.dropdown_names
end
def blob_editor_paths def blob_editor_paths
{ {
'relative-url-root' => Rails.application.config.relative_url_root, 'relative-url-root' => Rails.application.config.relative_url_root,
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
= dropdown_tag("Choose a .gitignore template", options: { toggle_class: 'btn js-gitignore-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: gitignore_names } } ) = dropdown_tag("Choose a .gitignore template", options: { toggle_class: 'btn js-gitignore-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: gitignore_names } } )
.gitlab-ci-yml-selector.js-gitlab-ci-yml-selector-wrap.hidden .gitlab-ci-yml-selector.js-gitlab-ci-yml-selector-wrap.hidden
= dropdown_tag("Choose a GitLab CI Yaml template", options: { toggle_class: 'btn js-gitlab-ci-yml-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls } } ) = dropdown_tag("Choose a GitLab CI Yaml template", options: { toggle_class: 'btn js-gitlab-ci-yml-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls } } )
.gitlab-ci-yml-selector.js-dockerfile-selector-wrap.hidden
= dropdown_tag("Choose a Dockerfile template", options: { toggle_class: 'js-dockerfile-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: dockerfile_names } } )
= button_tag class: 'soft-wrap-toggle btn', type: 'button' do = button_tag class: 'soft-wrap-toggle btn', type: 'button' do
%span.no-wrap %span.no-wrap
= custom_icon('icon_no_wrap') = custom_icon('icon_no_wrap')
......
...@@ -8,7 +8,8 @@ module API ...@@ -8,7 +8,8 @@ module API
gitlab_ci_ymls: { gitlab_ci_ymls: {
klass: Gitlab::Template::GitlabCiYmlTemplate, klass: Gitlab::Template::GitlabCiYmlTemplate,
gitlab_version: 8.9 gitlab_version: 8.9
} },
dockerfiles: Gitlab::Template::DockerfileTemplate
}.freeze }.freeze
PROJECT_TEMPLATE_REGEX = PROJECT_TEMPLATE_REGEX =
/[\<\{\[] /[\<\{\[]
......
module Gitlab
module Template
class DockerfileTemplate < BaseTemplate
def content
explanation = "# This file is a template, and might need editing before it works on your project."
[explanation, super].join("\n")
end
class << self
def extension
'Dockerfile'
end
def categories
{
"General" => ''
}
end
def base_dir
Rails.root.join('vendor/dockerfile')
end
def finder(project = nil)
Gitlab::Template::Finders::GlobalTemplateFinder.new(self.base_dir, self.extension, self.categories)
end
end
end
end
end
FROM httpd:alpine
COPY ./ /usr/local/apache2/htdocs/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment