Experimental plugin for sbt to create Azure Function artefacts (function.json) needed to publish code as an Azure Function.
in your project/plugins.sbt add sbt-assembly and sbt-azure-functions:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")
addSbtPlugin("nl.codestar" % "sbt-azure-functions" % "<latest version>")
in your build.sbt provide values for the assembly and azure-functions plugins:
lazy val root = (project in file("."))
.settings(
...
// replace these values with appropriate values for your Azure Function
azfunFunctionAppName := "ScalaFunction",
azfunLocation := "azure-location", // e.g. "westeurope", "eastus", etc.
azfunResourceGroup := "your-resource-group",
azfunStorageAccount := "yourstorageaccount"
// optional: override the zip and/or jar name (defaults are AzureFunction.zip and AzureFunction.jar)
azfunZipName := "myFunctions.zip",
azfunJarName := "ScalaFunctions.jar",
// you need this dependency to be able to use the annotations
libraryDependencies ++= Seq(
"com.microsoft.azure.functions" % "azure-functions-java-library" % "3.1.0"
)
)
-
sbt azfunCreateZipFileThis will generate the fat jar that you want to upload to Azure (
assembly), and then generates the function specifications (function.jsonin separate folders for each method that has been annotated with an@FunctionNameannotation, and further detailed with@HttpTriggerannotation).The
azfunCreateZipFiletask will automatically trigger the following intermediate tasks that could also be called individually:azfunGenerateFunctionJsons- to make thefunction.jsonfiles (implicitly callsassemblytask)azfunCopyHostJson- to copy thehost.jsonfileazfunCopyLocalSettingsJson- to copy thelocal.settings.jsonfile
-
sbt azfunDeployThis will deploy the function to Azure, using the azure CLI, which is expected to be available on your path and logged in to the correct Azure Subscription. You will also have to install the app-insights extension to the CLI, by running
az extension add -n application-insightsYou must provide the following settings to determine the destination:
azfunResourceGroupazfunStorageAccount
- add support for App Insights workspaces
- add tests against multiple Java versions (java 8 and Java 11)
Since this is an sbt plugin, it should be usable with multiple versions of sbt. This means it needs to be built and released for different scala versions and different sbt versions. I have not (yet) found a good resource that documents what Scala version is used for each sbt release, except for sbt/sbt#5032, so I am also keeping track here:
| SBT release(s) | Scala version | Remarks |
|---|---|---|
| 0.x | 2.10.x | |
| 1.x | 2.12.x | |
| 2.x | 2.13.x or 3.0.x | |
| 3.x | 3.0.x or 3.1.x |
For now, I will focus only on sbt 1.x and Scala 2.12.x
This plugin uses artifacts from Microsoft:
"com.microsoft.azure" % "azure-tools-common" % "0.10.0""com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1" % "test"
For now I will use these versions
sbt clean test
sbt publishLocalsbt scripted
Note: to successfully run the deploy scripted test, you need to have the Azure CLI installed and logged in to Azure with proper access
to a subscription that has a resource group and storage account as specified in the sbt-test/sbt-azure-functions/deploy/build.sbt file.
To release a new version, all you have to do is push a tag that starts with v (v0.5.1 for example).
The Github Action Release will pick it up and perform the sbt ci-release command, which will publish the plugin to Sonatype.
Then go to the Github Repo and create a new release, using the tag you just pushed.
In case you want to run the sbt ci-release command locally, you need to mimic the environment that the Github Action uses.
Make sure you have:
- proper access to the
nl.codestarnamespace on Sonatype. - GnuPG (
gpg) installed and a signing key configured.- We use
sbt-pgpplugin to sign, which relies on thegpgcommand line tool
- We use
- create a
.envfile in the project root with the following variables:PGP_ID=<id of the signing key> PGP_SECRET="---BEGIN PGP PRIVATE KEY BLOCK --- ... ---END PGP PRIVATE KEY BLOCK---" PGP_SECRET_B64=<base64 encoded version of PGP_SECRET> PGP_PASSPHRASE=<your PGP passphrase> SONATYPE_USERNAME=<user id or token id> SONATYPE_PASSWORD=<password or token>
Note: The .env file needs to be kept out of the git repository (it is .gitignored)!
See Using Sonatype in the SBT documentation.
Steps to release SNAPSHOT version:
- Make sure HEAD is not directly pointing to a tag
sbt publishSigned- make note of the SNAPSHOT version that is used (Sonatype does not allow searching/browsing for SNAPSHOT versions)
Steps to release production version:
- Tag the current commit with the new version number, e.g.
git tag v0.5.0 sbt publishSignedsbt sonaUpload- Go to https://central.sonatype.com/publishing/deployments and publish the deployment.
- or run
sbt sonaReleaseto publish the deployment automatically
- or run