diff --git a/.github/workflows/buildAndDeploy.yml b/.github/workflows/build_test_latest.yaml similarity index 62% rename from .github/workflows/buildAndDeploy.yml rename to .github/workflows/build_test_latest.yaml index 0c9830e..9b9be37 100644 --- a/.github/workflows/buildAndDeploy.yml +++ b/.github/workflows/build_test_latest.yaml @@ -1,4 +1,4 @@ -name: Cass Config Builder Build & Deploy +name: Build, Test, Latest Package on: push: branches: [ master ] @@ -18,17 +18,29 @@ jobs: if: github.event_name != 'pull_request' with: submodules: true + - name: Get current time + uses: 1466587594/get-current-time@v2 + id: current-time + with: + format: YYYYMMDDhhmmss - name: Set up java 1.8 uses: actions/setup-java@v1 with: java-version: 1.8 - - name: Build docker image + - name: Build + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-config-builder' + uses: eskatos/gradle-command-action@v1 + with: + gradle-version: 6.0.1 + arguments: build + - name: Publish Docker images to GitHub Packages if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-config-builder' env: ORG_GRADLE_PROJECT_dockerRegistry: docker.pkg.github.com ORG_GRADLE_PROJECT_dockerRegistryUsername: ${{ github.actor }} ORG_GRADLE_PROJECT_dockerRegistryPassword: ${{ secrets.GITHUB_TOKEN }} + VERSION_STAMP: ${{ steps.current-time.outputs.formattedTime }} uses: eskatos/gradle-command-action@v1 with: gradle-version: 6.0.1 - arguments: pushDockerImages + arguments: pushDockerImages -Prelease=$VERSION_STAMP diff --git a/.github/workflows/build_test_release.yaml b/.github/workflows/build_test_release.yaml new file mode 100644 index 0000000..64b9134 --- /dev/null +++ b/.github/workflows/build_test_release.yaml @@ -0,0 +1,49 @@ +name: Docker Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + release_config_builder: + name: Release Cass Config Builder + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Set up java 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Publish Docker images to GitHub Packages + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-config-builder' + env: + ORG_GRADLE_PROJECT_dockerRegistry: docker.pkg.github.com + ORG_GRADLE_PROJECT_dockerRegistryUsername: ${{ github.actor }} + ORG_GRADLE_PROJECT_dockerRegistryPassword: ${{ secrets.GITHUB_TOKEN }} + uses: eskatos/gradle-command-action@v1 + with: + gradle-version: 6.0.1 + arguments: pushDockerImages + - name: Publish Docker images to DockerHub + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-config-builder' + env: + ORG_GRADLE_PROJECT_dockerRegistry: datastax + ORG_GRADLE_PROJECT_dockerRegistryUsername: ${{ secrets.DOCKER_USERNAME }} + ORG_GRADLE_PROJECT_dockerRegistryPassword: ${{ secrets.DOCKER_PASSWORD }} + uses: eskatos/gradle-command-action@v1 + with: + gradle-version: 6.0.1 + arguments: pushDockerImages + - name: Publish Docker images to Red Hat + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-config-builder' + env: + ORG_GRADLE_PROJECT_dockerRegistry: ${{ secrets.REDHAT_REGISTRY }} + ORG_GRADLE_PROJECT_dockerRegistryUsername: unused + ORG_GRADLE_PROJECT_dockerRegistryPassword: ${{ secrets.REDHAT_REGISTRY_KEY }} + uses: eskatos/gradle-command-action@v1 + with: + gradle-version: 6.0.1 + arguments: pushRedHatImages diff --git a/build.gradle b/build.gradle index 84a5ce1..7e72520 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ * limitations under the License. */ plugins { - id 'com.bmuschko.docker-remote-api' version '6.4.0' + id 'com.bmuschko.docker-remote-api' version '6.6.1' id 'dev.clojurephant.clojure' version '0.5.0' id 'com.github.johnrengelman.shadow' version '5.2.0' id 'maven-publish' @@ -31,9 +31,8 @@ def getDate() { return df.format(new Date()); } -description = "Cassandra/DSE Configuration Builder Library" +description = "Cassandra / DSE Configuration Builder Library" group = 'datastax' -version = '1.0.3-' + getDate() repositories { mavenCentral() @@ -84,19 +83,59 @@ if (project.hasProperty('dockerRegistry')) { ext.set('imagePrefix', 'datastax' + '/cass-config-builder') } +ext { + defaultPropertyValue = { name, value, Closure converter = null -> + if (!ext.has(name)) ext.set(name, converter == null ? value : converter.call(value)) + else if (converter) ext.set(name, converter.call(ext.get(name))) + ext.get(name) + } + + loadDefaultPropertiesFromFile = {fileName -> + file("$fileName").withInputStream { + def props = new Properties() + props.load(it) + + for (key in props.keys()) { + defaultPropertyValue(key, props.getProperty(key)) + } + } + } + + defaultProjectPropertyValue = { proj, name, value, Closure converter = null -> + if (!proj.ext.has(name)) proj.ext.set(name, converter == null ? value : converter.call(value)) + else if (converter) proj.ext.set(name, converter.call(proj.ext.get(name))) + proj.ext.get(name) + } + + loadDefaultProjectPropertiesFromFile = {proj, fileName -> + file("$fileName").withInputStream { + def props = new Properties() + props.load(it) + + for (key in props.keys()) { + defaultProjectPropertyValue(proj, key, props.getProperty(key)) + } + } + } + +} + +loadDefaultPropertiesFromFile("$projectDir/default.properties") + docker { registryCredentials { if (project.hasProperty('dockerRegistry')) { url = project.dockerRegistry } - if (project.hasProperty('dockerRegistryUsername')) + + if (project.hasProperty('registryUsername')) { - username = project.dockerRegistryUsername + username = project.registryUsername } - if (project.hasProperty('dockerRegistryPassword')) + if (project.hasProperty('registryPassword')) { - password = project.dockerRegistryPassword + password = project.registryPassword } } } @@ -187,32 +226,36 @@ task copyDockerBuildCtx(type: Sync) { from shadowJar } -task dockerDebianImage(type: DockerBuildImage, group: 'Docker', description: 'Build cass-config-builder based on Debian') { +task buildDebianContainers(type: DockerBuildImage, group: 'Docker', description: 'Build cass-config-builder based on Debian') { dependsOn copyDockerBuildCtx + inputDir = copyDockerBuildCtx.destinationDir - dockerFile = new File(inputDir.get().asFile, "debian.Dockerfile") + dockerFile = file "$buildDir/docker/debian.Dockerfile" labels.put("release", "${version}") - images.add("${imagePrefix}/cass-config-builder:${version}") + images.add "$dockerRegistry/cass-config-builder:$imageVersion-$release" + images.add "$dockerRegistry/cass-config-builder:$imageVersion" } -task dockerRedHatImage(type: DockerBuildImage, group: 'Docker', description: 'Build cass-config-builder based on Red Hat') { +task buildRedHatContainers(type: DockerBuildImage, group: 'Docker', description: 'Build cass-config-builder based on Red Hat') { dependsOn copyDockerBuildCtx + inputDir = copyDockerBuildCtx.destinationDir - dockerFile = new File(inputDir.get().asFile, "redhat.Dockerfile") + dockerFile = file "$buildDir/docker/redhat.Dockerfile" labels.put("release", "${version}") - images.add("${imagePrefix}/cass-config-builder:${version}-ubi7") + images.add "$dockerRegistry/cass-config-builder:$imageVersion-ubi7-$release" + images.add "$dockerRegistry/cass-config-builder:$imageVersion-ubi7" } -task dockerImages(group: 'Docker', description: 'Build cass-config-builder docker images') { - dependsOn dockerDebianImage - dependsOn dockerRedHatImage +task buildContainers(group: 'Docker', description: 'Build cass-config-builder docker images') { + dependsOn buildDebianContainers + dependsOn buildRedHatContainers } task pushDockerImages(type: DockerPushImage, group: 'Docker', description: "Push Docker image to registry specified with 'dockerRegistry' property") { - dependsOn dockerDebianImage, dockerRedHatImage + dependsOn buildDebianContainers, buildRedHatContainers - images.addAll(dockerDebianImage.images.getOrNull().asList()) - images.addAll(dockerRedHatImage.images.getOrNull().asList()) + images.addAll(buildDebianContainers.images.getOrNull().asList()) + images.addAll(buildRedHatContainers.images.getOrNull().asList()) } clojureRepl { @@ -220,9 +263,9 @@ clojureRepl { // add extracted server functions to the classpath classpath += sourceSets.main.runtimeClasspath forkOptions { - jvmArgs << "-D${project.name}.version=$version" + jvmArgs << "-D${project.name}.version=$imageVersion" } } -assemble.dependsOn dockerImages +assemble.dependsOn buildContainers check.dependsOn assemble diff --git a/default.properties b/default.properties new file mode 100644 index 0000000..11fe8de --- /dev/null +++ b/default.properties @@ -0,0 +1,4 @@ +ubiBaseTag=7.8 +imageVersion=1.0.3 +release=1 +dockerRegistry=datastax diff --git a/settings.gradle b/settings.gradle index e5da060..67850ac 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,31 +2,3 @@ // Please see the included license file for details. rootProject.name = 'cass-config-builder' - -/* -The credentials are provided typically in 'gradle.properties' in the project root. -If needed, the repo location and the credentials could be changed. -Place the values in 'gradle.properties' or pass them via the command line with -P switches. -*/ - -def propertyExists(name) { - settings.hasProperty(name) || System.properties[(name)] != null -} -def propertiesExist(names) { - names.every { propertyExists(it)} -} -def propertyValue(name) { - settings.hasProperty(name) ? settings.getProperty(name) : System.properties[(name)] -} - -if (propertiesExist(['mavenRepositoryUsername', 'mavenRepositoryPassword'])) { - def repoUrl = propertyValue('mavenRepositoryUrl') - def repoUsername = propertyValue('mavenRepositoryUsername') - def repoPassword = propertyValue('mavenRepositoryPassword') - - gradle.beforeProject { proj -> - proj.ext.repoUrl = repoUrl - proj.ext.repoUsername = repoUsername - proj.ext.repoPassword = repoPassword - } -}