mirror of https://github.com/portainer/portainer
parent
1f24320fa7
commit
76e1aa97e2
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/src-d/go-git.v4"
|
"gopkg.in/src-d/go-git.v4"
|
||||||
|
"gopkg.in/src-d/go-git.v4/plumbing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service represents a service for managing Git.
|
// Service represents a service for managing Git.
|
||||||
|
@ -19,21 +20,27 @@ func NewService(dataStorePath string) (*Service, error) {
|
||||||
|
|
||||||
// ClonePublicRepository clones a public git repository using the specified URL in the specified
|
// ClonePublicRepository clones a public git repository using the specified URL in the specified
|
||||||
// destination folder.
|
// destination folder.
|
||||||
func (service *Service) ClonePublicRepository(repositoryURL, destination string) error {
|
func (service *Service) ClonePublicRepository(repositoryURL, referenceName string, destination string) error {
|
||||||
return cloneRepository(repositoryURL, destination)
|
return cloneRepository(repositoryURL, referenceName, destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClonePrivateRepositoryWithBasicAuth clones a private git repository using the specified URL in the specified
|
// ClonePrivateRepositoryWithBasicAuth clones a private git repository using the specified URL in the specified
|
||||||
// destination folder. It will use the specified username and password for basic HTTP authentication.
|
// destination folder. It will use the specified username and password for basic HTTP authentication.
|
||||||
func (service *Service) ClonePrivateRepositoryWithBasicAuth(repositoryURL, destination, username, password string) error {
|
func (service *Service) ClonePrivateRepositoryWithBasicAuth(repositoryURL, referenceName string, destination, username, password string) error {
|
||||||
credentials := username + ":" + url.PathEscape(password)
|
credentials := username + ":" + url.PathEscape(password)
|
||||||
repositoryURL = strings.Replace(repositoryURL, "://", "://"+credentials+"@", 1)
|
repositoryURL = strings.Replace(repositoryURL, "://", "://"+credentials+"@", 1)
|
||||||
return cloneRepository(repositoryURL, destination)
|
return cloneRepository(repositoryURL, referenceName, destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneRepository(repositoryURL, destination string) error {
|
func cloneRepository(repositoryURL, referenceName string, destination string) error {
|
||||||
_, err := git.PlainClone(destination, false, &git.CloneOptions{
|
options := &git.CloneOptions{
|
||||||
URL: repositoryURL,
|
URL: repositoryURL,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if referenceName != "" {
|
||||||
|
options.ReferenceName = plumbing.ReferenceName(referenceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := git.PlainClone(destination, false, options)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,7 @@ func (handler *Handler) createComposeStackFromFileContent(w http.ResponseWriter,
|
||||||
type composeStackFromGitRepositoryPayload struct {
|
type composeStackFromGitRepositoryPayload struct {
|
||||||
Name string
|
Name string
|
||||||
RepositoryURL string
|
RepositoryURL string
|
||||||
|
RepositoryReferenceName string
|
||||||
RepositoryAuthentication bool
|
RepositoryAuthentication bool
|
||||||
RepositoryUsername string
|
RepositoryUsername string
|
||||||
RepositoryPassword string
|
RepositoryPassword string
|
||||||
|
@ -146,19 +147,21 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite
|
||||||
|
|
||||||
gitCloneParams := &cloneRepositoryParameters{
|
gitCloneParams := &cloneRepositoryParameters{
|
||||||
url: payload.RepositoryURL,
|
url: payload.RepositoryURL,
|
||||||
|
referenceName: payload.RepositoryReferenceName,
|
||||||
path: projectPath,
|
path: projectPath,
|
||||||
authentication: payload.RepositoryAuthentication,
|
authentication: payload.RepositoryAuthentication,
|
||||||
username: payload.RepositoryUsername,
|
username: payload.RepositoryUsername,
|
||||||
password: payload.RepositoryPassword,
|
password: payload.RepositoryPassword,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doCleanUp := true
|
||||||
|
defer handler.cleanUp(stack, &doCleanUp)
|
||||||
|
|
||||||
err = handler.cloneGitRepository(gitCloneParams)
|
err = handler.cloneGitRepository(gitCloneParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to clone git repository", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to clone git repository", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCleanUp := true
|
|
||||||
defer handler.cleanUp(stack, &doCleanUp)
|
|
||||||
|
|
||||||
config, configErr := handler.createComposeDeployConfig(r, stack, endpoint)
|
config, configErr := handler.createComposeDeployConfig(r, stack, endpoint)
|
||||||
if configErr != nil {
|
if configErr != nil {
|
||||||
return configErr
|
return configErr
|
||||||
|
|
|
@ -97,6 +97,7 @@ type swarmStackFromGitRepositoryPayload struct {
|
||||||
SwarmID string
|
SwarmID string
|
||||||
Env []portainer.Pair
|
Env []portainer.Pair
|
||||||
RepositoryURL string
|
RepositoryURL string
|
||||||
|
RepositoryReferenceName string
|
||||||
RepositoryAuthentication bool
|
RepositoryAuthentication bool
|
||||||
RepositoryUsername string
|
RepositoryUsername string
|
||||||
RepositoryPassword string
|
RepositoryPassword string
|
||||||
|
@ -156,19 +157,21 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter,
|
||||||
|
|
||||||
gitCloneParams := &cloneRepositoryParameters{
|
gitCloneParams := &cloneRepositoryParameters{
|
||||||
url: payload.RepositoryURL,
|
url: payload.RepositoryURL,
|
||||||
|
referenceName: payload.RepositoryReferenceName,
|
||||||
path: projectPath,
|
path: projectPath,
|
||||||
authentication: payload.RepositoryAuthentication,
|
authentication: payload.RepositoryAuthentication,
|
||||||
username: payload.RepositoryUsername,
|
username: payload.RepositoryUsername,
|
||||||
password: payload.RepositoryPassword,
|
password: payload.RepositoryPassword,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doCleanUp := true
|
||||||
|
defer handler.cleanUp(stack, &doCleanUp)
|
||||||
|
|
||||||
err = handler.cloneGitRepository(gitCloneParams)
|
err = handler.cloneGitRepository(gitCloneParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to clone git repository", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to clone git repository", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCleanUp := true
|
|
||||||
defer handler.cleanUp(stack, &doCleanUp)
|
|
||||||
|
|
||||||
config, configErr := handler.createSwarmDeployConfig(r, stack, endpoint, false)
|
config, configErr := handler.createSwarmDeployConfig(r, stack, endpoint, false)
|
||||||
if configErr != nil {
|
if configErr != nil {
|
||||||
return configErr
|
return configErr
|
||||||
|
|
|
@ -2,6 +2,7 @@ package stacks
|
||||||
|
|
||||||
type cloneRepositoryParameters struct {
|
type cloneRepositoryParameters struct {
|
||||||
url string
|
url string
|
||||||
|
referenceName string
|
||||||
path string
|
path string
|
||||||
authentication bool
|
authentication bool
|
||||||
username string
|
username string
|
||||||
|
@ -10,7 +11,7 @@ type cloneRepositoryParameters struct {
|
||||||
|
|
||||||
func (handler *Handler) cloneGitRepository(parameters *cloneRepositoryParameters) error {
|
func (handler *Handler) cloneGitRepository(parameters *cloneRepositoryParameters) error {
|
||||||
if parameters.authentication {
|
if parameters.authentication {
|
||||||
return handler.GitService.ClonePrivateRepositoryWithBasicAuth(parameters.url, parameters.path, parameters.username, parameters.password)
|
return handler.GitService.ClonePrivateRepositoryWithBasicAuth(parameters.url, parameters.referenceName, parameters.path, parameters.username, parameters.password)
|
||||||
}
|
}
|
||||||
return handler.GitService.ClonePublicRepository(parameters.url, parameters.path)
|
return handler.GitService.ClonePublicRepository(parameters.url, parameters.referenceName, parameters.path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -570,8 +570,8 @@ type (
|
||||||
|
|
||||||
// GitService represents a service for managing Git.
|
// GitService represents a service for managing Git.
|
||||||
GitService interface {
|
GitService interface {
|
||||||
ClonePublicRepository(repositoryURL, destination string) error
|
ClonePublicRepository(repositoryURL, referenceName string, destination string) error
|
||||||
ClonePrivateRepositoryWithBasicAuth(repositoryURL, destination, username, password string) error
|
ClonePrivateRepositoryWithBasicAuth(repositoryURL, referenceName string, destination, username, password string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// JobScheduler represents a service to run jobs on a periodic basis.
|
// JobScheduler represents a service to run jobs on a periodic basis.
|
||||||
|
|
|
@ -4184,6 +4184,10 @@ definitions:
|
||||||
type: "string"
|
type: "string"
|
||||||
example: "https://github.com/openfaas/faas"
|
example: "https://github.com/openfaas/faas"
|
||||||
description: "URL of a Git repository hosting the Stack file. Required when using the 'repository' deployment method."
|
description: "URL of a Git repository hosting the Stack file. Required when using the 'repository' deployment method."
|
||||||
|
RepositoryReferenceName:
|
||||||
|
type: "string"
|
||||||
|
example: "refs/heads/master"
|
||||||
|
description: "Reference name of a Git repository hosting the Stack file. Used in 'repository' deployment method."
|
||||||
ComposeFilePathInRepository:
|
ComposeFilePathInRepository:
|
||||||
type: "string"
|
type: "string"
|
||||||
example: "docker-compose.yml"
|
example: "docker-compose.yml"
|
||||||
|
|
|
@ -282,6 +282,7 @@ function StackServiceFactory($q, Stack, ResourceControlService, FileUploadServic
|
||||||
var payload = {
|
var payload = {
|
||||||
Name: name,
|
Name: name,
|
||||||
RepositoryURL: repositoryOptions.RepositoryURL,
|
RepositoryURL: repositoryOptions.RepositoryURL,
|
||||||
|
RepositoryReferenceName: repositoryOptions.RepositoryReferenceName,
|
||||||
ComposeFilePathInRepository: repositoryOptions.ComposeFilePathInRepository,
|
ComposeFilePathInRepository: repositoryOptions.ComposeFilePathInRepository,
|
||||||
RepositoryAuthentication: repositoryOptions.RepositoryAuthentication,
|
RepositoryAuthentication: repositoryOptions.RepositoryAuthentication,
|
||||||
RepositoryUsername: repositoryOptions.RepositoryUsername,
|
RepositoryUsername: repositoryOptions.RepositoryUsername,
|
||||||
|
@ -301,6 +302,7 @@ function StackServiceFactory($q, Stack, ResourceControlService, FileUploadServic
|
||||||
Name: name,
|
Name: name,
|
||||||
SwarmID: swarm.Id,
|
SwarmID: swarm.Id,
|
||||||
RepositoryURL: repositoryOptions.RepositoryURL,
|
RepositoryURL: repositoryOptions.RepositoryURL,
|
||||||
|
RepositoryReferenceName: repositoryOptions.RepositoryReferenceName,
|
||||||
ComposeFilePathInRepository: repositoryOptions.ComposeFilePathInRepository,
|
ComposeFilePathInRepository: repositoryOptions.ComposeFilePathInRepository,
|
||||||
RepositoryAuthentication: repositoryOptions.RepositoryAuthentication,
|
RepositoryAuthentication: repositoryOptions.RepositoryAuthentication,
|
||||||
RepositoryUsername: repositoryOptions.RepositoryUsername,
|
RepositoryUsername: repositoryOptions.RepositoryUsername,
|
||||||
|
|
|
@ -7,6 +7,7 @@ function ($scope, $state, StackService, Authentication, Notifications, FormValid
|
||||||
StackFileContent: '',
|
StackFileContent: '',
|
||||||
StackFile: null,
|
StackFile: null,
|
||||||
RepositoryURL: '',
|
RepositoryURL: '',
|
||||||
|
RepositoryReferenceName: '',
|
||||||
RepositoryAuthentication: false,
|
RepositoryAuthentication: false,
|
||||||
RepositoryUsername: '',
|
RepositoryUsername: '',
|
||||||
RepositoryPassword: '',
|
RepositoryPassword: '',
|
||||||
|
@ -55,6 +56,7 @@ function ($scope, $state, StackService, Authentication, Notifications, FormValid
|
||||||
} else if (method === 'repository') {
|
} else if (method === 'repository') {
|
||||||
var repositoryOptions = {
|
var repositoryOptions = {
|
||||||
RepositoryURL: $scope.formValues.RepositoryURL,
|
RepositoryURL: $scope.formValues.RepositoryURL,
|
||||||
|
RepositoryReferenceName: $scope.formValues.RepositoryReferenceName,
|
||||||
ComposeFilePathInRepository: $scope.formValues.ComposeFilePathInRepository,
|
ComposeFilePathInRepository: $scope.formValues.ComposeFilePathInRepository,
|
||||||
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
||||||
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
||||||
|
@ -77,6 +79,7 @@ function ($scope, $state, StackService, Authentication, Notifications, FormValid
|
||||||
} else if (method === 'repository') {
|
} else if (method === 'repository') {
|
||||||
var repositoryOptions = {
|
var repositoryOptions = {
|
||||||
RepositoryURL: $scope.formValues.RepositoryURL,
|
RepositoryURL: $scope.formValues.RepositoryURL,
|
||||||
|
RepositoryReferenceName: $scope.formValues.RepositoryReferenceName,
|
||||||
ComposeFilePathInRepository: $scope.formValues.ComposeFilePathInRepository,
|
ComposeFilePathInRepository: $scope.formValues.ComposeFilePathInRepository,
|
||||||
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
||||||
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
||||||
|
|
|
@ -125,6 +125,17 @@
|
||||||
<input type="text" class="form-control" ng-model="formValues.RepositoryURL" id="stack_repository_url" placeholder="https://github.com/portainer/portainer-compose">
|
<input type="text" class="form-control" ng-model="formValues.RepositoryURL" id="stack_repository_url" placeholder="https://github.com/portainer/portainer-compose">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<span class="col-sm-12 text-muted small">
|
||||||
|
Specify a reference of the repository using the following syntax: branches with <code>refs/heads/branch_name</code> or tags with <code>refs/tags/tag_name</code>. If not specified, will use the default <code>HEAD</code> reference normally the <code>master</code> branch.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="stack_repository_url" class="col-sm-2 control-label text-left">Repository reference</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="text" class="form-control" ng-model="formValues.RepositoryReferenceName" id="stack_repository_reference_name" placeholder="refs/heads/master">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<span class="col-sm-12 text-muted small">
|
<span class="col-sm-12 text-muted small">
|
||||||
Indicate the path to the Compose file from the root of your repository.
|
Indicate the path to the Compose file from the root of your repository.
|
||||||
|
|
Loading…
Reference in New Issue