Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Docker workflow refactor #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Cass Config Builder Build & Deploy
name: Build, Test, Latest Package
on:
push:
branches: [ master ]
Expand All @@ -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
49 changes: 49 additions & 0 deletions .github/workflows/build_test_release.yaml
Original file line number Diff line number Diff line change
@@ -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
85 changes: 64 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -187,42 +226,46 @@ 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 {
port = 7888
// 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
4 changes: 4 additions & 0 deletions default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ubiBaseTag=7.8
imageVersion=1.0.3
release=1
dockerRegistry=datastax
28 changes: 0 additions & 28 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}