Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
2c49c1af
Commit
2c49c1af
authored
Dec 19, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dockerfile-templates' into 'master'
Allow to use Dockerfile templates See merge request !7247
parents
4f77a3f8
14d47884
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
138 additions
and
6 deletions
+138
-6
app/assets/javascripts/api.js
app/assets/javascripts/api.js
+5
-0
app/assets/javascripts/blob/blob_dockerfile_selector.js.es6
app/assets/javascripts/blob/blob_dockerfile_selector.js.es6
+18
-0
app/assets/javascripts/blob/blob_dockerfile_selectors.js.es6
app/assets/javascripts/blob/blob_dockerfile_selectors.js.es6
+27
-0
app/assets/javascripts/blob_edit/edit_blob.js
app/assets/javascripts/blob_edit/edit_blob.js
+3
-0
app/assets/stylesheets/pages/editor.scss
app/assets/stylesheets/pages/editor.scss
+4
-2
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+4
-0
app/views/projects/blob/_editor.html.haml
app/views/projects/blob/_editor.html.haml
+2
-0
changelogs/unreleased/dockerfile-templates.yml
changelogs/unreleased/dockerfile-templates.yml
+4
-0
lib/api/templates.rb
lib/api/templates.rb
+8
-4
lib/gitlab/template/dockerfile_template.rb
lib/gitlab/template/dockerfile_template.rb
+30
-0
spec/features/projects/files/dockerfile_dropdown_spec.rb
spec/features/projects/files/dockerfile_dropdown_spec.rb
+30
-0
vendor/dockerfile/HTTPdDockerfile
vendor/dockerfile/HTTPdDockerfile
+3
-0
No files found.
app/assets/javascripts/api.js
View file @
2c49c1af
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,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
)
...
@@ -120,6 +121,10 @@
...
@@ -120,6 +121,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
)
...
...
app/assets/javascripts/blob/blob_dockerfile_selector.js.es6
0 → 100644
View file @
2c49c1af
/* global Api */
/*= require blob/template_selector */
(() => {
const global = window.gl || (window.gl = {});
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;
})();
app/assets/javascripts/blob/blob_dockerfile_selectors.js.es6
0 → 100644
View file @
2c49c1af
(() => {
const global = window.gl || (window.gl = {});
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 gl.BlobDockerfileSelector({
editor,
pattern: /(Dockerfile)/,
data: $dropdown.data('data'),
wrapper: $dropdown.closest('.js-dockerfile-selector-wrap'),
dropdown: $dropdown,
});
});
}
}
global.BlobDockerfileSelectors = BlobDockerfileSelectors;
})();
app/assets/javascripts/blob_edit/edit_blob.js
View file @
2c49c1af
...
@@ -36,6 +36,9 @@
...
@@ -36,6 +36,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
()
{
...
...
app/assets/stylesheets/pages/editor.scss
View file @
2c49c1af
...
@@ -75,7 +75,8 @@
...
@@ -75,7 +75,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
;
...
@@ -105,7 +106,8 @@
...
@@ -105,7 +106,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
;
}
}
...
...
app/helpers/blob_helper.rb
View file @
2c49c1af
...
@@ -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
,
...
...
app/views/projects/blob/_editor.html.haml
View file @
2c49c1af
...
@@ -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
}
}
)
.dockerfile-selector.js-dockerfile-selector-wrap.hidden
=
dropdown_tag
(
"Choose a Dockerfile template"
,
options:
{
toggle_class:
'btn 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'
)
...
...
changelogs/unreleased/dockerfile-templates.yml
0 → 100644
View file @
2c49c1af
---
title
:
Add support for Dockerfile templates
merge_request
:
7247
author
:
lib/api/templates.rb
View file @
2c49c1af
...
@@ -8,6 +8,10 @@ module API
...
@@ -8,6 +8,10 @@ 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:
{
klass:
Gitlab
::
Template
::
DockerfileTemplate
,
gitlab_version:
8.15
}
}
}.
freeze
}.
freeze
PROJECT_TEMPLATE_REGEX
=
PROJECT_TEMPLATE_REGEX
=
...
@@ -51,7 +55,7 @@ module API
...
@@ -51,7 +55,7 @@ module API
end
end
params
do
params
do
optional
:popular
,
type:
Boolean
,
desc:
'If passed, returns only popular licenses'
optional
:popular
,
type:
Boolean
,
desc:
'If passed, returns only popular licenses'
end
end
get
route
do
get
route
do
options
=
{
options
=
{
featured:
declared
(
params
).
popular
.
present?
?
true
:
nil
featured:
declared
(
params
).
popular
.
present?
?
true
:
nil
...
@@ -69,7 +73,7 @@ module API
...
@@ -69,7 +73,7 @@ module API
end
end
params
do
params
do
requires
:name
,
type:
String
,
desc:
'The name of the template'
requires
:name
,
type:
String
,
desc:
'The name of the template'
end
end
get
route
,
requirements:
{
name:
/[\w\.-]+/
}
do
get
route
,
requirements:
{
name:
/[\w\.-]+/
}
do
not_found!
(
'License'
)
unless
Licensee
::
License
.
find
(
declared
(
params
).
name
)
not_found!
(
'License'
)
unless
Licensee
::
License
.
find
(
declared
(
params
).
name
)
...
@@ -78,7 +82,7 @@ module API
...
@@ -78,7 +82,7 @@ module API
present
template
,
with:
Entities
::
RepoLicense
present
template
,
with:
Entities
::
RepoLicense
end
end
end
end
GLOBAL_TEMPLATE_TYPES
.
each
do
|
template_type
,
properties
|
GLOBAL_TEMPLATE_TYPES
.
each
do
|
template_type
,
properties
|
klass
=
properties
[
:klass
]
klass
=
properties
[
:klass
]
gitlab_version
=
properties
[
:gitlab_version
]
gitlab_version
=
properties
[
:gitlab_version
]
...
@@ -104,7 +108,7 @@ module API
...
@@ -104,7 +108,7 @@ module API
end
end
params
do
params
do
requires
:name
,
type:
String
,
desc:
'The name of the template'
requires
:name
,
type:
String
,
desc:
'The name of the template'
end
end
get
route
do
get
route
do
new_template
=
klass
.
find
(
declared
(
params
).
name
)
new_template
=
klass
.
find
(
declared
(
params
).
name
)
...
...
lib/gitlab/template/dockerfile_template.rb
0 → 100644
View file @
2c49c1af
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
spec/features/projects/files/dockerfile_dropdown_spec.rb
0 → 100644
View file @
2c49c1af
require 'spec_helper'
feature 'User wants to add a Dockerfile file', feature: true do
include WaitForAjax
before do
user = create(:user)
project = create(:project)
project.team << [user, :master]
login_as user
visit namespace_project_new_blob_path(project.namespace, project, 'master', file_name: 'Dockerfile')
end
scenario 'user can see Dockerfile dropdown' do
expect(page).to have_css('.dockerfile-selector')
end
scenario 'user can pick a Dockerfile file from the dropdown', js: true do
find('.js-dockerfile-selector').click
wait_for_ajax
within '.dockerfile-selector' do
find('.dropdown-input-field').set('HTTPd')
find('.dropdown-content li', text: 'HTTPd').click
end
wait_for_ajax
expect(page).to have_css('.dockerfile-selector .dropdown-toggle-text', text: 'HTTPd')
expect(page).to have_content('COPY ./ /usr/local/apache2/htdocs/')
end
end
vendor/dockerfile/HTTPdDockerfile
0 → 100644
View file @
2c49c1af
FROM httpd:alpine
COPY ./ /usr/local/apache2/htdocs/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment