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
…instead of ballerina home
  • Loading branch information
MohamedSabthar committed Oct 4, 2023
1 parent 0240783 commit f8bb9d6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 @@ -298,9 +299,9 @@ class BallerinaPlugin implements Plugin<Project> {
}
startBallerinaContainer(project, ballerinaDockerTag)
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker exec $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}"
commandLine 'cmd', '/c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}"
} else {
commandLine 'sh', '-c', "docker exec $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}"
commandLine 'sh', '-c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}"
}
} else {
String distributionBinPath = project.projectDir.absolutePath + "/build/jballerina-tools-${ballerinaExtension.langVersion}/bin"
Expand All @@ -323,9 +324,9 @@ class BallerinaPlugin implements Plugin<Project> {
}
startBallerinaContainer(project, ballerinaDockerTag)
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'cmd', '/c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
} else {
commandLine 'sh', '-c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'sh', '-c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
}
} 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 @@ -400,9 +401,9 @@ class BallerinaPlugin implements Plugin<Project> {
if (buildOnDocker) {
startBallerinaContainer(project, ballerinaDockerTag)
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'cmd', '/c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
} else {
commandLine 'sh', '-c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'sh', '-c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
}
} else {
String distributionBinPath = project.projectDir.absolutePath + "/build/jballerina-tools-${ballerinaExtension.langVersion}/bin"
Expand Down Expand Up @@ -462,10 +463,12 @@ class BallerinaPlugin implements Plugin<Project> {
if (!stdOut.toString().contains(CONTAINER_NAME)) {
project.exec {
println "Starting Ballerina container."
def projectDir = new File(project.projectDir.toString())
def parentDir = new File(projectDir.parent.toString())
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v ${project.projectDir}:/home/ballerina ballerina/ballerina:$ballerinaDockerTag"
commandLine 'cmd', '/c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user ballerina:\$(id -g) -v $parentDir:/home/ballerina/$parentDir.name -v $projectDir:/home/ballerina/$parentDir.name/$projectDir.name ballerina/ballerina:$ballerinaDockerTag"
} else {
commandLine 'sh', '-c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v ${project.projectDir}:/home/ballerina ballerina/ballerina:$ballerinaDockerTag"
commandLine 'sh', '-c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user ballerina:\$(id -g) -v $parentDir:/home/ballerina/$parentDir.name -v $projectDir:/home/ballerina/$parentDir.name/$projectDir.name ballerina/ballerina:$ballerinaDockerTag"
}
}
} else {
Expand Down

0 comments on commit f8bb9d6

Please sign in to comment.