|
@@ -3,6 +3,7 @@ package gitlab
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
+ "net/url"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/shared/commonutils"
|
|
"github.com/porter-dev/porter/api/server/shared/commonutils"
|
|
@@ -32,8 +33,9 @@ type GitlabCI struct {
|
|
|
FolderPath string
|
|
FolderPath string
|
|
|
PorterToken string
|
|
PorterToken string
|
|
|
|
|
|
|
|
- defaultGitBranch string
|
|
|
|
|
- pID string
|
|
|
|
|
|
|
+ defaultGitBranch string
|
|
|
|
|
+ pID string
|
|
|
|
|
+ gitlabInstanceURL string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (g *GitlabCI) Setup() error {
|
|
func (g *GitlabCI) Setup() error {
|
|
@@ -95,37 +97,83 @@ func (g *GitlabCI) Setup() error {
|
|
|
return fmt.Errorf("error getting .gitlab-ci.yml file: %w", err)
|
|
return fmt.Errorf("error getting .gitlab-ci.yml file: %w", err)
|
|
|
} else {
|
|
} else {
|
|
|
// update .gitlab-ci.yml if needed
|
|
// update .gitlab-ci.yml if needed
|
|
|
- ciFileContentsMap := make(map[string]interface{})
|
|
|
|
|
- err = yaml.Unmarshal(ciFile, ciFileContentsMap)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // to preserve the order of the YAML, we use a MapSlice
|
|
|
|
|
+ ciFileContentsMap := yaml.MapSlice{}
|
|
|
|
|
+ err = yaml.Unmarshal(ciFile, &ciFileContentsMap)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("error unmarshalling existing .gitlab-ci.yml: %w", err)
|
|
return fmt.Errorf("error unmarshalling existing .gitlab-ci.yml: %w", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- stages, ok := ciFileContentsMap["stages"].([]string)
|
|
|
|
|
|
|
+ var stagesInt []interface{}
|
|
|
|
|
+ stagesIdx := -1
|
|
|
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return fmt.Errorf("error converting stages to string slice")
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ for idx, elem := range ciFileContentsMap {
|
|
|
|
|
+ if key, ok := elem.Key.(string); ok {
|
|
|
|
|
+ if key == "stages" {
|
|
|
|
|
+ stages, ok := elem.Value.([]interface{})
|
|
|
|
|
|
|
|
- stageExists := false
|
|
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return fmt.Errorf("error converting stages to interface slice")
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for _, stage := range stages {
|
|
|
|
|
- if stage == jobName {
|
|
|
|
|
- stageExists = true
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ stagesInt = stages
|
|
|
|
|
+ stagesIdx = idx
|
|
|
|
|
+
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return fmt.Errorf("invalid key '%v' in .gitlab-ci.yml", elem.Key)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if !stageExists {
|
|
|
|
|
- stages = append(stages, jobName)
|
|
|
|
|
|
|
+ // two cases can happen here:
|
|
|
|
|
+ // 1: "stages" exists
|
|
|
|
|
+ // 2: "stages" does not exist
|
|
|
|
|
+
|
|
|
|
|
+ if stagesIdx >= 0 { // 1: "stages" exists
|
|
|
|
|
+ stageExists := false
|
|
|
|
|
+
|
|
|
|
|
+ for _, stage := range stagesInt {
|
|
|
|
|
+ stageStr, ok := stage.(string)
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return fmt.Errorf("error converting from interface to string")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if stageStr == jobName {
|
|
|
|
|
+ stageExists = true
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if !stageExists {
|
|
|
|
|
+ stagesInt = append(stagesInt, jobName)
|
|
|
|
|
+
|
|
|
|
|
+ ciFileContentsMap[stagesIdx] = yaml.MapItem{
|
|
|
|
|
+ Key: "stages",
|
|
|
|
|
+ Value: stagesInt,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else { // 2: "stages" does not exist
|
|
|
|
|
+ stagesInt = append(stagesInt, jobName)
|
|
|
|
|
|
|
|
- ciFileContentsMap["stages"] = stages
|
|
|
|
|
|
|
+ ciFileContentsMap = append(ciFileContentsMap, yaml.MapItem{
|
|
|
|
|
+ Key: "stages",
|
|
|
|
|
+ Value: stagesInt,
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ciFileContentsMap[jobName] = g.getCIJob(jobName)
|
|
|
|
|
|
|
+ ciFileContentsMap = append(ciFileContentsMap, yaml.MapItem{
|
|
|
|
|
+ Key: jobName,
|
|
|
|
|
+ Value: g.getCIJob(jobName),
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ contentsYAML, err := yaml.Marshal(ciFileContentsMap)
|
|
|
|
|
|
|
|
- contentsYAML, _ := yaml.Marshal(ciFileContentsMap)
|
|
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return fmt.Errorf("error marshalling contents of .gitlab-ci.yml while updating to add porter job")
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
_, _, err = client.RepositoryFiles.UpdateFile(g.pID, ".gitlab-ci.yml", &gitlab.UpdateFileOptions{
|
|
_, _, err = client.RepositoryFiles.UpdateFile(g.pID, ".gitlab-ci.yml", &gitlab.UpdateFileOptions{
|
|
|
Branch: gitlab.String(g.defaultGitBranch),
|
|
Branch: gitlab.String(g.defaultGitBranch),
|
|
@@ -183,37 +231,72 @@ func (g *GitlabCI) Cleanup() error {
|
|
|
return fmt.Errorf("error getting .gitlab-ci.yml file: %w", err)
|
|
return fmt.Errorf("error getting .gitlab-ci.yml file: %w", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ciFileContentsMap := make(map[string]interface{})
|
|
|
|
|
- err = yaml.Unmarshal(ciFile, ciFileContentsMap)
|
|
|
|
|
|
|
+ ciFileContentsMap := yaml.MapSlice{}
|
|
|
|
|
+ err = yaml.Unmarshal(ciFile, &ciFileContentsMap)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("error unmarshalling existing .gitlab-ci.yml: %w", err)
|
|
return fmt.Errorf("error unmarshalling existing .gitlab-ci.yml: %w", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- stages, ok := ciFileContentsMap["stages"].([]interface{})
|
|
|
|
|
|
|
+ var stagesInt []interface{}
|
|
|
|
|
+ stagesIdx := -1
|
|
|
|
|
+
|
|
|
|
|
+ for idx, elem := range ciFileContentsMap {
|
|
|
|
|
+ if key, ok := elem.Key.(string); ok {
|
|
|
|
|
+ if key == "stages" {
|
|
|
|
|
+ stages, ok := elem.Value.([]interface{})
|
|
|
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return fmt.Errorf("error converting stages to interface slice")
|
|
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return fmt.Errorf("error converting stages to interface slice")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ stagesInt = stages
|
|
|
|
|
+ stagesIdx = idx
|
|
|
|
|
+
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return fmt.Errorf("invalid key '%v' in .gitlab-ci.yml", elem.Key)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var newStages []string
|
|
|
|
|
|
|
+ if stagesIdx >= 0 { // "stages" exists
|
|
|
|
|
+ var newStages []string
|
|
|
|
|
+
|
|
|
|
|
+ for _, stage := range stagesInt {
|
|
|
|
|
+ stageStr, ok := stage.(string)
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return fmt.Errorf("error converting from interface to string")
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for _, stage := range stages {
|
|
|
|
|
- stageStr, ok := stage.(string)
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return fmt.Errorf("error converting from interface to string")
|
|
|
|
|
|
|
+ if stageStr != jobName {
|
|
|
|
|
+ newStages = append(newStages, stageStr)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if stageStr != jobName {
|
|
|
|
|
- newStages = append(newStages, stageStr)
|
|
|
|
|
|
|
+ ciFileContentsMap[stagesIdx] = yaml.MapItem{
|
|
|
|
|
+ Key: "stages",
|
|
|
|
|
+ Value: newStages,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ciFileContentsMap["stage"] = newStages
|
|
|
|
|
|
|
+ newCIFileContentsMap := yaml.MapSlice{}
|
|
|
|
|
|
|
|
- delete(ciFileContentsMap, jobName)
|
|
|
|
|
|
|
+ for _, elem := range ciFileContentsMap {
|
|
|
|
|
+ if key, ok := elem.Key.(string); ok {
|
|
|
|
|
+ if key != jobName {
|
|
|
|
|
+ newCIFileContentsMap = append(newCIFileContentsMap, elem)
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return fmt.Errorf("invalid key '%v' in .gitlab-ci.yml", elem.Key)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ contentsYAML, err := yaml.Marshal(newCIFileContentsMap)
|
|
|
|
|
|
|
|
- contentsYAML, _ := yaml.Marshal(ciFileContentsMap)
|
|
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return fmt.Errorf("error unmarshalling contents of .gitlab-ci.yml while updating to remove porter job")
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
_, _, err = client.RepositoryFiles.UpdateFile(g.pID, ".gitlab-ci.yml", &gitlab.UpdateFileOptions{
|
|
_, _, err = client.RepositoryFiles.UpdateFile(g.pID, ".gitlab-ci.yml", &gitlab.UpdateFileOptions{
|
|
|
Branch: gitlab.String(g.defaultGitBranch),
|
|
Branch: gitlab.String(g.defaultGitBranch),
|
|
@@ -237,14 +320,23 @@ func (g *GitlabCI) getClient() (*gitlab.Client, error) {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- oauthInt, err := g.Repo.GitlabAppOAuthIntegration().ReadGitlabAppOAuthIntegration(g.UserID, g.ProjectID, g.IntegrationID)
|
|
|
|
|
|
|
+ giOAuthInt, err := g.Repo.GitlabAppOAuthIntegration().ReadGitlabAppOAuthIntegration(g.UserID, g.ProjectID, g.IntegrationID)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ oauthInt, err := g.Repo.OAuthIntegration().ReadOAuthIntegration(g.ProjectID, giOAuthInt.OAuthIntegrationID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- accessToken, _, err := oauth.GetAccessToken(oauthInt.SharedOAuthModel, commonutils.GetGitlabOAuthConf(g.PorterConf, gi),
|
|
|
|
|
- oauth.MakeUpdateGitlabAppOAuthIntegrationFunction(oauthInt, g.Repo))
|
|
|
|
|
|
|
+ accessToken, _, err := oauth.GetAccessToken(
|
|
|
|
|
+ oauthInt.SharedOAuthModel,
|
|
|
|
|
+ commonutils.GetGitlabOAuthConf(g.PorterConf, gi),
|
|
|
|
|
+ oauth.MakeUpdateGitlabAppOAuthIntegrationFunction(g.ProjectID, giOAuthInt, g.Repo),
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -256,50 +348,150 @@ func (g *GitlabCI) getClient() (*gitlab.Client, error) {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ g.gitlabInstanceURL = gi.InstanceURL
|
|
|
|
|
+
|
|
|
return client, nil
|
|
return client, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (g *GitlabCI) getCIJob(jobName string) map[string]interface{} {
|
|
|
|
|
- return map[string]interface{}{
|
|
|
|
|
- "image": "public.ecr.aws/o1j4x7p4/porter-cli:latest",
|
|
|
|
|
- "stage": jobName,
|
|
|
|
|
- "timeout": "20 minutes",
|
|
|
|
|
- "variables": map[string]string{
|
|
|
|
|
- "GIT_STRATEGY": "clone",
|
|
|
|
|
|
|
+func (g *GitlabCI) getCIJob(jobName string) yaml.MapSlice {
|
|
|
|
|
+ res := yaml.MapSlice{}
|
|
|
|
|
+ url, _ := url.Parse(g.gitlabInstanceURL)
|
|
|
|
|
+
|
|
|
|
|
+ res = append(res,
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "rules",
|
|
|
|
|
+ Value: []map[string]string{
|
|
|
|
|
+ {
|
|
|
|
|
+ "if": fmt.Sprintf("$CI_COMMIT_BRANCH == \"%s\" && $CI_PIPELINE_SOURCE == \"push\"", g.GitBranch),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- "rules": []map[string]string{
|
|
|
|
|
- {
|
|
|
|
|
- "if": fmt.Sprintf("$CI_COMMIT_BRANCH == \"%s\" && $CI_PIPELINE_SOURCE == \"push\"", g.GitBranch),
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ if url.Hostname() == "gitlab.com" || url.Hostname() == "www.gitlab.com" {
|
|
|
|
|
+ res = append(res,
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "image",
|
|
|
|
|
+ Value: "docker:latest",
|
|
|
|
|
+ },
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "services",
|
|
|
|
|
+ Value: []string{
|
|
|
|
|
+ "docker:dind",
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "script",
|
|
|
|
|
+ Value: []string{
|
|
|
|
|
+ fmt.Sprintf(
|
|
|
|
|
+ "docker run --rm --workdir=\"/app\" "+
|
|
|
|
|
+ "-v /var/run/docker.sock:/var/run/docker.sock "+
|
|
|
|
|
+ "-v $(pwd):/app "+
|
|
|
|
|
+ "public.ecr.aws/o1j4x7p4/porter-cli:latest "+
|
|
|
|
|
+ "update --host \"%s\" --project %d --cluster %d "+
|
|
|
|
|
+ "--token \"$%s\" --app \"%s\" "+
|
|
|
|
|
+ "--tag \"$(echo $CI_COMMIT_SHA | cut -c1-7)\" --namespace \"%s\" --stream",
|
|
|
|
|
+ g.ServerURL, g.ProjectID, g.ClusterID, g.getPorterTokenSecretName(),
|
|
|
|
|
+ g.ReleaseName, g.ReleaseNamespace,
|
|
|
|
|
+ ),
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "tags",
|
|
|
|
|
+ Value: []string{
|
|
|
|
|
+ "docker",
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
|
|
+ } else {
|
|
|
|
|
+ res = append(res,
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "image",
|
|
|
|
|
+ Value: map[string]interface{}{
|
|
|
|
|
+ "name": "public.ecr.aws/o1j4x7p4/porter-cli:latest",
|
|
|
|
|
+ "entrypoint": []string{
|
|
|
|
|
+ "",
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "script",
|
|
|
|
|
+ Value: []string{
|
|
|
|
|
+ fmt.Sprintf(
|
|
|
|
|
+ "porter update --host \"%s\" --project %d --cluster %d "+
|
|
|
|
|
+ "--token \"$%s\" --app \"%s\" "+
|
|
|
|
|
+ "--tag \"$(echo $CI_COMMIT_SHA | cut -c1-7)\" --namespace \"%s\" --stream",
|
|
|
|
|
+ g.ServerURL, g.ProjectID, g.ClusterID, g.getPorterTokenSecretName(),
|
|
|
|
|
+ g.ReleaseName, g.ReleaseNamespace,
|
|
|
|
|
+ ),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "tags",
|
|
|
|
|
+ Value: []string{
|
|
|
|
|
+ "porter-runner",
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ res = append(res,
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "stage",
|
|
|
|
|
+ Value: jobName,
|
|
|
},
|
|
},
|
|
|
- "script": []string{
|
|
|
|
|
- fmt.Sprintf("export PORTER_HOST=\"%s\"", g.ServerURL),
|
|
|
|
|
- fmt.Sprintf("export PORTER_PROJECT=\"%d\"", g.ProjectID),
|
|
|
|
|
- fmt.Sprintf("export PORTER_CLUSTER=\"%d\"", g.ClusterID),
|
|
|
|
|
- fmt.Sprintf("export PORTER_TOKEN=\"$%s\"", g.getPorterTokenSecretName()),
|
|
|
|
|
- "export PORTER_TAG=\"$(echo $CI_COMMIT_SHA | cut -c1-7)\"",
|
|
|
|
|
- fmt.Sprintf("porter update --app \"%s\" --tag \"$PORTER_TAG\" --namespace \"%s\" --path \"%s\" --stream",
|
|
|
|
|
- g.ReleaseName, g.ReleaseNamespace, g.FolderPath),
|
|
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "timeout",
|
|
|
|
|
+ Value: "20 minutes",
|
|
|
},
|
|
},
|
|
|
- }
|
|
|
|
|
|
|
+ yaml.MapItem{
|
|
|
|
|
+ Key: "variables",
|
|
|
|
|
+ Value: map[string]string{
|
|
|
|
|
+ "GIT_STRATEGY": "clone",
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ return res
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (g *GitlabCI) createGitlabSecret(client *gitlab.Client) error {
|
|
func (g *GitlabCI) createGitlabSecret(client *gitlab.Client) error {
|
|
|
- _, _, err := client.ProjectVariables.CreateVariable(g.pID, &gitlab.CreateProjectVariableOptions{
|
|
|
|
|
- Key: gitlab.String(g.getPorterTokenSecretName()),
|
|
|
|
|
- Value: gitlab.String(g.PorterToken),
|
|
|
|
|
- Masked: gitlab.Bool(true),
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ _, resp, err := client.ProjectVariables.GetVariable(g.pID, g.getPorterTokenSecretName(),
|
|
|
|
|
+ &gitlab.GetProjectVariableOptions{})
|
|
|
|
|
+
|
|
|
|
|
+ if resp.StatusCode == http.StatusNotFound {
|
|
|
|
|
+ _, _, err = client.ProjectVariables.CreateVariable(g.pID, &gitlab.CreateProjectVariableOptions{
|
|
|
|
|
+ Key: gitlab.String(g.getPorterTokenSecretName()),
|
|
|
|
|
+ Value: gitlab.String(g.PorterToken),
|
|
|
|
|
+ Masked: gitlab.Bool(true),
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return fmt.Errorf("error creating porter token variable: %w", err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+ } else if err != nil {
|
|
|
|
|
+ return fmt.Errorf("error getting porter token variable: %w", err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ _, _, err = client.ProjectVariables.UpdateVariable(g.pID, g.getPorterTokenSecretName(),
|
|
|
|
|
+ &gitlab.UpdateProjectVariableOptions{
|
|
|
|
|
+ Value: gitlab.String(g.PorterToken),
|
|
|
|
|
+ Masked: gitlab.Bool(true),
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return fmt.Errorf("error creating porter token variable: %w", err)
|
|
|
|
|
|
|
+ return fmt.Errorf("error updating porter token variable: %w", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (g *GitlabCI) deleteGitlabSecret(client *gitlab.Client) error {
|
|
func (g *GitlabCI) deleteGitlabSecret(client *gitlab.Client) error {
|
|
|
- _, err := client.ProjectVariables.RemoveVariable(g.pID, g.getPorterTokenSecretName(), &gitlab.RemoveProjectVariableOptions{})
|
|
|
|
|
|
|
+ _, err := client.ProjectVariables.RemoveVariable(g.pID, g.getPorterTokenSecretName(),
|
|
|
|
|
+ &gitlab.RemoveProjectVariableOptions{})
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("error removing porter token variable: %w", err)
|
|
return fmt.Errorf("error removing porter token variable: %w", err)
|
|
@@ -309,7 +501,7 @@ func (g *GitlabCI) deleteGitlabSecret(client *gitlab.Client) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (g *GitlabCI) getPorterTokenSecretName() string {
|
|
func (g *GitlabCI) getPorterTokenSecretName() string {
|
|
|
- return fmt.Sprintf("PORTER_TOKEN_%d", g.ProjectID)
|
|
|
|
|
|
|
+ return fmt.Sprintf("PORTER_TOKEN_%d_%s", g.ProjectID, strings.ToLower(strings.ReplaceAll(g.ReleaseName, "-", "_")))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func getGitlabStageJobName(releaseName string) string {
|
|
func getGitlabStageJobName(releaseName string) string {
|