Skip to content

Commit c090e97

Browse files
committed
add example project
1 parent f9c8836 commit c090e97

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed

example/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Example
2+
3+
This example uses native-packager and just prints its config.
4+
5+
```bash
6+
ssh-copy-id localhost
7+
sbt
8+
> deploySsh server1
9+
cat /tmp/example/nohup.out
10+
# should be 'name1'
11+
```

example/build.sbt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ThisBuild / scalaVersion := "2.12.8"
2+
ThisBuild / fork := true
3+
ThisBuild / cancelable in Global := true
4+
ThisBuild / scalacOptions in Compile ++= Vector(
5+
"-target:jvm-1.8",
6+
"-feature",
7+
"-unchecked",
8+
"-deprecation",
9+
"-language:_",
10+
"-encoding", "UTF-8",
11+
"-Xfatal-warnings",
12+
"-Ywarn-unused-import",
13+
)
14+
15+
import deployssh.DeploySSH.{ServerConfig, ArtifactSSH}
16+
import fr.janalyse.ssh.SSH
17+
18+
lazy val example = project.in(file(".")).settings(
19+
libraryDependencies += "com.typesafe" % "config" % "1.3.3",
20+
mainClass in (Compile, run) := Some("example.App"),
21+
deployConfigs ++= Seq(
22+
ServerConfig(name="server1", host="localhost", user=None),
23+
),
24+
deployArtifacts ++= Seq(
25+
ArtifactSSH((packageBin in Universal).value, "/tmp/example")
26+
),
27+
deploySshExecBefore ++= Seq(
28+
(ssh: SSH) => ssh.shell{ shell =>
29+
shell.execute("cd /tmp/example")
30+
shell.execute("touch pid")
31+
val pid = shell.execute("cat pid")
32+
if (pid != "") {
33+
shell.execute(s"kill ${pid}; sleep 5; kill -9 ${pid}")
34+
} else ()
35+
shell.execute("rm pid")
36+
}
37+
),
38+
deploySshExecAfter ++= Seq(
39+
(ssh: SSH) => {
40+
ssh.scp { scp =>
41+
scp.send(file(s"./deploy/${ssh.options.name.get}.conf"), "/tmp/example/app.conf")
42+
}
43+
ssh.shell{ shell =>
44+
val name = (packageName in Universal).value
45+
val script = (executableScriptName in Universal).value
46+
shell.execute("cd /tmp/example")
47+
shell.execute(s"unzip -q -o ${name}.zip")
48+
shell.execute(s"rm ${name}.zip")
49+
shell.execute(s"nohup ./${name}/bin/${script} -Dconfig.file=/tmp/example/app.conf &")
50+
shell.execute("echo $! > pid")
51+
shell.execute("touch pid")
52+
val pid = shell.execute("cat pid")
53+
val (_, status) = shell.executeWithStatus("echo $?")
54+
if (status != 0 || pid == "") {
55+
throw new RuntimeException(s"status=${status}, pid=${pid}. please check package")
56+
}
57+
}
58+
}
59+
),
60+
).enablePlugins(JavaAppPackaging, DeploySSH)

example/deploy/server1.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = name1

example/project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.2.8

example/project/plugins.sbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
scalacOptions in Compile ++= Seq("-deprecation", "-feature")
2+
3+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.14")
4+
5+
resolvers += "JAnalyse Repository" at "http://www.janalyse.fr/repository/"
6+
addSbtPlugin("com.github.shmishleniy" % "sbt-deploy-ssh" % "0.1.4")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = default

example/src/main/scala/App.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package example
2+
3+
import com.typesafe.config.ConfigFactory
4+
5+
object Example extends App {
6+
val config = ConfigFactory.load()
7+
val name = config.getString("name")
8+
val t = System.currentTimeMillis
9+
println(s"name=${name}, t=${t}")
10+
}

0 commit comments

Comments
 (0)