Skip to content

Commit

Permalink
Update logic to override docker tag using buildUsingDocker flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedSabthar committed Dec 5, 2023
1 parent 156d6a8 commit a6da00c
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class BallerinaExtension {

String module
String langVersion
String buildOnDockerImage
String testCoverageParam
String packageOrganization
String customTomlVersion
String platform
boolean isConnector = false
}

class BallerinaPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -79,18 +79,14 @@ class BallerinaPlugin implements Plugin<Project> {
}

project.afterEvaluate {
if (ballerinaExtension.hasProperty('buildOnDockerImage') && ballerinaExtension.buildOnDockerImage.asType(boolean) == true) {
if (ballerinaExtension.isConnector == true) {
buildOnDocker = true
ballerinaDockerTag = extractVersion(project.findProperty('ballerinaLangVersion'))
ballerinaDockerTag = getDockerImageTag(project)
}

if (project.hasProperty('buildUsingDocker')) {
buildOnDocker = true
ballerinaDockerTag = project.findProperty('buildUsingDocker')
}

if (ballerinaDockerTag == '') {
ballerinaDockerTag = 'nightly'
ballerinaDockerTag = getDockerImageTag(project)
}

if (buildOnDocker) {
Expand Down Expand Up @@ -293,10 +289,7 @@ class BallerinaPlugin implements Plugin<Project> {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
String dockerTag = extractVersion(project.findProperty('ballerinaLangVersion'))
if (dockerTag != null && dockerTag != '') {
ballerinaDockerTag = dockerTag
}
ballerinaDockerTag = getDockerImageTag(project)
createDockerEnvFile("$project.projectDir/docker.env")
def balPackWithDocker = """
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
Expand Down Expand Up @@ -325,10 +318,7 @@ class BallerinaPlugin implements Plugin<Project> {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
String dockerTag = extractVersion(project.findProperty('ballerinaLangVersion'))
if (dockerTag != null && dockerTag != '') {
ballerinaDockerTag = dockerTag
}
ballerinaDockerTag = getDockerImageTag(project)
def balTestWithDocker = """
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
Expand Down Expand Up @@ -372,10 +362,7 @@ class BallerinaPlugin implements Plugin<Project> {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
String dockerTag = extractVersion(project.findProperty('ballerinaLangVersion'))
if (dockerTag != null && dockerTag != '') {
ballerinaDockerTag = dockerTag
}
ballerinaDockerTag = getDockerImageTag(project)
def balPushWithDocker = """
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
Expand Down Expand Up @@ -511,7 +498,21 @@ class BallerinaPlugin implements Plugin<Project> {
}
}

static String extractVersion(String versionWithTimeStamp) {
return versionWithTimeStamp.trim().split("-")[0]
static String getDockerImageTag(Project project) {
def ballerinaDockerTag = project.findProperty('ballerinaLangVersion')
if (project.hasProperty('buildUsingDocker')) {
ballerinaDockerTag = project.findProperty('buildUsingDocker')
if (ballerinaDockerTag == '') {
return 'nightly'
}
}
if (isTimeStampVersion(ballerinaDockerTag)) {
return 'nightly'
}
return ballerinaDockerTag
}

static boolean isTimeStampVersion(String version) {
return version.trim().split("-").length > 1
}
}

0 comments on commit a6da00c

Please sign in to comment.