Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

merge the gradlew #10

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 15 additions & 134 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,145 +1,26 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.6.4/samples
*/
import java.text.SimpleDateFormat

allprojects {
version = "1.0.0"
apply plugin: "java-library"
}

def getGitCommitDetails(length = 8) {
try {
def gitFolder = "$projectDir/.git/"
if (!file(gitFolder).isDirectory()) {
gitFolder = file(gitFolder).text.substring(length).trim() + "/"
}
def takeFromHash = length
def head = new File(gitFolder + "HEAD").text.split(":")
def isCommit = head.length == 1

def commitHash, refHeadFile
if (isCommit) {
commitHash = head[0].trim().take(takeFromHash)
refHeadFile = new File(gitFolder + "HEAD")
} else {
refHeadFile = new File(gitFolder + head[1].trim())
commitHash = refHeadFile.text.trim().take(takeFromHash)
}

// Use head file modification time as a proxy for the build date
def lastModified = new Date(refHeadFile.lastModified())
// Format the date as "yy.M" (e.g. 24.3 for March 2024)
def formattedDate = new SimpleDateFormat("yy.M").format(lastModified)

return [hash: commitHash, date: formattedDate]
} catch (Exception e) {
logger.warn('Could not calculate git commit details, using defaults (run with --info for stacktrace)')
logger.info('Error retrieving git commit details', e)
return [hash: "xxxxxxxx", date: "00.0"]
}
plugins {
id 'java'
}

// http://label-schema.org/rc1/
// using the RFC3339 format "2016-04-12T23:20:50.52Z"
def buildTime() {
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
tasks.named('jar') {
enabled = false
}

// set the shell command to use according to os
def shell = org.gradle.internal.os.OperatingSystem.current().isWindows() ? "${projectDir}\\wslsh.bat" : '/bin/bash'

def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.getProperty('release.releaseVersion') : "${rootProject.version}"
def dockerOrgName = project.hasProperty('dockerOrgName') ? project.getProperty("dockerOrgName") : "tronprotocol"
def dockerArtifactName = project.hasProperty("dockerArtifactName") ? project.getProperty("dockerArtifactName") : "java-tron"
def dockerImageName = "${dockerOrgName}/${dockerArtifactName}"

task sourceDocker {
def dockerBuildDir = "build/docker-tron/"

doLast {
copy {
from file("${projectDir}/docker/Dockerfile")
into(dockerBuildDir)
}
copy {
from file("${projectDir}/docker/docker-entrypoint.sh")
into "${dockerBuildDir}"
}
exec {
def image = "${dockerImageName}:${dockerBuildVersion}"
def dockerPlatform = ""
if (project.hasProperty('docker-platform')){
dockerPlatform = "--platform ${project.getProperty('docker-platform')}"
println "Building for platform ${project.getProperty('docker-platform')}"
} else {
dockerPlatform = "--platform linux/amd64"
println "Building for default linux/amd64 platform"
}
def gitDetails = getGitCommitDetails(7)
executable shell
workingDir dockerBuildDir
args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ."
}
task copyToParent(type: Copy) {
into "$buildDir/libs"
subprojects.each { subproject ->
from(subproject.tasks.withType(Jar))
}
}

// Takes the version and if it contains SNAPSHOT, alpha, beta or RC in version then return true indicating an interim build
def isInterimBuild(dockerBuildVersion) {
return (dockerBuildVersion ==~ /.*-SNAPSHOT/) || (dockerBuildVersion ==~ /.*-alpha/)
|| (dockerBuildVersion ==~ /.*-beta/) || (dockerBuildVersion ==~ /.*-RC.*/)
|| (dockerBuildVersion ==~ /.*develop.*/)
}


task testDocker {
dependsOn sourceDocker
def dockerReportsDir = "docker/reports/"

doFirst {
new File(dockerReportsDir).mkdir()
}
build.finalizedBy(copyToParent)

doLast {
exec {
def image = project.hasProperty('release.releaseVersion') ? "${dockerImageName}:" + project.property('release.releaseVersion') : "${dockerImageName}:${project.version}"
workingDir "${projectDir}/docker"
executable shell
args "-c", "./test.sh ${image}"
gradle.buildFinished {
if (project.hasProperty('cleanSubBuild')) {
subprojects.each { subproject ->
if (subproject.buildDir.exists()) {
subproject.buildDir.deleteDir()
}
}
}
}

// Make sure to `docker login` first
task dockerUpload {
dependsOn sourceDocker
def architecture = System.getenv('architecture')
if (architecture == null) {
architecture = "amd64" //set default as amd64
}
def image = "${dockerImageName}:${dockerBuildVersion}"
def additionalTags = []

if (project.hasProperty('branch') && project.property('branch') == 'main') {
additionalTags.add('develop')
}

if (!isInterimBuild(dockerBuildVersion)) {
additionalTags.add(dockerBuildVersion.split(/\./)[0..1].join('.'))
}

doLast {
exec {
def archVariantImage = "${image}-${architecture}"
def cmd = "docker tag '${image}' '${archVariantImage}' && docker push '${archVariantImage}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
}
}
152 changes: 152 additions & 0 deletions docker/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.6.4/samples
*/
import java.text.SimpleDateFormat

//allprojects {
// version = "1.0.0"
// apply plugin: "java-library"
//}

version = "1.0.0"
apply plugin: "java-library"

def getGitCommitDetails(length = 8) {
try {
def gitFolder = "$projectDir/.git/"
if (!file(gitFolder).isDirectory()) {
gitFolder = file(gitFolder).text.substring(length).trim() + "/"
}
def takeFromHash = length
def head = new File(gitFolder + "HEAD").text.split(":")
def isCommit = head.length == 1

def commitHash, refHeadFile
if (isCommit) {
commitHash = head[0].trim().take(takeFromHash)
refHeadFile = new File(gitFolder + "HEAD")
} else {
refHeadFile = new File(gitFolder + head[1].trim())
commitHash = refHeadFile.text.trim().take(takeFromHash)
}

// Use head file modification time as a proxy for the build date
def lastModified = new Date(refHeadFile.lastModified())
// Format the date as "yy.M" (e.g. 24.3 for March 2024)
def formattedDate = new SimpleDateFormat("yy.M").format(lastModified)

return [hash: commitHash, date: formattedDate]
} catch (Exception e) {
logger.warn('Could not calculate git commit details, using defaults (run with --info for stacktrace)')
logger.info('Error retrieving git commit details', e)
return [hash: "xxxxxxxx", date: "00.0"]
}
}

// http://label-schema.org/rc1/
// using the RFC3339 format "2016-04-12T23:20:50.52Z"
def buildTime() {
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}

// set the shell command to use according to os
def shell = org.gradle.internal.os.OperatingSystem.current().isWindows() ? "${projectDir}\\wslsh.bat" : '/bin/bash'

def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.getProperty('release.releaseVersion') : "${version}"
def dockerOrgName = project.hasProperty('dockerOrgName') ? project.getProperty("dockerOrgName") : "tronprotocol"
def dockerArtifactName = project.hasProperty("dockerArtifactName") ? project.getProperty("dockerArtifactName") : "java-tron"
def dockerImageName = "${dockerOrgName}/${dockerArtifactName}"

task sourceDocker {
def dockerBuildDir = "build/docker-tron/"

doLast {
copy {
from file("${projectDir}/docker/Dockerfile")
into(dockerBuildDir)
}
copy {
from file("${projectDir}/docker/docker-entrypoint.sh")
into "${dockerBuildDir}"
}
exec {
def image = "${dockerImageName}:${dockerBuildVersion}"
def dockerPlatform = ""
if (project.hasProperty('docker-platform')){
dockerPlatform = "--platform ${project.getProperty('docker-platform')}"
println "Building for platform ${project.getProperty('docker-platform')}"
} else {
dockerPlatform = "--platform linux/amd64"
println "Building for default linux/amd64 platform"
}
def gitDetails = getGitCommitDetails(7)
executable shell
workingDir dockerBuildDir
args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ."
}
}
}

// Takes the version and if it contains SNAPSHOT, alpha, beta or RC in version then return true indicating an interim build
def isInterimBuild(dockerBuildVersion) {
return (dockerBuildVersion ==~ /.*-SNAPSHOT/) || (dockerBuildVersion ==~ /.*-alpha/)
|| (dockerBuildVersion ==~ /.*-beta/) || (dockerBuildVersion ==~ /.*-RC.*/)
|| (dockerBuildVersion ==~ /.*develop.*/)
}


task testDocker {
dependsOn sourceDocker
def dockerReportsDir = "docker/reports/"

doFirst {
new File(dockerReportsDir).mkdir()
}

doLast {
exec {
def image = project.hasProperty('release.releaseVersion') ? "${dockerImageName}:" + project.property('release.releaseVersion') : "${dockerImageName}:${project.version}"
workingDir "${projectDir}/docker"
executable shell
args "-c", "./test.sh ${image}"
}
}
}

// Make sure to `docker login` first
task dockerUpload {
dependsOn sourceDocker
def architecture = System.getenv('architecture')
if (architecture == null) {
architecture = "amd64" //set default as amd64
}
def image = "${dockerImageName}:${dockerBuildVersion}"
def additionalTags = []

if (project.hasProperty('branch') && project.property('branch') == 'main') {
additionalTags.add('develop')
}

if (!isInterimBuild(dockerBuildVersion)) {
additionalTags.add(dockerBuildVersion.split(/\./)[0..1].join('.'))
}

doLast {
exec {
def archVariantImage = "${image}-${architecture}"
def cmd = "docker tag '${image}' '${archVariantImage}' && docker push '${archVariantImage}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
}
}

tasks.named('jar') {
enabled = false
}
11 changes: 2 additions & 9 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.6.4/userguide/multi_project_builds.html
*/

rootProject.name = 'tron-docker'
include('docker')
include('tools:dbfork')
9 changes: 0 additions & 9 deletions tools/.gitattributes

This file was deleted.

5 changes: 0 additions & 5 deletions tools/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion tools/dbfork/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jar {

checkstyle {
toolVersion = '8.41'
configFile = rootProject.file('config/checkstyle/checkStyle.xml')
configFile = rootProject.file('tools/config/checkstyle/checkStyle.xml')
}

task checkstyleDBForkMain(type: Checkstyle) {
Expand Down
Binary file removed tools/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 0 additions & 6 deletions tools/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Loading