From 87da6535758b64a0edc6cc1c5b3d5f91ec02fe1a Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 5 Jan 2021 11:08:05 +0100 Subject: [PATCH] Create package.yml for each distributed package --- build-plugins/build.gradle | 4 + .../com/cloudogu/scm/PackageYamlTask.groovy | 101 ++++++++++++++++++ .../com/cloudogu/scm/PackagingPlugin.groovy | 37 +++++++ scm-packaging/deb/build.gradle | 12 ++- scm-packaging/docker/build.gradle | 12 ++- scm-packaging/helm/build.gradle | 11 +- scm-packaging/rpm/build.gradle | 12 ++- scm-packaging/unix/build.gradle | 19 +++- scm-packaging/windows/build.gradle | 15 ++- 9 files changed, 212 insertions(+), 11 deletions(-) create mode 100644 build-plugins/src/main/groovy/com/cloudogu/scm/PackageYamlTask.groovy create mode 100644 build-plugins/src/main/groovy/com/cloudogu/scm/PackagingPlugin.groovy diff --git a/build-plugins/build.gradle b/build-plugins/build.gradle index ff7ac1ea79..51e9374783 100644 --- a/build-plugins/build.gradle +++ b/build-plugins/build.gradle @@ -58,6 +58,10 @@ gradlePlugin { id = 'org.scm-manager.integration-tests' implementationClass = 'com.cloudogu.scm.IntegrationTestPlugin' } + packaging { + id = 'org.scm-manager.packaging' + implementationClass = 'com.cloudogu.scm.PackagingPlugin' + } } } diff --git a/build-plugins/src/main/groovy/com/cloudogu/scm/PackageYamlTask.groovy b/build-plugins/src/main/groovy/com/cloudogu/scm/PackageYamlTask.groovy new file mode 100644 index 0000000000..2c7c760ffd --- /dev/null +++ b/build-plugins/src/main/groovy/com/cloudogu/scm/PackageYamlTask.groovy @@ -0,0 +1,101 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the 'Software'), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +package com.cloudogu.scm + +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.artifacts.Configuration +import org.gradle.api.file.Directory +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.Classpath +import org.gradle.api.tasks.Nested +import org.gradle.api.tasks.Internal +import org.gradle.api.GradleException + +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import groovy.xml.MarkupBuilder +import java.io.BufferedWriter +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.InputFile + +import com.google.common.hash.Hashing +import com.google.common.hash.HashCode +import com.google.common.io.Files +import groovy.json.JsonOutput + +class PackageYamlTask extends DefaultTask { + + private String type + private File artifact + + @Input + public String getType() { + return type + } + + public void setType(String type) { + this.type = type + } + + @Optional + @InputFile + public File getArtifact() { + return artifact + } + + public void setArtifact(File artifact) { + this.artifact = artifact + } + + @OutputFile + public File getOutputFile() { + return new File(project.buildDir, 'libs/package.yml') + } + + @TaskAction + void execute() { + File packageYaml = getOutputFile() + if (packageYaml.exists() && !packageYaml.delete()) { + throw new GradleException("failed to remove outdated package.yml"); + } + if (artifact != null) { + String repository = project.version.contains('-SNAPSHOT') ? 'snapshots' : 'releases' + HashCode hashCode = Files.asByteSource(artifact).hash(Hashing.sha256()) + packageYaml << """ + type: ${type} + checksum: ${hashCode} + url: https://packages.scm-manager.org/repository/${repository}/sonia/scm/packaging/${type}/${project.version}/${artifact.name} + """.stripIndent().replaceAll(/^\s+/, '') + } else { + packageYaml << "type: ${type}\n" + } + } + +} diff --git a/build-plugins/src/main/groovy/com/cloudogu/scm/PackagingPlugin.groovy b/build-plugins/src/main/groovy/com/cloudogu/scm/PackagingPlugin.groovy new file mode 100644 index 0000000000..d08993a970 --- /dev/null +++ b/build-plugins/src/main/groovy/com/cloudogu/scm/PackagingPlugin.groovy @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +package com.cloudogu.scm + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class PackagingPlugin implements Plugin { + + void apply(Project project) { + project.ext.PackageYaml = PackageYamlTask + } + +} diff --git a/scm-packaging/deb/build.gradle b/scm-packaging/deb/build.gradle index 45fabe3c67..220bf8bc68 100644 --- a/scm-packaging/deb/build.gradle +++ b/scm-packaging/deb/build.gradle @@ -25,6 +25,7 @@ import org.gradle.util.VersionNumber plugins { id 'nebula.ospackage' version '8.4.1' + id 'org.scm-manager.packaging' } configurations { @@ -38,7 +39,7 @@ dependencies { webapp project(path: ':scm-webapp', configuration: 'webapp') } -task distribution(type: Deb) { +task deb(type: Deb) { packageName 'scm-server' packageGroup 'devel' summary 'SCM-Manager Server' @@ -132,3 +133,12 @@ task distribution(type: Deb) { link '/opt/scm-server/conf', '/etc/scm' link '/opt/scm-server/work', '/var/cache/scm/work' } + +task packageYaml(type: PackageYaml) { + type = 'debian' + dependsOn deb +} + +task distribution { + dependsOn packageYaml +} diff --git a/scm-packaging/docker/build.gradle b/scm-packaging/docker/build.gradle index 0b86570755..f9cef2fe1e 100644 --- a/scm-packaging/docker/build.gradle +++ b/scm-packaging/docker/build.gradle @@ -24,6 +24,7 @@ plugins { id 'com.bmuschko.docker-remote-api' version '6.6.1' + id 'org.scm-manager.packaging' } import org.gradle.util.VersionNumber @@ -66,7 +67,7 @@ task context(type: Copy) { } } -task distribution(type: DockerBuildImage) { +task dockerImage(type: DockerBuildImage) { inputDir = file('build/docker') images = images() dependsOn 'context' @@ -87,3 +88,12 @@ def images() { ] } } + +task packageYaml(type: PackageYaml) { + type = 'docker' + dependsOn dockerImage +} + +task distribution { + dependsOn packageYaml +} diff --git a/scm-packaging/helm/build.gradle b/scm-packaging/helm/build.gradle index 898088a5bb..7dcb301945 100644 --- a/scm-packaging/helm/build.gradle +++ b/scm-packaging/helm/build.gradle @@ -24,9 +24,9 @@ plugins { id 'org.unbroken-dome.helm' version '1.4.0' + id 'org.scm-manager.packaging' } - helm { downloadClient { enabled = true @@ -54,6 +54,11 @@ helmPackageScmServerChart { appVersion = expandedVersion } -task distribution { - dependsOn 'helmPackageScmServerChart' +task packageYaml(type: PackageYaml) { + type = 'k8s' + dependsOn helmPackageScmServerChart +} + +task distribution { + dependsOn packageYaml } diff --git a/scm-packaging/rpm/build.gradle b/scm-packaging/rpm/build.gradle index 00362ed262..c6f74aba4f 100644 --- a/scm-packaging/rpm/build.gradle +++ b/scm-packaging/rpm/build.gradle @@ -25,6 +25,7 @@ import org.gradle.util.VersionNumber plugins { id 'nebula.ospackage' version '8.4.1' + id 'org.scm-manager.packaging' } configurations { @@ -37,7 +38,7 @@ dependencies { webapp project(path: ':scm-webapp', configuration: 'webapp') } -task distribution(type: Rpm) { +task rpm(type: Rpm) { packageName 'scm-server' packageGroup 'Development/Tools' summary 'SCM-Manager Server' @@ -129,3 +130,12 @@ task distribution(type: Rpm) { link '/opt/scm-server/conf', '/etc/scm' link '/opt/scm-server/work', '/var/cache/scm/work' } + +task packageYaml(type: PackageYaml) { + type = 'redhat' + dependsOn rpm +} + +task distribution { + dependsOn packageYaml +} diff --git a/scm-packaging/unix/build.gradle b/scm-packaging/unix/build.gradle index 29a5db20fc..6e4d078584 100644 --- a/scm-packaging/unix/build.gradle +++ b/scm-packaging/unix/build.gradle @@ -23,6 +23,10 @@ */ import org.gradle.util.VersionNumber +plugins { + id 'org.scm-manager.packaging' +} + configurations { server webapp @@ -35,11 +39,10 @@ dependencies { jsvc libraries.jsvc } -task distribution(type: Tar) { - +task unix(type: Tar) { VersionNumber version = VersionNumber.parse(project.version) - archiveName = "unix-${project.version}.tar.gz" + archiveName = "unix-${project.version}-app.tar.gz" into('scm-server') { into('conf') { from 'src/main/fs/conf' @@ -79,3 +82,13 @@ task distribution(type: Tar) { destinationDir file('build/libs') compression = Compression.GZIP } + +task packageYaml(type: PackageYaml) { + type = 'unix' + artifact = file("build/libs/unix-${project.version}-app.tar.gz") + dependsOn unix +} + +task distribution { + dependsOn packageYaml +} diff --git a/scm-packaging/windows/build.gradle b/scm-packaging/windows/build.gradle index ca33253d8d..bb5b5802d5 100644 --- a/scm-packaging/windows/build.gradle +++ b/scm-packaging/windows/build.gradle @@ -25,6 +25,7 @@ import org.gradle.util.VersionNumber plugins { id "de.undercouch.download" version "4.1.1" + id 'org.scm-manager.packaging' } configurations { @@ -57,10 +58,10 @@ task verifyWinSW(type: Verify) { dependsOn 'downloadWinSW' } -task distribution(type: Zip) { +task windows(type: Zip) { VersionNumber version = VersionNumber.parse(project.version) - archiveName = "windows-${project.version}.zip" + archiveName = "windows-${project.version}-app.zip" into('scm-server') { into('conf') { from 'src/main/fs/conf' @@ -85,3 +86,13 @@ task distribution(type: Zip) { destinationDir file('build/libs') dependsOn 'verifyWinSW' } + +task packageYaml(type: PackageYaml) { + type = 'windows' + artifact = file("build/libs/windows-${project.version}-app.zip") + dependsOn windows +} + +task distribution { + dependsOn packageYaml +}