Skip to content

Commit fcbc392

Browse files
authored
Use deploy-utils instead of an external ssh plugin (#2077)
1 parent 7d927ac commit fcbc392

File tree

4 files changed

+66
-67
lines changed

4 files changed

+66
-67
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Note that these are case sensitive!
4141
* linuxarm64
4242
* linuxathena
4343
- `-PtgtIP`: Specifies where `./gradlew deploy` should try to copy the fat JAR to
44+
- `-PtgtUser`: Specifies custom username for `./gradlew deploy` to SSH into
45+
- `-PtgtPw`: Specifies custom password for `./gradlew deploy` to SSH into
4446
- `-Pprofile`: enables JVM profiling
4547
- `-PwithSanitizers`: On Linux, enables `-fsanitize=address,undefined,leak`
4648

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ plugins {
1111
id "org.ysb33r.doxygen" version "1.0.4" apply false
1212
id 'com.gradleup.shadow' version '8.3.4' apply false
1313
id "com.github.node-gradle.node" version "7.0.1" apply false
14-
id "org.hidetake.ssh" version "2.11.2" apply false
1514
}
1615

1716
allprojects {

docs/source/docs/contributing/building-photon.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Running the following command under the root directory will build the jar under
113113

114114
### Build and Run PhotonVision on a Raspberry Pi Coprocessor
115115

116-
As a convenience, the build has a built-in `deploy` command which builds, deploys, and starts the current source code on a coprocessor.
116+
As a convenience, the build has a built-in `deploy` command which builds, deploys, and starts the current source code on a coprocessor. It uses [deploy-utils](https://github.com/wpilibsuite/deploy-utils/blob/main/README.md), so it works very similarly to deploys on robot projects.
117117

118118
An architecture override is required to specify the deploy target's architecture.
119119

photon-server/build.gradle

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
apply plugin: "org.hidetake.ssh"
21
apply plugin: "com.github.node-gradle.node"
32
apply plugin: 'com.gradleup.shadow'
43
apply plugin: "application"
@@ -68,72 +67,71 @@ run {
6867
}
6968
}
7069

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+
}
9795
}
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!")
10896
}
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+
}
137135
}
138136
}
139137
}

0 commit comments

Comments
 (0)