-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
86 lines (72 loc) · 2.63 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import gov.nyc.doitt.nyc.gis.gradle.*
plugins {
id 'base'
id 'org.hidetake.ssh' version '1.1.2'
}
ext{
appName = 'idnyc'
ver = 'v1.0.2'
local_nyclib = 'https://maps.nyc.gov/nyc-lib/'
stg_nyclib = '../nyc-lib/'
prd_nyclib = '../nyc-lib/'
default_env = 'local'
}
task setEnv << {
if (!project.hasProperty('env')) project.ext.env = default_env
archive.archiveName = "${appName}-${ver}-${env}.zip"
archive.from {"build/${ver}"}
}
task copyFiles(dependsOn: clean) << {
def build = new File("build/${ver}")
build.mkdirs()
copy {
from 'src'
include '*.html'
include '*.json'
include 'img/**'
include 'manifest.webmanifest'
exclude 'img/Thumbs.db'
include 'data/**'
include 'ta/**'
into "build/${ver}"
}
}
task replaceTokens(dependsOn: [setEnv, copyFiles]) << {
ant.taskdef(name: 'replace', classname: 'org.apache.tools.ant.taskdefs.Replace')
ant.replace(file: "build/${ver}/index.html", token: local_nyclib, value: project.ext["${env}_nyclib"])
if (project.hasProperty("idnyc.${env}.geoclient.url")){
ant.replace(file: "build/${ver}/index.html", token: project.ext['idnyc.git.geoclient.url'], value: project.ext["idnyc.${env}.geoclient.url"])
}
if (project.hasProperty("idnyc.${env}.google.url")){
ant.replace(file: "build/${ver}/index.html", token: project.ext['idnyc.git.google.url'], value: project.ext["idnyc.${env}.google.url"])
}
if (project.hasProperty("idnyc.${env}.analytics")){
ant.replace(file: "build/${ver}/index.html", token: '<!-- google analytics -->', value: project.ext["idnyc.${env}.analytics"])
}
}
task archive(type: Zip, dependsOn: [replaceTokens]) {}
remotes {
deployTarget {}
}
task deploy(dependsOn: [archive]) << {
def archiveDir = project.ext['archive.dir']
def deployDir = project.ext['idnyc.deploy.dir']
remotes.deployTarget.host = project.ext["${env}.host"]
remotes.deployTarget.user = project.ext["${env}.user"]
remotes.deployTarget.identity = file("${System.properties['user.home']}/.ssh/id_rsa")
println "deploying ${archive.archiveName} to ${remotes.deployTarget.host}:${deployDir}"
ssh.run {
session(remotes.deployTarget) {
execute "mkdir -p ${archiveDir}"
execute "mkdir -p ${deployDir}"
put "build/distributions/${archive.archiveName}", archiveDir
execute "cp -R ${deployDir} ${deployDir}.bak"
execute "rm -rf ${deployDir}"
execute "unzip ${archiveDir}/${archive.archiveName} -d ${deployDir}"
execute "rm -rf ${deployDir}.bak"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion '2.9'
}