> **Warning** This SDK is experimental. Please do not use it for anything
> mission-critical. Possible issues include:
- Missing features
- Stability issues
- Performance issues
- Lack of polish
- Upcoming breaking changes
- Incomplete or out-of-date documentation
> **Warning**
> The Dagger Java SDK requires Dagger v0.9.0 or later
# dagger-java-sdk
![main workflow](https://github.com/dagger/dagger/actions/workflows/test.yml/badge.svg?branch=main)
A [Dagger.io](https://dagger.io) SDK written in Java.
## Build
### Requirements
- Java 17+
### Build
Simply run maven to build the jars, run all tests (unit and integration) and install them in your
local `${HOME}/.m2` repository
```bash
./mvnw clean install
```
### Troubleshoot generated code
To inspect the code that gets generated, run:
```bash
./mvnw package
```
The generated code will exist under
`sdk/java/dagger-java-sdk/target/generated-sources/dagger/io/dagger/client`.
### Javadoc
To generate the Javadoc (site and jar), use the `javadoc` profile.
The javadoc are built in `./dagger-java-sdk/target/apidocs/index.html`
```bash
./mvnw package -Pjavadoc
```
## Usage
in your project's `pom.xml` add the dependency
```xml
<dependency>
<groupId>io.dagger</groupId>
<artifactId>dagger-java-sdk</artifactId>
<version>0.6.2-SNAPSHOT</version>
</dependency>
```
Here is a code snippet using the Dagger client
```java
package io.dagger.sample;
import io.dagger.client.Client;
import io.dagger.client.Dagger;
import java.util.List;
public class GetDaggerWebsite {
public static void main(String... args) throws Exception {
try (Client client = Dagger.connect()) {
String output = client.pipeline("test")
.container()
.from("alpine")
.withExec(List.of("apk", "add", "curl"))
.withExec(List.of("curl", "https://dagger.io"))
.stdout();
System.out.println(output.substring(0, 300));
}
}
}
```
### Run sample code snippets
The `dagger-java-samples` module contains code samples.
Run the samples with this command:
```bash
# Build the packages and run the samples
./mvnw package -Prun-samples
```
Then select the sample to run:
```
=== Dagger.io Java SDK samples ===
1 io.dagger.sample.RunContainer Run a binary in a container
2 io.dagger.sample.GetDaggerWebsite Fetch the Dagger website content and print the first 300 characters
3 io.dagger.sample.ListEnvVars List container environment variables
4 io.dagger.sample.MountHostDirectoryInContainer Mount a host directory in container
5 io.dagger.sample.ListHostDirectoryContents List the files and directories from the host working dir in a container
6 io.dagger.sample.ReadFileInGitRepository Clone the Dagger git repository and print the first line of README.md
7 io.dagger.sample.PublishImage Publish a container image to a remote registry
8 io.dagger.sample.BuildFromDockerfile Clone the Dagger git repository and build from a Dockerfile
9 io.dagger.sample.CreateAndUseSecret Create a secret with a Github token and call a Github API using this secret
10 io.dagger.sample.TestWithDatabase Run a sample CI test pipeline with MariaDB, Drupal and PHPUnit
11 io.dagger.sample.HostToContainerNetworking Expose a service from a container to the host
12 io.dagger.sample.ContainerToHostNetworking Expose MySQL service running on the host to client containers
q exit
Select sample:
```
### Run pipeline with Dagger CLI
To run a Java pipeline, the Java SDK is needed as a JAR file containing all dependencies.
This self-contained JAR file can be built with this command:
```bash
./mvnw clean package -Pbigjar,release
```
To run a sample, the classpath has to contain the Java SDK JAR file and the samples JAR file.
The following command uses the Dagger CLI to start the ListEnvVars sample:
```bash
dagger run java -cp dagger-java-sdk/target/dagger-java-sdk-1.0.0-SNAPSHOT-jar-with-dependencies.jar:dagger-java-samples/target/dagger-java-samples-1.0.0-SNAPSHOT.jar io.dagger.sample.ListEnvVars
```
**Warning**: It may happen that the pipeline does not terminate after the execution of the sample code.
## Customizing the code generation
It is possible to change the dagger version targeted by the SDK by setting the maven
property `daggerengine.version`.
```shell
# Build the SDK for Dagger 0.8.1
./mvnw package -Ddaggerengine.version=0.8.1
```
> **Warning**
> If the targeted version mismatches the actual CLI version, the code generation will fail
By setting the variable to the special `local` value (or the alias `devel`), it is possible to query
a dagger CLI to generate the API schema.
It is also possible to specify the Dagger CLI binary to use to generate the schema...
Either by setting the `_EXPERIMENTAL_DAGGER_CLI_BIN` environment variable
```shell
# Build the SDK for a specific Dagger CLI
_EXPERIMENTAL_DAGGER_CLI_BIN=/path/to/dagger ./mvnw package -Ddaggerengine.version=local
```
or by setting the maven property `dagger.bin`
```shell
# Build the SDK for a specific Dagger CLI
./mvnw package -Ddaggerengine.version=local -Ddagger.bin=/path/to/dagger
```
## Upgrade to a new Dagger Engine version
In order to upgrade the SDK to a new engine version follow these steps:
1. Download the new dagger CLI (or install it via the package manager of your choice)
2. Bump dagger engine dependency by updating the `daggerengine.version` property
in `sdk/java/pom.xml` file
3. Generate the API schema for the new engine and copy it
the `dagger-codegen-maven-plugin/src/main/resources/schemas` directory
```shell
# in sdk/java directory
./mvnw install -pl dagger-codegen-maven-plugin
./mvnw -N dagger-codegen:generateSchema -Ddagger.bin=/path/to/dagger/bin
NEW_VERSION=$(./mvnw help:evaluate -q -DforceStdout -Dexpression=daggerengine.version)
cp ./target/generated-schema/schema.json dagger-codegen-maven-plugin/src/main/resources/schemas/schema-$NEW_VERSION.json
```
## Test without building
For those who would like to test without having to build the SDK:
1. Go to the workflows on the main
branch: https://github.com/jcsirot/dagger-java-sdk/actions?query=branch%3Amain
2. Click on the most recent executed workflow
3. Scroll down to the bottom of the page and download the `jar-with-dependencies` artifact
> **Warning**
> It is a zip file. Unzip it to retrieve the jar file.
4. Compile and run your sample pipeline with this jar file in the classpath
```bash
# Compile
javac -cp dagger-java-sdk-[version]-jar-with-dependencies.jar GetDaggerWebsite.java
# Run
java -cp dagger-java-sdk-[version]-jar-with-dependencies.jar:. GetDaggerWebsite
```
5. Enjoy ����
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
可编程的CI/CD引擎:一个可编程的CI/CD引擎,旨在让持续集成和持续交付过程更加灵活和高效 (1973个子文件)
BUILDKIT_AUTHORS 1KB
BUILDKIT_AUTHORS 1KB
.eslintrc-docs.cjs 403B
.eslintrc.cjs 340B
.prettierrc.cjs 279B
.eslintrc.cjs 98B
mvnw.cmd 8KB
codegen 621B
CODEOWNERS 120B
LaravelExample.cs 4KB
IntrospectionQuery.cs 2KB
Serializer.cs 2KB
Program.cs 1KB
BasicConnect.cs 1KB
GraphQLClient.cs 898B
ContainerBuilder.cs 729B
Container.cs 456B
From.cs 430B
QueryType.cs 427B
WithExec.cs 416B
GraphQLElement.cs 409B
QueryField.cs 322B
QueryDirective.cs 241B
EnumType.cs 238B
InputField.cs 234B
QueryArg.cs 233B
TypeDef.cs 180B
ArgType.cs 180B
GraphQLQuery.cs 123B
Usings.cs 29B
IntegrationTests.csproj 709B
DaggerSDKCodeGen.csproj 337B
DaggerSDK.csproj 209B
spectaql.min.css 11KB
App.css 564B
App.css 564B
App.css 564B
App.css 564B
App.css 564B
App.css 564B
App.css 564B
App.css 564B
index.css 366B
index.css 366B
index.css 366B
index.css 366B
index.css 366B
index.css 366B
index.css 366B
index.css 366B
dev 501B
phpunit.xml.dist 709B
DNSNAME_AUTHORS 640B
Dockerfile 2KB
dev.Dockerfile 1KB
Dockerfile 187B
dockerignore 21B
.dockerignore 16B
.envrc 286B
.envrc 213B
container.ex 53KB
client.ex 28KB
object_tmpl.ex 14KB
directory.ex 14KB
module_source.ex 10KB
module.ex 9KB
type_def.ex 8KB
host.ex 5KB
service.ex 4KB
downloader.ex 4KB
function.ex 4KB
query_builder.ex 4KB
object_type_def.ex 4KB
current_module.ex 3KB
file.ex 3KB
function_call.ex 3KB
function.ex 3KB
git_module_source.ex 3KB
module_ref.ex 3KB
generated_code.ex 2KB
engine_conn.ex 2KB
interface_type_def.ex 2KB
git_repository.ex 2KB
project_command.ex 2KB
module_config.ex 2KB
git_module_ref.ex 2KB
type_def_kind.ex 2KB
input_type_def.ex 2KB
function_arg.ex 2KB
git_ref.ex 2KB
session.ex 2KB
project.ex 2KB
local_module_source.ex 2KB
field_type_def.ex 2KB
port.ex 2KB
client.ex 2KB
module.ex 1KB
enum_tmpl.ex 1KB
compiler.ex 1KB
input_tmpl.ex 1KB
共 1973 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
UnknownToKnown
- 粉丝: 1w+
- 资源: 773
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Java项目开发的架构设计.pptx
- 사다리 타기 구현을 위한 저장소.zip
- 用户权限控制demo项目
- 图书馆座位预约小程序源码(云开发项目高分期末大作业)
- jlink驱动v924
- c++ WebSocketServer 测试demo
- 水稻植物病害数据集 水稻常见叶部病害 4684张图片
- (跨平台)Java 版本管理器.zip
- 全国37个农业熟制区划-Shp文件+Excel文档
- 使用Python高级技巧绘制动态爱心图案
- 聚合支付系统官方个人免签系统三方支付系统稳定安全高并发
- 【PHP毕业设计】 php+mysql学生成绩查询(系统).zip
- 【PHP毕业设计】 php+mysql社区交流系统(毕业论文+封面目录+系统+说明书).zip
- 【PHP毕业设计】 php+mysql学生成绩查询系统(源代码+论文).zip
- mpc-0.8.tar.gz
- Wave-Analyze-Installer-1.3.8.2117593
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功