Create package.yml for each distributed package

This commit is contained in:
Sebastian Sdorra
2021-01-05 11:08:05 +01:00
committed by René Pfeuffer
parent 822f88561b
commit 87da653575
9 changed files with 212 additions and 11 deletions

View File

@@ -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'
}
}
}

View File

@@ -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"
}
}
}

View File

@@ -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<Project> {
void apply(Project project) {
project.ext.PackageYaml = PackageYamlTask
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}