blob: 99b4e3d344c1991cef7ee2db7a1d920c558c1f90 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
ext.dockerImageName = "wskdeploy"
ext.dockerContainerName = "wskdeploy"
ext.dockerBuildArgs = getDockerBuildArgs()
apply from: 'gradle/docker.gradle'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.org.nosphere.apache:creadur-rat-gradle:0.3.1"
}
}
apply plugin: "org.nosphere.apache.rat"
rat {
excludes += [
'Godeps/*',
'.gradletasknamecache', 'gradle/wrapper/**', 'gradlew*', 'build/**', // Gradle
'.gitignore', '.rat-excludes',
'i18n_resources.go',
'**/*.json','wski18n/resources/*'
]
}
project.ext {
basePackageName = "openwhisk-wskdeploy"
packageExtension = "tar.gz"
if (project.hasProperty('projectVersion')) {
packageVersion = "${projectVersion}"
} else {
packageVersion = ""
}
buildFolder = "build"
}
task taredSources(type: Tar) {
baseName basePackageName
description "Creates a combined tar.gz file of wskdeploy's sources"
group "Release artifact"
classifier "sources"
from(project.rootDir) {
include('cmd/*.go', 'deployers/*.go', 'parsers/*.go', 'utils/*.go',
'wskderrors/*.go', 'wskenv/*.go', 'wskprint/*.go', 'wski18n/**')
include('*.go')
include('gradle/**')
include('README.md', 'CONTRIBUTING.md', 'DEPENDENCIES.md')
include('gradlew', 'gradlew.bat', 'Dockerfile', 'build.gradle')
include('LICENSE.txt', 'NOTICE.txt', 'CHANGELOG.txt')
}
destinationDir file(buildFolder)
extension packageExtension
version packageVersion
compression = Compression.GZIP
}
task cleanBuild(type: Delete) {
def folder = new File(buildFolder)
if(folder.exists()) {
delete file(buildFolder).listFiles()
}
}
task removeBinary(type: Delete) {
delete "${projectDir}/bin/wskdeploy"
delete "${projectDir}/bin/mac"
delete "${projectDir}/bin/linux"
delete "${projectDir}/bin/windows"
}
task distBinary(dependsOn: [removeBinary, distDocker]) {
doLast {
run(dockerBinary + ["rm", "-f", dockerContainerName], true)
run(dockerBinary + ["run", "--name", dockerContainerName, dockerTaggedImageName])
// Copy all Go binaries from Docker into openwhisk/bin folder
run(dockerBinary + ["cp", dockerContainerName +
":/src/github.com/apache/incubator-openwhisk-wskdeploy/build/.", "${projectDir}/bin"])
run(dockerBinary + ["rm", "-f", dockerContainerName])
}
}
task dumpOSInfo {
doLast {
println "os.name = "+getOsName()
println "os.arch = "+getOsArch()
println "go.name = "+mapOsNameToGoName(getOsName())
println "go.arch = "+mapOsArchToGoArch(getOsArch())
}
}
task copyWSKDEPLOYShortcut(type: Copy, dependsOn: [distBinary, dumpOSInfo]) {
String go_osname = mapOsNameToGoName(getOsName())
String go_osarch = mapOsArchToGoArch(getOsArch())
String from_path_wsk = "${projectDir}/bin/${go_osname}/${go_osarch}/wskdeploy"
String to_path_dir = "${projectDir}/bin"
from from_path_wsk
into to_path_dir
}
pushImage.finalizedBy copyWSKDEPLOYShortcut
// Returns the Go CLI docker build args
def getDockerBuildArgs() {
String local_os = mapOsNameToGoName(getOsName())
String local_arch = mapOsArchToGoArch(getOsArch())
def res = []
if(!project.hasProperty('crossCompileWSKDEPLOY') || project.crossCompileWSKDEPLOY == "false") {
res = ["WSKDEPLOY_OS=${local_os}", "WSKDEPLOY_ARCH=${local_arch}"]
} else {
res = ["WSKDEPLOY_OS=mac linux windows", "WSKDEPLOY_ARCH=386 amd64"]
}
return res
}
def run(cmd, ignoreError = false) {
println("Executing '${cmd.join(" ")}'")
def proc = cmd.execute()
proc.waitFor()
if(!ignoreError && proc.exitValue() != 0) {
println("Command '${cmd.join(" ")}' failed with exitCode ${proc.exitValue()}")
}
}
def getOsName() {
return System.properties['os.name']
}
def getOsArch() {
return System.properties['os.arch']
}
def mapOsNameToGoName(String osname) {
String osname_l = osname.toLowerCase()
if (osname_l.contains("nux") || osname.contains("nix")) return "linux"
if (osname_l.contains("mac")) return "mac"
if (osname_l.contains("windows")) return "windows"
return osname_l
}
def mapOsArchToGoArch(String osarch) {
String osarch_l = osarch.toLowerCase()
if (osarch_l.contains("x86_64") || osarch_l == "amd64") return "amd64"
if (osarch_l.contains("i386") || osarch_l.contains("x86_32")) return "386"
return osarch_l
}