As Alibaba/Aliyun Function Compute updated a lot of features since I implemented the first version of this gradle plugin, such as definding bootstrap command inside s.yaml template file and extend template files, this plugin is eventually become outdated.
So, there will be no more update. Please migrate to the offical cli tool maintained by Alibaba/Aliyun team: @serverless-devs/s.
This is a gradle plugin used to automatically compress your bootJar with a bootstrap file into a zip.
After applying this plugin, it will try to search bootstrap files under ${PROJECT_DIR}
and ${PROJECT_DIR}/bootstrap
dir.
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "dev.dengchao:fc-custom-runtime-packer:x.y.z" // replace x.y.z with actual version of this plugin
}
}
version 'your-project-version'
// This plugin MUST be applied below version field.
apply plugin: "dev.dengchao.fc-custom-runtime-packer"
Let's assume you have a spring project like below:
project dir
+--- bootstrap
| +--- bootstrap-pro (1)
| \--- dev (2)
+--- build
+--- src
+--- bootstrap.sh (3)
+--- build.gradle (plugin applyed)
After run gradle :zipBootstrap
, there will be a regular bootJar, three profile-ed bootstrap zip:
project dir
+...
+--- build
| \--- libs
| +--- demo-1.0.0.jar (bootJar)
| +--- demo-1.0.0-default.zip
| | +--- bootstrap (generated from 3)
| | \--- demo-1.0.0.jar
| +--- demo-1.0.0-dev.zip
| | +--- bootstrap (generated from 2)
| | \--- demo-1.0.0.jar
| \--- demo-1.0.0-pro.zip
| +--- bootstrap (generated from 1)
| \--- demo-1.0.0.jar
+...
More additionally, you can run gradle :zipBootstrapDefault
to package default profile only, so does other profiles.
- It's content MAY have one or more place holder
archive
orboot.jar
, which will be replaced by actual bootJar name in generated bootstrap file. eg:java -jar archive
will resultjava -jar demo-1.0.0.jar
- See [ReplacePlaceHolderContentInterceptor]1 for more details.
- If it is placed under project dir like (3), its name MUST match regex expression
bootstrap(-[a-zA-Z0-9\-]+)?(\.sh)?
- If a profile
(-[a-zA-Z0-9\-]+)
is present, it will result a${PROJECT_NAME}-${PROJECT_VERSION}-${PROFILE}.zip
zip. - If the profile is not present, it will result a
${PROJECT_NAME}-${PROJECT_VERSION}-default.zip
zip. - See [ProjectDirBootstrapCollector]2 for more details.
- If a profile
- If it is placed under bootstrap dir like (1) and (2), its name MUST match regex expression
([a-zA-Z0-9\-]+)(\.sh)?
- If a 'bootstrap-' prefix is present, it will be removed from profile.
- See [BootstrapDirBootstrapCollector]3 for more details.
- It's content MAY have announced its [shebang command][^Shebang @wikipedia.org]. Accepted values are
#!/bin/bash
and#!/usr/bin/env sh
.- If it is missing or having an invalid shebang command,
#!/bin/bash
will be prepend into generated bootstrap. - See [ShebangInterceptor]4 for more details.
- If it is missing or having an invalid shebang command,
- It MAY have granted the execution permission.
- As the bootstrap inside the zip file is a generated file, not the original one, so the execution permission the original file have is ignored, and the generated one's [file mode][^Unix file mode] is setting to 775.
- See [ZipBootstrap]5 for more details.
- If there are more than one bootstrap files having the same profile,
a [DuplicateBootstrapProfileException]6 will be thrown when running.
- See [ProjectBootstrapCollector]7 for more details.
Please PR to master branch.
If you want to perform integrate test on demo
module with your modifications,
just run gradle :fc-custom-runtime-packer:publishToMavenLocal
.
Spring boot gradle plugin @github.com
How to get project version in custom gradle plugin @stackoverflow.com
Footnotes
-
fc-custom-runtime-packer/src/main/java/dev/dengchao/content/interceptor/ReplacePlaceHolderContentInterceptor.java ↩
-
fc-custom-runtime-packer/src/main/java/dev/dengchao/bootstrap/collector/ProjectDirBootstrapCollector.java ↩
-
fc-custom-runtime-packer/src/main/java/dev/dengchao/bootstrap/collector/BootstrapDirBootstrapCollector.java ↩
-
fc-custom-runtime-packer/src/main/java/dev/dengchao/content/interceptor/ShebangInterceptor.java ↩
-
fc-custom-runtime-packer/src/main/java/dev/dengchao/ZipBootstrap.java [^Unix file mode]:https://www.tutorialspoint.com/unix/unix-file-permission.htm ↩
-
fc-custom-runtime-packer/src/main/java/dev/dengchao/bootstrap/collector/DuplicateBootstrapProfileException.java ↩
-
fc-custom-runtime-packer/src/main/java/dev/dengchao/bootstrap/collector/ProjectBootstrapCollector.java [^Shebang @wikipedia.org]:https://en.wikipedia.org/wiki/Shebang_(Unix) ↩