Skip to content

Commit 60c1da7

Browse files
author
Jean-Marc van Leerdam
committed
Create task, add dependency to create zip task
1 parent c6d7653 commit 60c1da7

File tree

10 files changed

+124
-22
lines changed

10 files changed

+124
-22
lines changed

README.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ Experimental plugin for sbt to create Azure Function artefacts (function.json) n
77

88
## Setup and Usage
99

10-
* Setup
10+
### Setup
1111

12-
in your `project/plugins.sbt` add sbt-assembly and sbt-azure-functions:
12+
in your `project/plugins.sbt` add sbt-assembly and sbt-azure-functions:
1313

14-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
15-
addSbtPlugin("nl.codestar" % "sbt-azure-functions" % "<latest version>")
16-
17-
in your `build.sbt` provide values for the assembly and azure-functions plugins:
18-
19-
lazy val root = (project in file("."))
20-
.settings(
21-
...
22-
23-
// optional: override the zip and/or jar name (defaults are AzureFunction.zip and AzureFunction.jar)
24-
azfunZipName := "myFunctions.zip",
25-
azfunJarName := "ScalaFunctions.jar",
26-
27-
// you need this dependency to be able to use the annotations
28-
libraryDependencies ++= Seq(
29-
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
30-
)
14+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
15+
addSbtPlugin("nl.codestar" % "sbt-azure-functions" % "<latest version>")
16+
17+
in your `build.sbt` provide values for the assembly and azure-functions plugins:
18+
19+
lazy val root = (project in file("."))
20+
.settings(
21+
...
22+
23+
// optional: override the zip and/or jar name (defaults are AzureFunction.zip and AzureFunction.jar)
24+
azfunZipName := "myFunctions.zip",
25+
azfunJarName := "ScalaFunctions.jar",
26+
27+
// you need this dependency to be able to use the annotations
28+
libraryDependencies ++= Seq(
29+
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
30+
)
3131
32-
)
32+
)
3333

34-
* Usage
34+
### Usage
3535

36-
`sbt azfunCreateZipFile`
36+
* `sbt azfunCreateZipFile`
3737

3838
This will generate the fat jar that you want to upload to Azure (`assembly`), and then generates the function
3939
specifications (`function.json` in separate folders for each method that has been annotated with an `@FunctionName`
@@ -46,6 +46,15 @@ Experimental plugin for sbt to create Azure Function artefacts (function.json) n
4646
* `azfunCopyHostJson` - to copy the `host.json` file
4747
* `azfunCopyLocalSettingsJson` - to copy the `local.settings.json` file
4848

49+
* `sbt azfunDeploy`
50+
51+
This will deploy the function to Azure, using the azure CLI, which is expected to be available on your path
52+
and logged in to the correct Azure Subscription.
53+
54+
You can provide these settings to determine the destination:
55+
* `azfunResourceGroup`
56+
57+
4958
## TODO:
5059
1. add task to upload to Azure
5160
1. add tests against multiple Java versions (java 8 and Java 11)

plugin/src/main/scala/sbtazurefunctions/AzureFunctions.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ object AzureFunctionsKeys {
2727
)
2828
val azfunCopyHostJson = taskKey[File]("Copies host.json file")
2929
val azfunCopyLocalSettingsJson = taskKey[File]("Copies host.json file")
30+
val azfunDeploy = taskKey[Unit]("Deploys the function to Azure")
3031
val azfunGenerateFunctionJsons =
3132
taskKey[File]("Generates the function.json files for all annotated function entry points")
3233

@@ -109,6 +110,18 @@ object AzureFunctions extends AutoPlugin {
109110
IO.zip(allSubpaths(src), tgt)
110111
tgt
111112
},
113+
azfunDeploy := {
114+
// depend on having the zip available
115+
val _ = azfunCreateZipFile.value
116+
//val artefact = azfunCreateZipFile.value
117+
118+
val log = sbt.Keys.streams.value.log
119+
log.info("Running azfunDeploy task...")
120+
121+
import scala.sys.process._
122+
import scala.language.postfixOps
123+
"echo 'hello world'" !
124+
},
112125
azfunGenerateFunctionJsons := {
113126
// depend on assembly step
114127
val assemblyJar = assembly.value
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sbt.Keys.libraryDependencies
2+
3+
lazy val root = (project in file("."))
4+
.settings(
5+
version := "0.1",
6+
scalaVersion := "2.12.7",
7+
libraryDependencies ++= Seq(
8+
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
9+
),
10+
assemblyJarName in assembly := "ScalaFunctions.jar"
11+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "2.0",
3+
"extensionBundle": {
4+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
5+
"version": "[1.*, 2.0.0)"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"AzureWebJobsStorage": "",
5+
"FUNCTIONS_WORKER_RUNTIME": "java"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
2+
3+
sys.props.get("plugin.version") match {
4+
case Some(x) => addSbtPlugin("nl.codestar" % "sbt-azure-functions" % x)
5+
case _ => sys.error("""|The system property 'plugin.version' is not defined.
6+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Main extends App {
2+
println("hello")
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package nl.codestar.sample
2+
3+
import com.microsoft.azure.functions.ExecutionContext
4+
import com.microsoft.azure.functions.HttpMethod
5+
import com.microsoft.azure.functions.HttpRequestMessage
6+
import com.microsoft.azure.functions.HttpResponseMessage
7+
import com.microsoft.azure.functions.HttpStatus
8+
import com.microsoft.azure.functions.annotation.AuthorizationLevel
9+
import com.microsoft.azure.functions.annotation.FunctionName
10+
import com.microsoft.azure.functions.annotation.HttpTrigger
11+
12+
import java.util.Optional
13+
14+
class SampleAzureFunctions {
15+
@FunctionName("ScalaFunction")
16+
def run(
17+
@HttpTrigger(
18+
name="req",
19+
methods = Array(HttpMethod.GET),
20+
authLevel = AuthorizationLevel.ANONYMOUS) request: HttpRequestMessage[Optional[String]],
21+
context: ExecutionContext): HttpResponseMessage = {
22+
context.getLogger.info("Scala HTTP Trigger received a request")
23+
request.createResponseBuilder(HttpStatus.OK).body("Hello there").build()
24+
}
25+
26+
@FunctionName("SecondFunction")
27+
def runAnother(
28+
@HttpTrigger(
29+
name="req2",
30+
methods = Array(HttpMethod.GET),
31+
authLevel = AuthorizationLevel.ANONYMOUS) request: HttpRequestMessage[Optional[String]],
32+
context: ExecutionContext): HttpResponseMessage = {
33+
context.getLogger.info("Scala HTTP Trigger received a request")
34+
request.createResponseBuilder(HttpStatus.OK).body("Hello there").build()
35+
}
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# test deploy task
2+
> azfunDeploy
3+
4+
# Uncomment the next lines if you want to look at the results from the scripted test
5+
# $ pause

releasenotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release notes
22

3+
## Version 0.5.0
4+
New features:
5+
* New task to deploy function to azure (`azfunDeploy`)
6+
37
## Version 0.4.1
48
Bug fixes:
59
* Default folder name for results used .zip extension

0 commit comments

Comments
 (0)