-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from opendevstack/hotfix/rollout-stage
Fix component stage rollout and agent image tag
- Loading branch information
Showing
12 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
bin/ | ||
converter | ||
out/ | ||
internal/test/**/out/Jenkinsfile | ||
out/Jenkinsfile | ||
cover.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// See https://www.opendevstack.org/ods-documentation/ for usage and customization. | ||
|
||
@Library('[email protected]') _ | ||
|
||
node { | ||
dockerRegistry = env.DOCKER_REGISTRY | ||
} | ||
|
||
odsComponentPipeline( | ||
imageStreamTag: 'ods/jenkins-agent-maven:3.0.0', | ||
branchToEnvironmentMapping: [ | ||
'master': 'dev', | ||
'release/': 'test', | ||
] | ||
) { context -> | ||
|
||
odsComponentStageImportOpenShiftImageOrElse(context) { | ||
stageBuild(context) | ||
odsComponentStageScanWithSonar(context) | ||
odsComponentStageBuildOpenShiftImage(context,[ | ||
tailorParams: [ | ||
"DOCKER_REGISTRY=${dockerRegistry}" | ||
] | ||
]) | ||
} | ||
odsComponentStageRolloutOpenShiftDeployment(context, [ | ||
deployTimeoutMinutes: 5, | ||
openshiftDir: "openshift", | ||
dockerDir: "docker", | ||
resourceName : "${context.componentId}", | ||
tailorSelector : "app=${context.projectId}-${context.componentId}", | ||
tailorExclude : 'bc,is', | ||
tailorParams: [ | ||
"DOCKER_REGISTRY=${dockerRegistry}" | ||
] | ||
// tailorParams : [ | ||
// "PROJECT=${context.projectId}", // projectId == atlasdev-dev, targetProject == atlasdev | ||
// "ENV=${context.environment}", | ||
// "DOCKER_REGISTRY=${dockerRegistry}", | ||
// "COMPONENT=${context.componentId}", | ||
// "TAGVERSION=${context.gitCommit}", | ||
// ], | ||
]) | ||
} | ||
|
||
def stageBuild(def context) { | ||
def javaOpts = "-Xmx512m" | ||
def gradleTestOpts = "-Xmx128m" | ||
def springBootEnv = context.environment | ||
if (springBootEnv.contains('-dev')) { | ||
springBootEnv = 'dev' | ||
} | ||
stage('Build and Unit Test') { | ||
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}","GRADLE_TEST_OPTS=${gradleTestOpts}","ENVIRONMENT=${springBootEnv}"]) { | ||
def chmodXGradelw = sh(script: "chmod +x gradlew", returnStatus: true) | ||
def status = sh(script: "./gradlew clean build --stacktrace --no-daemon", returnStatus: true) | ||
if (status != 0) { | ||
error "Build failed!" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// See https://www.opendevstack.org/ods-documentation/ for usage and customization. | ||
|
||
@Library('[email protected]') _ | ||
|
||
node { | ||
dockerRegistry = env.DOCKER_REGISTRY | ||
} | ||
|
||
odsComponentPipeline( | ||
imageStreamTag: 'ods/jenkins-agent-maven:4.0.0', | ||
branchToEnvironmentMapping: [ | ||
'master': 'dev', | ||
'release/': 'test', | ||
] | ||
) { context -> | ||
|
||
odsComponentFindOpenShiftImageOrElse(context) { | ||
stageBuild(context) | ||
odsComponentStageScanWithSonar(context) | ||
odsComponentStageBuildOpenShiftImage(context,[ | ||
tailorParams: [ | ||
"DOCKER_REGISTRY=${dockerRegistry}" | ||
] | ||
]) | ||
} | ||
odsComponentStageRolloutOpenShiftDeployment(context) | ||
} | ||
|
||
def stageBuild(def context) { | ||
def javaOpts = "-Xmx512m" | ||
def gradleTestOpts = "-Xmx128m" | ||
def springBootEnv = context.environment | ||
if (springBootEnv.contains('-dev')) { | ||
springBootEnv = 'dev' | ||
} | ||
stage('Build and Unit Test') { | ||
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}","GRADLE_TEST_OPTS=${gradleTestOpts}","ENVIRONMENT=${springBootEnv}"]) { | ||
def chmodXGradelw = sh(script: "chmod +x gradlew", returnStatus: true) | ||
def status = sh(script: "./gradlew clean build --stacktrace --no-daemon", returnStatus: true) | ||
if (status != 0) { | ||
error "Build failed!" | ||
} | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// See https://www.opendevstack.org/ods-documentation/ for usage and customization. | ||
|
||
@Library('[email protected]') _ | ||
|
||
odsComponentPipeline( | ||
imageStreamTag: 'ods/jenkins-agent-base:3.0.0', | ||
openshiftBuildTimeout: 30, | ||
branchToEnvironmentMapping: [ | ||
'master': 'dev', | ||
// 'release/': 'test' | ||
] | ||
) { context -> | ||
|
||
odsComponentStageImportOpenShiftImageOrElse(context) { | ||
odsComponentStageBuildOpenShiftImage(context) | ||
} | ||
|
||
// rollout auth proxy - this registers the dc for later promotion | ||
odsComponentStageRolloutOpenShiftDeployment(context, [resourceName: "${context.componentId}-auth-proxy"]) | ||
|
||
odsComponentStageRolloutOpenShiftDeployment(context) | ||
} |
22 changes: 22 additions & 0 deletions
22
internal/test/stage-rollout-single-line/golden/Jenkinsfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// See https://www.opendevstack.org/ods-documentation/ for usage and customization. | ||
|
||
@Library('[email protected]') _ | ||
|
||
odsComponentPipeline( | ||
imageStreamTag: 'ods/jenkins-agent-base:4.0.0', | ||
openshiftBuildTimeout: 30, | ||
branchToEnvironmentMapping: [ | ||
'master': 'dev', | ||
// 'release/': 'test' | ||
] | ||
) { context -> | ||
|
||
odsComponentFindOpenShiftImageOrElse(context) { | ||
odsComponentStageBuildOpenShiftImage(context) | ||
} | ||
|
||
// rollout auth proxy - this registers the dc for later promotion | ||
odsComponentStageRolloutOpenShiftDeployment(context) | ||
|
||
odsComponentStageRolloutOpenShiftDeployment(context) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
func TestReplace(t *testing.T) { | ||
|
||
type args struct { | ||
inputFile string | ||
convertedFile string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "Stage Rollout Single Line", | ||
args: args{ | ||
inputFile: "internal/test/stage-rollout-single-line/Jenkinsfile", | ||
convertedFile: "internal/test/stage-rollout-single-line/out/Jenkinsfile", | ||
}, | ||
want: readFile("internal/test/stage-rollout-single-line/golden/Jenkinsfile"), | ||
}, | ||
{ | ||
name: "Stage Rollout Multi Line", | ||
args: args{ | ||
inputFile: "internal/test/stage-rollout-multi-line/Jenkinsfile", | ||
convertedFile: "internal/test/stage-rollout-multi-line/out/Jenkinsfile", | ||
}, | ||
want: readFile("internal/test/stage-rollout-multi-line/golden/Jenkinsfile"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
Replace(tt.args.inputFile, tt.args.convertedFile, false) | ||
|
||
converted, err := ioutil.ReadFile(tt.args.convertedFile) | ||
if err != nil { | ||
t.Errorf("failed to open file: %w", err) | ||
} | ||
|
||
if got := string(converted); got != string(tt.want) { | ||
t.Errorf("Replace() =\n%v, want\n%v", got, string(tt.want)) | ||
} | ||
}) | ||
} | ||
|
||
} | ||
|
||
func readFile(goldenFile string) string { | ||
want, err := ioutil.ReadFile(goldenFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return string(want) | ||
} |