@ -50,13 +50,12 @@ var funcmap = map[StackRemoteOperation]buildCmdFunc{
// build the unpacker cmd for stack based on stackOperation
// build the unpacker cmd for stack based on stackOperation
func ( d * stackDeployer ) buildUnpackerCmdForStack ( stack * portainer . Stack , operation StackRemoteOperation , opts unpackerCmdBuilderOptions ) ( [ ] string , error ) {
func ( d * stackDeployer ) buildUnpackerCmdForStack ( stack * portainer . Stack , operation StackRemoteOperation , opts unpackerCmdBuilderOptions ) ( [ ] string , error ) {
fn := funcmap [ operation ]
fn := funcmap [ operation ]
if fn == nil {
if fn == nil {
return nil , fmt . Errorf ( "unknown stack operation %s" , operation )
return nil , fmt . Errorf ( "unknown stack operation %s" , operation )
}
}
registriesStrings := ge tRegistry ( opts . registries , d . dataStore )
registriesStrings := ge nerateRegistriesStrings ( opts . registries , d . dataStore )
envStrings := getEnv ( stack . Env )
envStrings := getEnv ( stack . Env )
return fn ( stack , opts , registriesStrings , envStrings ) , nil
return fn ( stack , opts , registriesStrings , envStrings ) , nil
@ -64,72 +63,74 @@ func (d *stackDeployer) buildUnpackerCmdForStack(stack *portainer.Stack, operati
// deploy [-u username -p password] [--skip-tls-verify] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <ref> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
// deploy [-u username -p password] [--skip-tls-verify] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <ref> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
func buildDeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildDeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
cmd := [ ] string { UnpackerCmdDeploy }
cmd = append ( cmd , UnpackerCmdDeploy )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
cmd = append ( cmd , env ... )
cmd = append ( cmd , env ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , stack . GitConfig . URL )
cmd = append ( cmd ,
cmd = append ( cmd , stack . GitConfig . ReferenceName )
stack . GitConfig . URL ,
cmd = append ( cmd , stack . Name )
stack . GitConfig . ReferenceName ,
cmd = append ( cmd , opts . composeDestination )
stack . Name ,
cmd = append ( cmd , stack . EntryPoint )
opts . composeDestination ,
cmd = appendAdditionalFiles ( cmd , stack . AdditionalFiles )
stack . EntryPoint ,
return cmd
)
return append ( cmd , stack . AdditionalFiles ... )
}
}
// undeploy [-u username -p password] [-k] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
// undeploy [-u username -p password] [-k] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
func buildUndeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildUndeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
cmd := [ ] string { UnpackerCmdUndeploy }
cmd = append ( cmd , UnpackerCmdUndeploy )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = append ( cmd , stack . GitConfig . URL )
cmd = append ( cmd , stack . GitConfig . URL ,
cmd = append ( cmd , stack . Name )
stack . Name ,
cmd = append ( cmd , opts . composeDestination )
opts . composeDestination ,
cmd = append ( cmd , stack . EntryPoint )
stack . EntryPoint ,
cmd = appendAdditionalFiles ( cmd , stack . AdditionalFiles )
)
return cmd
return append ( cmd , stack . AdditionalFiles ... )
}
}
// deploy [-u username -p password] [--skip-tls-verify] [-k] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
// deploy [-u username -p password] [--skip-tls-verify] [-k] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
func buildComposeStartCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildComposeStartCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
cmd := [ ] string { UnpackerCmdDeploy }
cmd = append ( cmd , UnpackerCmdDeploy )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
cmd = append ( cmd , "-k" )
cmd = append ( cmd , "-k" )
cmd = append ( cmd , env ... )
cmd = append ( cmd , env ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , stack . GitConfig . URL )
cmd = append ( cmd , stack . GitConfig . URL ,
cmd = append ( cmd , stack . GitConfig . ReferenceName )
stack . GitConfig . ReferenceName ,
cmd = append ( cmd , stack . Name )
stack . Name ,
cmd = append ( cmd , opts . composeDestination )
opts . composeDestination ,
cmd = append ( cmd , stack . EntryPoint )
stack . EntryPoint ,
cmd = appendAdditionalFiles ( cmd , stack . AdditionalFiles )
)
return cmd
return append ( cmd , stack . AdditionalFiles ... )
}
}
// undeploy [-u username -p password] [-k] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
// undeploy [-u username -p password] [-k] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
func buildComposeStopCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildComposeStopCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
cmd := [ ] string { UnpackerCmdUndeploy }
cmd = append ( cmd , UnpackerCmdUndeploy )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = append ( cmd , "-k" )
cmd = append ( cmd ,
cmd = append ( cmd , stack . GitConfig . URL )
"-k" ,
cmd = append ( cmd , stack . Name )
stack . GitConfig . URL ,
cmd = append ( cmd , opts . composeDestination )
stack . Name ,
cmd = append ( cmd , stack . EntryPoint )
opts . composeDestination ,
cmd = appendAdditionalFiles ( cmd , stack . AdditionalFiles )
stack . EntryPoint ,
return cmd
)
return append ( cmd , stack . AdditionalFiles ... )
}
}
// swarm-deploy [-u username -p password] [--skip-tls-verify] [-f] [-r] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <git-ref> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
// swarm-deploy [-u username -p password] [--skip-tls-verify] [-f] [-r] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <git-ref> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
func buildSwarmDeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildSwarmDeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
cmd := [ ] string { UnpackerCmdSwarmDeploy }
cmd = append ( cmd , UnpackerCmdSwarmDeploy )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendGitAuthIfNeeded ( cmd , stack )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
if opts . pullImage {
if opts . pullImage {
cmd = append ( cmd , "-f" )
cmd = append ( cmd , "-f" )
}
}
@ -137,85 +138,76 @@ func buildSwarmDeployCmd(stack *portainer.Stack, opts unpackerCmdBuilderOptions,
if opts . prune {
if opts . prune {
cmd = append ( cmd , "-r" )
cmd = append ( cmd , "-r" )
}
}
cmd = append ( cmd , env ... )
cmd = append ( cmd , env ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , stack . GitConfig . URL )
cmd = append ( cmd , stack . GitConfig . URL ,
cmd = append ( cmd , stack . GitConfig . ReferenceName )
stack . GitConfig . ReferenceName ,
cmd = append ( cmd , stack . Name )
stack . Name ,
cmd = append ( cmd , opts . composeDestination )
opts . composeDestination ,
cmd = append ( cmd , stack . EntryPoint )
stack . EntryPoint ,
cmd = appendAdditionalFiles ( cmd , stack . AdditionalFiles )
)
return cmd
return append ( cmd , stack . AdditionalFiles ... )
}
}
// swarm-undeploy [-k] <project-name> <destination>
// swarm-undeploy [-k] <project-name> <destination>
func buildSwarmUndeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildSwarmUndeployCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
return [ ] string { UnpackerCmdSwarmUndeploy , stack . Name , opts . composeDestination }
cmd = append ( cmd , UnpackerCmdSwarmUndeploy )
cmd = append ( cmd , stack . Name )
cmd = append ( cmd , opts . composeDestination )
return cmd
}
}
// swarm-deploy [-u username -p password] [-f] [-r] [-k] [--skip-tls-verify] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
// swarm-deploy [-u username -p password] [-f] [-r] [-k] [--skip-tls-verify] [--env KEY1=VALUE1 --env KEY2=VALUE2] <git-repo-url> <project-name> <destination> <compose-file-path> [<more-file-paths>...]
func buildSwarmStartCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildSwarmStartCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
cmd := [ ] string { UnpackerCmdSwarmDeploy , "-f" , "-r" , "-k" }
cmd = append ( cmd , UnpackerCmdSwarmDeploy , "-f" , "-r" , "-k" )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
cmd = appendSkipTLSVerifyIfNeeded ( cmd , stack )
cmd = append ( cmd , getEnv ( stack . Env ) ... )
cmd = append ( cmd , getEnv ( stack . Env ) ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , registries ... )
cmd = append ( cmd , stack . GitConfig . URL )
cmd = append ( cmd , stack . GitConfig . URL ,
cmd = append ( cmd , stack . GitConfig . ReferenceName )
stack . GitConfig . ReferenceName ,
cmd = append ( cmd , stack . Name )
stack . Name ,
cmd = append ( cmd , opts . composeDestination )
opts . composeDestination ,
cmd = append ( cmd , stack . EntryPoint )
stack . EntryPoint ,
cmd = appendAdditionalFiles ( cmd , stack . AdditionalFiles )
)
return cmd
return append ( cmd , stack . AdditionalFiles ... )
}
}
// swarm-undeploy [-k] <project-name> <destination>
// swarm-undeploy [-k] <project-name> <destination>
func buildSwarmStopCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
func buildSwarmStopCmd ( stack * portainer . Stack , opts unpackerCmdBuilderOptions , registries [ ] string , env [ ] string ) [ ] string {
cmd := [ ] string { }
return [ ] string { UnpackerCmdSwarmUndeploy , "-k" , stack . Name , opts . composeDestination }
cmd = append ( cmd , UnpackerCmdSwarmUndeploy , "-k" )
cmd = append ( cmd , stack . Name )
cmd = append ( cmd , opts . composeDestination )
return cmd
}
}
func appendGitAuthIfNeeded ( cmd [ ] string , stack * portainer . Stack ) [ ] string {
func appendGitAuthIfNeeded ( cmd [ ] string , stack * portainer . Stack ) [ ] string {
if stack . GitConfig . Authentication != nil && len ( stack . GitConfig . Authentication . Password ) != 0 {
if stack . GitConfig . Authentication == nil || stack . GitConfig . Authentication . Password == "" {
cmd = append ( cmd , "-u" , stack . GitConfig . Authentication . Username , "-p" , stack . GitConfig . Authentication . Password )
return cmd
}
}
return cmd
return append ( cmd , "-u" , stack . GitConfig . Authentication . Username , "-p" , stack . GitConfig . Authentication . Password )
}
}
func appendSkipTLSVerifyIfNeeded ( cmd [ ] string , stack * portainer . Stack ) [ ] string {
func appendSkipTLSVerifyIfNeeded ( cmd [ ] string , stack * portainer . Stack ) [ ] string {
if stack . GitConfig . TLSSkipVerify {
if ! stack . GitConfig . TLSSkipVerify {
cmd = append ( cmd , "--skip-tls-verify" )
return cmd
}
}
return cmd
}
func appendAdditionalFiles ( cmd [ ] string , files [ ] string ) [ ] string {
return append ( cmd , "--skip-tls-verify" )
for i := 0 ; i < len ( files ) ; i ++ {
cmd = append ( cmd , files [ i ] )
}
return cmd
}
}
func ge tRegistry ( registries [ ] portainer . Registry , dataStore dataservices . DataStore ) [ ] string {
func generateRegistriesStrings ( registries [ ] portainer . Registry , dataStore dataservices . DataStore ) [ ] string {
cmds := [ ] string { }
cmds := [ ] string { }
for _ , registry := range registries {
for _ , registry := range registries {
if registry . Authentication {
if registry . Authentication {
err := registryutils . EnsureRegTokenValid ( dataStore , & registry )
if err := registryutils . EnsureRegTokenValid ( dataStore , & registry ) ; err != nil {
if err == nil {
continue
username , password , err := registryutils . GetRegEffectiveCredential ( & registry )
}
if err == nil {
cmd := fmt . Sprintf ( "--registry=%s:%s:%s" , username , password , registry. URL )
username , password , err := registryutils . GetRegEffectiveCredential ( & registry )
cmds = append ( cmds , cmd )
if err != nil {
}
continue
}
}
cmds = append ( cmds , fmt . Sprintf ( "--registry=%s:%s:%s" , username , password , registry . URL ) )
}
}
}
}