Skip to content

Commit

Permalink
Update docker command to mount the directory to a new project folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedSabthar committed Oct 5, 2023
1 parent 5b3f0b8 commit 4d08623
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BallerinaPlugin implements Plugin<Project> {
def balBuildTarget = 'build/bal_build_target'
def balaArtifact = new File("$project.projectDir/build/bala_unzipped/")
def projectDirectory = new File("$project.projectDir")
def parentDirectory = new File("$projectDirectory.parent")
def ballerinaCentralAccessToken = System.getenv('BALLERINA_CENTRAL_ACCESS_TOKEN')
def groupParams = ''
def disableGroups = ''
Expand Down Expand Up @@ -295,10 +296,18 @@ class BallerinaPlugin implements Plugin<Project> {
if (dockerTag != null && dockerTag != '') {
ballerinaDockerTag = dockerTag
}
def balPackWithDocker = """
docker run --rm --net=host --user ballerina:\$(id -g) \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
-w /home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam \
bal pack --target-dir ${balBuildTarget} ${debugParams}
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal pack --target-dir ${balBuildTarget} ${debugParams}"
commandLine 'cmd', '/c', "$balPackWithDocker"
} else {
commandLine 'sh', '-c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal pack --target-dir ${balBuildTarget} ${debugParams}"
commandLine 'sh', '-c', "$balPackWithDocker"
}
} else {
String distributionBinPath = project.projectDir.absolutePath + "/build/jballerina-tools-${ballerinaExtension.langVersion}/bin"
Expand All @@ -319,10 +328,18 @@ class BallerinaPlugin implements Plugin<Project> {
if (dockerTag != null && dockerTag != '') {
ballerinaDockerTag = dockerTag
}
def balTestWithDocker = """
docker run --rm --net=host --user ballerina:\$(id -g) \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
-w /home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'cmd', '/c', "$balTestWithDocker"
} else {
commandLine 'sh', '-c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'sh', '-c', "$balTestWithDocker"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balJavaDebugParam $distributionBinPath/bal.bat test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams} && exit %%ERRORLEVEL%%"
Expand Down Expand Up @@ -394,11 +411,19 @@ class BallerinaPlugin implements Plugin<Project> {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
def balTestWithDocker = """
docker run --rm --net=host --user ballerina:\$(id -g) \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
-w /home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}
"""
if (buildOnDocker) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'cmd', '/c', "$balTestWithDocker"
} else {
commandLine 'sh', '-c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'sh', '-c', "$balTestWithDocker"
}
} else {
String distributionBinPath = project.projectDir.absolutePath + "/build/jballerina-tools-${ballerinaExtension.langVersion}/bin"
Expand Down

0 comments on commit 4d08623

Please sign in to comment.