Skip to content

Commit

Permalink
getime bug
Browse files Browse the repository at this point in the history
  • Loading branch information
smerleCB committed Aug 2, 2023
1 parent d68738b commit 75b594f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
34 changes: 34 additions & 0 deletions test/groovy/BuildDockerAndPublishImageStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,38 @@ class BuildDockerAndPublishImageStepTests extends BaseTest {
// And all mocked/stubbed methods have to be called
verifyMocks()
}

@Test
void itBuildsAndDeploysWithPlatformsSpecificOnPrincipalBranch() throws Exception {
def script = loadScript(scriptName)
mockPrincipalBranch()
withMocks{
script.call(testImageName, [
dockerfile: 'build.Dockerfile',
imageDir: 'docker/',
platforms: ['linux/amd64','linux/arm64'],
automaticSemanticVersioning: true,
gitCredentials: 'git-creds',
registryNamespace: 'jenkins',
])
}
printCallStack()
// Then we expect a successful build with the code cloned
assertJobStatusSuccess()
// With the common workflow run as expected
assertTrue(assertBaseWorkflow())
assertTrue(assertMethodCallContainsPattern('node', 'docker'))
// And the expected environment variables set to their default values
assertTrue(assertMethodCallContainsPattern('withEnv', 'IMAGE_DIR=.'))
assertTrue(assertMethodCallContainsPattern('withEnv', 'IMAGE_DOCKERFILE=Dockerfile'))
assertTrue(assertMethodCallContainsPattern('withEnv', 'IMAGE_PLATFORM=linux/amd64'))
// And generated reports recorded
assertTrue(assertRecordIssues())
// And the deploy step called
assertTrue(assertMakeDeploy())
// But no release created automatically
assertFalse(assertTagPushed(defaultGitTag))
// And all mocked/stubbed methods been called
verifyMocks()
}
}
32 changes: 18 additions & 14 deletions vars/buildDockerAndPublishImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def call(String imageShortName, Map userConfig=[:]) {
includeImageNameInTag: false, // Set to true for multiple semversioned images built in parallel, will include the image name in tag to avoid conflict
dockerfile: 'Dockerfile', // Obvious default
platform: 'linux/amd64', // Intel/AMD 64 Bits, following Docker platform identifiers
platforms: [:], // Docker platform identifiers
platforms: [], // Docker platform identifiers
nextVersionCommand: 'jx-release-version', // Commmand line used to retrieve the next version
gitCredentials: 'github-app-infra', // Credential ID for tagging and creating release
imageDir: '.', // Relative path to the context directory for the Docker build
Expand Down Expand Up @@ -38,27 +38,31 @@ def call(String imageShortName, Map userConfig=[:]) {
echo "INFO: Using platforms from the pipeline configuration"
} else {
echo "INFO: Using platform from the pipeline configuration"
finalConfig.platforms[finalConfig.platform]=finalConfig.platform
finalConfig.platforms = [finalConfig.platform]
}

platforms.each {platform ->

final InfraConfig infraConfig = new InfraConfig(env)
final String defaultRegistryNamespace = infraConfig.getDockerRegistryNamespace()
final String registryNamespace = finalConfig.registryNamespace ?: defaultRegistryNamespace
final String imageName = registryNamespace + '/' + imageShortName
finalConfig.platforms.each {oneplatform ->

echo "DEBUG platform in build '${oneplatform}'."

// Warn about potential Linux/Windows contradictions between platform & agentLabels, and set the Windows config suffix for CST files
String cstConfigSuffix = ''
if (finalConfig.agentLabels.contains('windows') || platform.contains('windows')) {
if (finalConfig.agentLabels.contains('windows') && !platform.contains('windows')) {
echo "WARNING: A 'windows' agent is requested, but the 'platform' is set to '${platform}'."
if (finalConfig.agentLabels.contains('windows') || oneplatform.contains('windows')) {
if (finalConfig.agentLabels.contains('windows') && !oneplatform.contains('windows')) {
echo "WARNING: A 'windows' agent is requested, but the 'platform' is set to '${oneplatform}'."
}
if (!finalConfig.agentLabels.contains('windows') && platform.contains('windows')) {
echo "WARNING: The 'platform' is set to '${platform}', but there isn't any 'windows' agent requested."
if (!finalConfig.agentLabels.contains('windows') && oneplatform.contains('windows')) {
echo "WARNING: The 'platform' is set to '${oneplatform}', but there isn't any 'windows' agent requested."
}
cstConfigSuffix = '-windows'
}
String operatingSystem = platform.split('/')[0]
String operatingSystem = oneplatform.split('/')[0]

final InfraConfig infraConfig = new InfraConfig(env)
final String defaultRegistryNamespace = infraConfig.getDockerRegistryNamespace()
final String registryNamespace = finalConfig.registryNamespace ?: defaultRegistryNamespace
final String imageName = registryNamespace + '/' + imageShortName
echo "INFO: Resolved Container Image Name: ${imageName}"

node(finalConfig.agentLabels) {
Expand All @@ -67,7 +71,7 @@ def call(String imageShortName, Map userConfig=[:]) {
"IMAGE_NAME=${imageName}",
"IMAGE_DIR=${finalConfig.imageDir}",
"IMAGE_DOCKERFILE=${finalConfig.dockerfile}",
"IMAGE_PLATFORM=${platform}",
"IMAGE_PLATFORM=${oneplatform}",
]) {
infra.withDockerPullCredentials{
String nextVersion = ''
Expand Down

0 comments on commit 75b594f

Please sign in to comment.