|
1 |
| -apply plugin: "org.hidetake.ssh" |
2 | 1 | apply plugin: "com.github.node-gradle.node"
|
3 | 2 | apply plugin: 'com.gradleup.shadow'
|
4 | 3 | apply plugin: "application"
|
@@ -68,72 +67,71 @@ run {
|
68 | 67 | }
|
69 | 68 | }
|
70 | 69 |
|
71 |
| -remotes { |
72 |
| - pi { |
73 |
| - host = 'photonvision.local' |
74 |
| - user = 'pi' |
75 |
| - password = 'raspberry' |
76 |
| - knownHosts = allowAnyHosts |
77 |
| - } |
78 |
| -} |
79 |
| - |
80 |
| -task findDeployTarget { |
81 |
| - doLast { |
82 |
| - if(project.hasProperty('tgtIP')){ |
83 |
| - //If user specified IP, default to using the PI profile |
84 |
| - // but adjust hostname to match the provided IP address |
85 |
| - findDeployTarget.ext.rmt = remotes.pi |
86 |
| - findDeployTarget.ext.rmt.host=tgtIP |
87 |
| - } else { |
88 |
| - findDeployTarget.ext.rmt = null |
89 |
| - for(testRmt in remotes){ |
90 |
| - println "Checking for " + testRmt.host |
91 |
| - boolean canContact = false; |
92 |
| - try { |
93 |
| - InetAddress testAddr = InetAddress.getByName(testRmt.host) |
94 |
| - canContact = testAddr.isReachable(2000) |
95 |
| - } catch(UnknownHostException e) { |
96 |
| - canContact = false; |
| 70 | +import edu.wpi.first.deployutils.deploy.artifact.* |
| 71 | +import edu.wpi.first.deployutils.deploy.target.RemoteTarget |
| 72 | +import edu.wpi.first.deployutils.deploy.target.location.SshDeployLocation |
| 73 | +deploy { |
| 74 | + targets { |
| 75 | + pi(RemoteTarget) { |
| 76 | + // Can't login as root, so deploy our file to /tmp, which is owned by pi |
| 77 | + directory = '/tmp' |
| 78 | + locations { |
| 79 | + ssh(SshDeployLocation) { |
| 80 | + if (project.hasProperty('tgtIP')) { |
| 81 | + address = tgtIP |
| 82 | + } else { |
| 83 | + address = "photonvision.local" |
| 84 | + } |
| 85 | + if (project.hasProperty('tgtUser')) { |
| 86 | + user = tgtUser |
| 87 | + } else { |
| 88 | + user = "pi" |
| 89 | + } |
| 90 | + if (project.hasProperty('tgtPw')) { |
| 91 | + password = tgtPw |
| 92 | + } else { |
| 93 | + password = "raspberry" |
| 94 | + } |
97 | 95 | }
|
98 |
| - if(canContact){ |
99 |
| - println "Found!" |
100 |
| - findDeployTarget.ext.rmt = testRmt |
101 |
| - break |
102 |
| - } else { |
103 |
| - println "Not Found." |
104 |
| - } |
105 |
| - } |
106 |
| - if(findDeployTarget.ext.rmt == null ){ |
107 |
| - throw new GradleException("Could not find a supported target for deployment!") |
108 | 96 | }
|
109 |
| - } |
110 |
| - } |
111 |
| -} |
112 |
| - |
113 |
| -task deploy { |
114 |
| - dependsOn findDeployTarget |
115 |
| - dependsOn 'shadowJar' |
116 |
| - |
117 |
| - doLast { |
118 |
| - println 'Starting deployment to ' + findDeployTarget.rmt.host |
119 |
| - println 'targetArch = ' + wpilibTools.platformMapper.currentPlatform.platformName |
120 |
| - ssh.run{ |
121 |
| - session(findDeployTarget.rmt) { |
122 |
| - //Stop photonvision before manipulating its files |
123 |
| - execute 'sudo systemctl stop photonvision.service' |
124 |
| - // gerth2 - I was having issues with the .jar being in use still - waiting a tiny bit here seems to get rid of it on a pi4 |
125 |
| - execute 'sleep 3' |
126 |
| - // Copy into a folder owned by PI. Mostly because, as far as I can tell, the put command doesn't support sudo. |
127 |
| - put from: "${projectDir}/build/libs/photonvision-${project.version}-${wpilibTools.platformMapper.currentPlatform.platformName}.jar", into: "/tmp/photonvision.jar" |
128 |
| - //belt-and-suspenders. Make sure the old jar is gone first. |
129 |
| - execute 'sudo rm -f /opt/photonvision/photonvision.jar' |
130 |
| - //Copy in the new .jar and make sure it's executable |
131 |
| - execute 'sudo mv /tmp/photonvision.jar /opt/photonvision/photonvision.jar' |
132 |
| - execute 'sudo chmod +x /opt/photonvision/photonvision.jar' |
133 |
| - //Fire up photonvision again |
134 |
| - execute 'sudo systemctl start photonvision.service' |
135 |
| - //Cleanup |
136 |
| - execute 'sudo rm -f /tmp/photonvision.jar' |
| 97 | + artifacts { |
| 98 | + stop(CommandArtifact) { |
| 99 | + predeploy << { |
| 100 | + println 'Starting deployment to ' + deploy.targets.pi.locations.ssh.address |
| 101 | + println 'targetArch = ' + wpilibTools.platformMapper.currentPlatform.platformName |
| 102 | + } |
| 103 | + //Stop photonvision before manipulating its files |
| 104 | + command = "sudo systemctl stop photonvision.service" |
| 105 | + } |
| 106 | + sleep(CommandArtifact) { |
| 107 | + // gerth2 - I was having issues with the .jar being in use still - waiting a tiny bit here seems to get rid of it on a pi4 |
| 108 | + command = "sleep 3" |
| 109 | + dependsOn artifacts.stop.deployTask |
| 110 | + } |
| 111 | + photonvisionJar(JavaArtifact) { |
| 112 | + jarTask = shadowJar |
| 113 | + filename = "photonvision.jar" |
| 114 | + dependsOn artifacts.sleep.deployTask |
| 115 | + } |
| 116 | + moveJar(CommandArtifact) { |
| 117 | + //belt-and-suspenders. Make sure the old jar is gone first before moving in the new .jar |
| 118 | + command = "sudo rm -f /opt/photonvision/photonvision.jar && sudo mv /tmp/photonvision.jar /opt/photonvision/photonvision.jar" |
| 119 | + dependsOn artifacts.photonvisionJar.deployTask |
| 120 | + } |
| 121 | + chmodJar(CommandArtifact) { |
| 122 | + //Make sure it's executable |
| 123 | + command = "sudo chmod +x /opt/photonvision/photonvision.jar" |
| 124 | + dependsOn artifacts.moveJar.deployTask |
| 125 | + } |
| 126 | + start(CommandArtifact) { |
| 127 | + //Fire up photonvision again |
| 128 | + command = "sudo systemctl start photonvision.service" |
| 129 | + dependsOn artifacts.chmodJar.deployTask |
| 130 | + } |
| 131 | + cleanUp(CommandArtifact) { |
| 132 | + command = 'sudo rm -f /tmp/photonvision.jar' |
| 133 | + dependsOn artifacts.moveJar.deployTask |
| 134 | + } |
137 | 135 | }
|
138 | 136 | }
|
139 | 137 | }
|
|
0 commit comments