mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-14 19:42:11 +01:00
150 lines
3.5 KiB
Groovy
150 lines
3.5 KiB
Groovy
/*
|
|
* Copyright (c) 2020 - present Cloudogu GmbH
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
* Software Foundation, version 3.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
* details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
|
*/
|
|
|
|
plugins {
|
|
id 'org.scm-manager.packaging'
|
|
id 'org.scm-manager.license'
|
|
}
|
|
|
|
|
|
import org.gradle.util.VersionNumber
|
|
|
|
configurations {
|
|
server
|
|
webapp
|
|
packageYaml {
|
|
canBeConsumed = true
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
server project(':scm-server')
|
|
webapp project(path: ':scm-webapp', configuration: 'webapp')
|
|
}
|
|
|
|
task context(type: Copy) {
|
|
VersionNumber version = VersionNumber.parse(project.version)
|
|
destinationDir = project.buildDir
|
|
into('docker') {
|
|
into('etc') {
|
|
from('src/main/fs/etc')
|
|
expand([version: version])
|
|
}
|
|
into('opt') {
|
|
from('src/main/fs/opt')
|
|
}
|
|
into('opt/scm-server/lib') {
|
|
from project.configurations.server
|
|
}
|
|
into('opt/scm-server/var/webapp') {
|
|
from project.configurations.webapp
|
|
rename {
|
|
'scm-webapp.war'
|
|
}
|
|
}
|
|
from('.') {
|
|
include 'Dockerfile'
|
|
}
|
|
}
|
|
}
|
|
|
|
task setupBuilder() {
|
|
doLast {
|
|
def inspect = exec {
|
|
commandLine = ["docker", "buildx", "inspect", "scm-builder"]
|
|
ignoreExitValue = true
|
|
}
|
|
if (inspect.exitValue != 0) {
|
|
exec {
|
|
commandLine = ["docker", "run", "--privileged", "--rm", "tonistiigi/binfmt", "--install", "arm64"]
|
|
}
|
|
exec {
|
|
commandLine = ["docker", "buildx", "create", "--name", "scm-builder", "--driver", "docker-container", "--platform", "linux/arm/v7,linux/arm64/v8,linux/amd64"]
|
|
}
|
|
exec {
|
|
commandLine = ["docker", "buildx", "inspect", "scm-builder"]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
task build(type: Exec) {
|
|
commandLine = ["docker", "buildx", "bake", "--builder", "scm-builder", isSnapshot ? "dev": "prod"]
|
|
|
|
setEnvironmentForDockerBuild({ String name, Object value -> environment(name, value) })
|
|
|
|
doLast {
|
|
File file = new File(project.buildDir, 'docker.tag')
|
|
file.text = dockerTag
|
|
}
|
|
dependsOn 'context', 'setupBuilder'
|
|
}
|
|
|
|
task pushImages(type: Exec) {
|
|
commandLine = ["docker", "buildx", "bake", "--builder", "scm-builder", isSnapshot ? "dev": "prod", "--push"]
|
|
|
|
setEnvironmentForDockerBuild({ String name, Object value -> environment(name, value) })
|
|
|
|
dependsOn 'build'
|
|
}
|
|
|
|
task publish() {
|
|
dependsOn 'pushImages'
|
|
}
|
|
|
|
task distribution(type: PackageYaml) {
|
|
type = 'docker'
|
|
dependsOn build
|
|
}
|
|
|
|
artifacts {
|
|
packageYaml(file('build/libs/package.yml')) {
|
|
builtBy distribution
|
|
}
|
|
}
|
|
|
|
license {
|
|
header rootProject.file("LICENSE-HEADER.txt")
|
|
lineEnding = "\n"
|
|
|
|
tasks {
|
|
build {
|
|
files.from("build.gradle", "Dockerfile")
|
|
}
|
|
main {
|
|
files.from("src")
|
|
}
|
|
}
|
|
}
|
|
|
|
task check {
|
|
dependsOn checkLicenses
|
|
}
|
|
|
|
def setEnvironmentForDockerBuild(environment){
|
|
environment "VERSION", dockerTag
|
|
environment "COMMIT_SHA", revision
|
|
environment "IMAGE", dockerRepository
|
|
|
|
if (project.hasProperty("isHotfix")) {
|
|
environment "IS_HOTFIX", isHotfix
|
|
println("Setting hotfix to ${isHotfix}")
|
|
} else {
|
|
environment "IS_HOTFIX", true
|
|
println("'isHotfix'-Property not defined. Assuming hotfix release")
|
|
}
|
|
}
|