feat(stack): make stack created from app template editable EE-1941 (#6104)

feat(stack): make stack from app template editable
pull/6233/head
Hao Zhang 3 years ago committed by GitHub
parent 0627e16b35
commit 9f5ac154aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,6 +25,8 @@ type composeStackFromFileContentPayload struct {
StackFileContent string `example:"version: 3\n services:\n web:\n image:nginx" validate:"required"`
// A list of environment(endpoint) variables used during stack deployment
Env []portainer.Pair `example:""`
// Whether the stack is from a app template
FromAppTemplate bool `example:"false"`
}
func (payload *composeStackFromFileContentPayload) Validate(r *http.Request) error {
@ -101,14 +103,15 @@ func (handler *Handler) createComposeStackFromFileContent(w http.ResponseWriter,
stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{
ID: portainer.StackID(stackID),
Name: payload.Name,
Type: portainer.DockerComposeStack,
EndpointID: endpoint.ID,
EntryPoint: filesystem.ComposeFileDefaultName,
Env: payload.Env,
Status: portainer.StackStatusActive,
CreationDate: time.Now().Unix(),
ID: portainer.StackID(stackID),
Name: payload.Name,
Type: portainer.DockerComposeStack,
EndpointID: endpoint.ID,
EntryPoint: filesystem.ComposeFileDefaultName,
Env: payload.Env,
Status: portainer.StackStatusActive,
CreationDate: time.Now().Unix(),
FromAppTemplate: payload.FromAppTemplate,
}
stackFolder := strconv.Itoa(int(stack.ID))
@ -163,6 +166,8 @@ type composeStackFromGitRepositoryPayload struct {
AutoUpdate *portainer.StackAutoUpdate
// A list of environment(endpoint) variables used during stack deployment
Env []portainer.Pair
// Whether the stack is from a app template
FromAppTemplate bool `example:"false"`
}
func (payload *composeStackFromGitRepositoryPayload) Validate(r *http.Request) error {
@ -239,6 +244,7 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite
AdditionalFiles: payload.AdditionalFiles,
AutoUpdate: payload.AutoUpdate,
Env: payload.Env,
FromAppTemplate: payload.FromAppTemplate,
GitConfig: &gittypes.RepoConfig{
URL: payload.RepositoryURL,
ReferenceName: payload.RepositoryReferenceName,

@ -26,6 +26,8 @@ type swarmStackFromFileContentPayload struct {
StackFileContent string `example:"version: 3\n services:\n web:\n image:nginx" validate:"required"`
// A list of environment(endpoint) variables used during stack deployment
Env []portainer.Pair
// Whether the stack is from a app template
FromAppTemplate bool `example:"false"`
}
func (payload *swarmStackFromFileContentPayload) Validate(r *http.Request) error {
@ -61,15 +63,16 @@ func (handler *Handler) createSwarmStackFromFileContent(w http.ResponseWriter, r
stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{
ID: portainer.StackID(stackID),
Name: payload.Name,
Type: portainer.DockerSwarmStack,
SwarmID: payload.SwarmID,
EndpointID: endpoint.ID,
EntryPoint: filesystem.ComposeFileDefaultName,
Env: payload.Env,
Status: portainer.StackStatusActive,
CreationDate: time.Now().Unix(),
ID: portainer.StackID(stackID),
Name: payload.Name,
Type: portainer.DockerSwarmStack,
SwarmID: payload.SwarmID,
EndpointID: endpoint.ID,
EntryPoint: filesystem.ComposeFileDefaultName,
Env: payload.Env,
Status: portainer.StackStatusActive,
CreationDate: time.Now().Unix(),
FromAppTemplate: payload.FromAppTemplate,
}
stackFolder := strconv.Itoa(int(stack.ID))
@ -121,6 +124,8 @@ type swarmStackFromGitRepositoryPayload struct {
RepositoryUsername string `example:"myGitUsername"`
// Password used in basic authentication. Required when RepositoryAuthentication is true.
RepositoryPassword string `example:"myGitPassword"`
// Whether the stack is from a app template
FromAppTemplate bool `example:"false"`
// Path to the Stack file inside the Git repository
ComposeFile string `example:"docker-compose.yml" default:"docker-compose.yml"`
// Applicable when deploying with multiple stack files
@ -189,6 +194,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter,
EntryPoint: payload.ComposeFile,
AdditionalFiles: payload.AdditionalFiles,
AutoUpdate: payload.AutoUpdate,
FromAppTemplate: payload.FromAppTemplate,
GitConfig: &gittypes.RepoConfig{
URL: payload.RepositoryURL,
ReferenceName: payload.RepositoryReferenceName,

@ -849,6 +849,8 @@ type (
AutoUpdate *StackAutoUpdate `json:"AutoUpdate"`
// The git config of this stack
GitConfig *gittypes.RepoConfig
// Whether the stack is from a app template
FromAppTemplate bool `example:"false"`
// Kubernetes namespace if stack is a kube application
Namespace string `example:"default"`
// IsComposeFormat indicates if the Kubernetes stack is created from a Docker Compose file

@ -21,6 +21,7 @@ export function StackViewModel(data) {
this.Orphaned = false;
this.Checked = false;
this.GitConfig = data.GitConfig;
this.FromAppTemplate = data.FromAppTemplate;
this.AdditionalFiles = data.AdditionalFiles;
this.AutoUpdate = data.AutoUpdate;
}

@ -363,6 +363,7 @@ angular.module('portainer.app').factory('StackService', [
RepositoryUsername: repositoryOptions.RepositoryUsername,
RepositoryPassword: repositoryOptions.RepositoryPassword,
Env: env,
FromAppTemplate: repositoryOptions.FromAppTemplate,
};
if (repositoryOptions.AutoUpdate) {
@ -389,6 +390,7 @@ angular.module('portainer.app').factory('StackService', [
RepositoryUsername: repositoryOptions.RepositoryUsername,
RepositoryPassword: repositoryOptions.RepositoryPassword,
Env: env,
FromAppTemplate: repositoryOptions.FromAppTemplate,
};
if (repositoryOptions.AutoUpdate) {

@ -110,7 +110,8 @@
</div>
<!-- !associate -->
<stack-redeploy-git-form ng-if="stack.GitConfig" model="stack.GitConfig" stack="stack" authorization="PortainerStackUpdate"> </stack-redeploy-git-form>
<stack-redeploy-git-form ng-if="stack.GitConfig && !stack.FromAppTemplate" model="stack.GitConfig" stack="stack" authorization="PortainerStackUpdate">
</stack-redeploy-git-form>
<stack-duplication-form
ng-if="regular && endpoints.length > 0"
endpoints="endpoints"
@ -125,7 +126,7 @@
</uib-tab>
<!-- !tab-info -->
<!-- tab-file -->
<uib-tab index="1" select="showEditor()" ng-if="!external && !stack.GitConfig">
<uib-tab index="1" select="showEditor()" ng-if="!external && (!stack.GitConfig || stack.FromAppTemplate)">
<uib-tab-heading> <i class="fa fa-pencil-alt space-right" aria-hidden="true"></i> Editor </uib-tab-heading>
<form class="form-horizontal" ng-if="state.showEditorTab" style="margin-top: 10px;" name="stackUpdateForm">
<div class="form-group">

@ -141,6 +141,7 @@ angular.module('portainer.app').controller('TemplatesController', [
var repositoryOptions = {
RepositoryURL: template.Repository.url,
ComposeFilePathInRepository: template.Repository.stackfile,
FromAppTemplate: true,
};
const endpointId = +$state.params.endpointId;
@ -178,6 +179,7 @@ angular.module('portainer.app').controller('TemplatesController', [
var repositoryOptions = {
RepositoryURL: template.Repository.url,
ComposeFilePathInRepository: template.Repository.stackfile,
FromAppTemplate: true,
};
const endpointId = +$state.params.endpointId;

Loading…
Cancel
Save