Skip to content

Commit 3461e63

Browse files
committed
update janalyse, README fix, fill name in ssh options, sshDir and sshKeyFile changes
1 parent 360ec1e commit 3461e63

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ Add resolver to `project/plugins.sbt`:
4040
resolvers += "JAnalyse Repository" at "http://www.janalyse.fr/repository/"
4141
```
4242

43+
Add import to your project build file
44+
45+
```sbt
46+
import deployssh.DeploySSH._
47+
```
48+
4349
Enable plugin in your project.
4450
For example in your `build.sbt`
4551

@@ -57,14 +63,19 @@ You can use `.conf` files or set configs directly in project settings.
5763

5864
Allowed config fields:
5965

60-
* `name` - your server name. **Should be unique** in all loaded configs. (Duplication will be overriden)
66+
* `name` - your server name. **Should be unique** in all loaded configs. (Duplication will be overridden)
6167
* `host` - ip adress or hostname of the server
6268
* `user` - ssh username. If missing or empty will be used your current user (`user.name`)
6369
* `password`- ssh password. If missing or empty will be used ssh key
6470
* `passphrase`- passphrase for ssh key. Remove or leave empty for ssh key without passphrase
6571
* `port` - ssh port. If missing or empty will be used `22`
66-
* `sshDir` - directory with you ssh keys. This directory should contain `id_rsa` or `id_dsa`. By default `user.name/.ssh` directory. This field is not allowed to be empty in `.conf` file. You should remove this field from config in `.conf` file to use default value.
67-
* `sshKeyFile` - private key that will be used for ssh connection. By default will be used `id_rsa` or `id_dsa`. This field is not allowed to be empty in `.conf` file. You should remove this field from config in `.conf` file to use default value.
72+
* `sshDir` - directory with you ssh keys.
73+
This directory should contain `identity`, `id_dsa`, `id_ecdsa`, `id_ed25519` or `id_rsa` (the first matched file in the folder will be used for auth).
74+
By default `user.name/.ssh` directory. This field is not allowed to be empty in `.conf` file.
75+
You should remove this field from config in `.conf` file to use default value.
76+
* `sshKeyFile` - add additional private key file name that will be used for ssh connection.
77+
This file name will be added to head of the default list [`identity`, `id_dsa`, `id_ecdsa`, `id_ed25519`, `id_rsa`].
78+
This field is not allowed to be empty in `.conf` file. You should remove this field from config in `.conf` file to use default value.
6879

6980
**`name` and `host` fields are mandatory**
7081

@@ -95,7 +106,7 @@ servers = [
95106
host = "169.254.0.2"
96107
user = "ssh_test"
97108
sshDir = "/tmp/.sshKeys"
98-
sshKeyFile = "id_a12
109+
sshKeyFile = "id_a12" #custom private key file name
99110
}
100111
]
101112
```
@@ -124,7 +135,7 @@ lazy val myProject = project.enablePlugins(DeploySSH).settings(
124135
)
125136
)
126137

127-
val mySettings = Seq(
138+
lazy val mySettings = Seq(
128139
ServerConfig("server_5", "169.254.0.2")
129140
)
130141
```
@@ -159,9 +170,11 @@ or
159170

160171
Use `deploySshExecBefore` and `deploySshExecAfter` to execute any bash commands before and after deploy.
161172

162-
Any exeption in `deploySshExecBefore` and `deploySshExecAfter` will abort deploy for all servers.
173+
Any exception in `deploySshExecBefore` and `deploySshExecAfter` will abort deploy for all servers.
174+
175+
To skip deploy only for current server you should wrap exception to `SkipDeployException`.
163176

164-
To skip deploy only for curent server you should wrap exeption to `SkipDeployException`.
177+
For example stop and update and run your app, copy with scp needed application.conf depends on server name:
165178

166179
``` sbt
167180
lazy val myProject = project.enablePlugins(DeploySSH).settings(
@@ -181,6 +194,9 @@ lazy val myProject = project.enablePlugins(DeploySSH).settings(
181194
),
182195
deploySshExecAfter ++= Seq(
183196
(ssh: SSH) => {
197+
ssh.scp { scp =>
198+
scp.send(file(s"./src/main/resources/application-${ssh.options.name.get}.conf"), s"/home/app/application.conf")))
199+
}
184200
ssh.execOnce("nohup ./myApp/run & echo $! > ~/pid")
185201
ssh.execOnce("touch pid")
186202
val pid = ssh.execOnceAndTrim("cat pid")

build.sbt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sbtPlugin := true
44

55
name := "sbt-deploy-ssh"
66
organization := "com.github.shmishleniy"
7-
version := org.eclipse.jgit.api.Git.open(file(".")).describe().call()
7+
version := "0.1.3"
88

99
publishMavenStyle := false
1010
bintrayPublishSettings
@@ -15,7 +15,8 @@ bintrayOrganization in bintray := None
1515
resolvers += "JAnalyse Repository" at "http://www.janalyse.fr/repository/"
1616
libraryDependencies ++= Seq(
1717
"com.typesafe" % "config" % "1.2.1",
18-
"fr.janalyse" %% "janalyse-ssh" % "0.9.19"
18+
"fr.janalyse" %% "janalyse-ssh" % "0.9.19",
19+
"org.scalaz" %% "scalaz-core" % "7.2.8"
1920
)
2021

2122
scalacOptions in Compile ++= Seq("-encoding","UTF-8","-target:jvm-1.7","-deprecation","-feature")

src/main/scala/DeploySSH.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,23 @@ object DeploySSH extends AutoPlugin {
145145
execBefore: Seq[(SSH) => Any],
146146
execAfter: Seq[(SSH) => Any],
147147
log: Logger): Unit = {
148-
import java.io.File.{separator=>`/`}
149-
val sshKey = serverConfig.sshDir.getOrElse(Properties.userHome+`/`+".ssh")+`/`+serverConfig.sshKeyFile
148+
import java.io.File.separator
149+
import java.nio.file.Paths
150+
151+
val sshDir = serverConfig.sshDir.map(Paths.get(_)).getOrElse(Paths.get(Properties.userHome + separator + ".ssh"))
152+
val keyFilenames = (serverConfig.sshKeyFile.toList ++ SSHOptions.defaultPrivKeyFilenames).distinct
153+
val identities = keyFilenames.map(f => sshDir.resolve(f)).map(p => SSHIdentity(p.toString))
150154

151155
implicit val ssh = SSH(
152-
SSHOptions(serverConfig.host,
156+
SSHOptions(
157+
serverConfig.host,
153158
serverConfig.user getOrElse Properties.userName,
154159
serverConfig.password,
155160
serverConfig.passphrase,
161+
Some(serverConfig.name),
156162
port = serverConfig.port.getOrElse(22),
157-
identities = SSHIdentity(sshKey)::Nil)
163+
identities = identities
164+
)
158165
)
159166
val sftp = ssh.newSftp
160167
log.info("Exec before deploy")

0 commit comments

Comments
 (0)