Skip to content

Commit

Permalink
Merge pull request #162 from ayeshLK/main
Browse files Browse the repository at this point in the history
Add mock docker run command to the gradle-plugin
  • Loading branch information
ayeshLK authored Jul 2, 2024
2 parents 62f4594 + 2aedb39 commit 8dc9d41
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,14 @@ class BallerinaPlugin implements Plugin<Project> {
packageOrg = ballerinaExtension.packageOrganization
}

def outStream = new ByteArrayOutputStream()
def errStream = new ByteArrayOutputStream()
// Pack bala first
def execResults = project.exec {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
createDockerEnvFile("$project.projectDir/docker.env")
def balPackWithDocker = """
docker run --env-file $project.projectDir/docker.env --net=host -u root \
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
Expand All @@ -282,9 +280,8 @@ class BallerinaPlugin implements Plugin<Project> {
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
println "Executing command on windows: ${balPackWithDocker}"
commandLine 'cmd', '/c', "$balPackWithDocker && exit %%ERRORLEVEL%%"
standardOutput = outStream
errorOutput = errStream
// commandLine 'cmd', '/c', "$balPackWithDocker && exit %%ERRORLEVEL%%"
commandLine 'cmd', '/c', "docker run --env-file $project.projectDir/docker.env --rm --net=host -u root hello-world && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$balPackWithDocker"
}
Expand All @@ -296,13 +293,12 @@ class BallerinaPlugin implements Plugin<Project> {
}
}
}
println("Result: ${execResults.exitValue} ${execResults.properties}\nStdOut: ${outStream.toString()} \nErrOut: ${errStream.toString()}\n")

def balaPath = "$project.projectDir/${balBuildTarget}/bala"
def balaDir = new File(balaPath)
if (!balaDir.exists()) {
println("[Error] 'bala' directory does not exist: ${balaPath}, hence exiting")
return
throw new FileNotFoundException(
"[Error] 'bala' directory does not exist: ${balaPath}, hence exiting")
}

// extract bala file to balaArtifact
Expand Down

0 comments on commit 8dc9d41

Please sign in to comment.