From f807314668892aee276b93c68cabf51eb4482958 Mon Sep 17 00:00:00 2001 From: Alvise Date: Tue, 29 Jun 2021 10:11:57 +0000 Subject: [PATCH 1/3] Add maven package in stdlib Signed-off-by: Alvise --- docs/reference/universe/README.md | 1 + docs/reference/universe/java/maven.md | 32 +++++++++ stdlib/.dagger/env/java-maven/.gitignore | 2 + stdlib/.dagger/env/java-maven/values.yaml | 28 ++++++++ stdlib/java/maven/maven.cue | 69 +++++++++++++++++++ stdlib/java/maven/tests/maven.cue | 43 ++++++++++++ stdlib/java/maven/tests/testdata/.gitignore | 33 +++++++++ stdlib/java/maven/tests/testdata/pom.xml | 41 +++++++++++ .../SpringBootTestApplication.java | 13 ++++ .../src/main/resources/application.properties | 1 + .../SpringBootTestApplicationTests.java | 13 ++++ stdlib/universe.bats | 4 ++ 12 files changed, 280 insertions(+) create mode 100644 docs/reference/universe/java/maven.md create mode 100644 stdlib/.dagger/env/java-maven/.gitignore create mode 100644 stdlib/.dagger/env/java-maven/values.yaml create mode 100644 stdlib/java/maven/maven.cue create mode 100644 stdlib/java/maven/tests/maven.cue create mode 100644 stdlib/java/maven/tests/testdata/.gitignore create mode 100644 stdlib/java/maven/tests/testdata/pom.xml create mode 100644 stdlib/java/maven/tests/testdata/src/main/java/io/dagger/maven/springboottest/SpringBootTestApplication.java create mode 100644 stdlib/java/maven/tests/testdata/src/main/resources/application.properties create mode 100644 stdlib/java/maven/tests/testdata/src/test/java/io/dagger/maven/springboottest/SpringBootTestApplicationTests.java diff --git a/docs/reference/universe/README.md b/docs/reference/universe/README.md index 27fbc85b..6dd66572 100644 --- a/docs/reference/universe/README.md +++ b/docs/reference/universe/README.md @@ -19,6 +19,7 @@ - [git](./git.md) - Git operations - [go](./go.md) - Go build operations - [io](./io.md) - IO operations +- [java/maven](./java/maven.md) - Maven is a build automation tool for Java - [js/yarn](./js/yarn.md) - Yarn is a package manager for Javascript applications - [kubernetes](./kubernetes/README.md) - Kubernetes client operations - [kubernetes/helm](./kubernetes/helm.md) - Helm package manager diff --git a/docs/reference/universe/java/maven.md b/docs/reference/universe/java/maven.md new file mode 100644 index 00000000..17387563 --- /dev/null +++ b/docs/reference/universe/java/maven.md @@ -0,0 +1,32 @@ +--- +sidebar_label: maven +--- + +# alpha.dagger.io/java/maven + +Maven is a build automation tool for Java + +```cue +import "alpha.dagger.io/java/maven" +``` + +## maven.#Project + +A Maven project + +### maven.#Project Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*source* | `dagger.#Artifact` |Application source code | +|*package* | `struct` |Extra alpine packages to install | +|*env* | `struct` |Environment variables | +|*phases* | `*["package"] \| []` |- | +|*goals* | `*[] \| []` |- | +|*args* | `*[] \| []` |Optional arguments for the script | + +### maven.#Project Outputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*build* | `struct` |Build output directory | diff --git a/stdlib/.dagger/env/java-maven/.gitignore b/stdlib/.dagger/env/java-maven/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/java-maven/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/java-maven/values.yaml b/stdlib/.dagger/env/java-maven/values.yaml new file mode 100644 index 00000000..c1c88b39 --- /dev/null +++ b/stdlib/.dagger/env/java-maven/values.yaml @@ -0,0 +1,28 @@ +plan: + module: ./java/maven + package: ./tests +name: java-maven +inputs: + TestData: + dir: + path: ./java/maven/tests/testdata +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1frg88gugx9ynthc66rcld7k5frtcddjehz4aw5k0wmntkd9pgsxs2vj5xe + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA4dWpSS2djbldQTzZQQ3kz + VUt2OU9zaVpCZHREa2plRDJsNFRaeVNOWmdVCnVqOVFZR2pJNXB4bThSUjBYTDZy + WWIzaWp3UTk2d0ErSFAzcHNYK3FRQ2cKLS0tIDhZWjVZZGFvbHVzN2FmTno3QzFx + WWV2Zjhra3AyenBKTVBoV3lNYVVTVWMKZQWIThYlZBEJKn62tGl7g3GkK4UqEfLF + NsY3h5vkK0ScE4DctWS4uSdL8tgfy40W/TyZpjRd2uHnSJkpbf/Amg== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-28T07:24:04Z" + mac: ENC[AES256_GCM,data:c70mmWYksMLoDf0Ok+fXz0QYot/x4UTptsrAfgaMJ8Zba50OuvDhashvSfngtmzoXV0wYH0OK7uk0+JwIPV/6dC+6/qOw66Zpt1AF6fZ6FjayNXsdwuyzrG+ykYNS5PmlNm+U54CmGkCG/NdJ33dC1sfEzX6giL5cgSsjXA7FJw=,iv:sEFBzWFvjmR7czlAeNyKpB7uXgL6TBi+9t67Bn5xL/0=,tag:cGBLLp0BOQHZerbdvF/y0g==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/java/maven/maven.cue b/stdlib/java/maven/maven.cue new file mode 100644 index 00000000..d86a6748 --- /dev/null +++ b/stdlib/java/maven/maven.cue @@ -0,0 +1,69 @@ +// Maven is a build automation tool for Java +package maven + +import ( + "strings" + + "alpha.dagger.io/dagger" + "alpha.dagger.io/alpine" + "alpha.dagger.io/os" +) + +// A Maven project +#Project: { + + // Application source code + source: dagger.#Artifact @dagger(input) + + // Extra alpine packages to install + package: { + [string]: true | false | string + } @dagger(input) + + // Environment variables + env: { + [string]: string + } @dagger(input) + + phases: [...string] | *["package"] @dagger(input) + goals: [...string] | *[] @dagger(input) + + // Optional arguments for the script + args: [...string] | *[] @dagger(input) + + // Build output directory + build: os.#Dir & { + from: ctr + path: "/build" + } @dagger(output) + + ctr: os.#Container & { + image: alpine.#Image & { + "package": package & { + bash: "=~5.1" + openjdk11: "=~11.0.9" + maven: "=~3.6.3" + } + } + shell: path: "/bin/bash" + command: """ + opts=( $(echo $MAVEN_ARGS) ) + mvn $MAVEN_GOALS $MAVEN_PHASES ${opts[@]} + result=$? + modules=$(mvn -Dexec.executable='pwd' -Dexec.args='${project.artifactId}' exec:exec -q) + for module in $modules;do + source=$(echo "$module/target" | tr -s /) + target=$(echo "/build/$module" | tr -s /) + mkdir -p $target;cp -a $source $target 2>/dev/null || : + done + exit $result + """ + "env": env & { + MAVEN_ARGS: strings.Join(args, "\n") + MAVEN_PHASES: strings.Join(phases, "\n") + MAVEN_GOALS: strings.Join(goals, "\n") + } + dir: "/" + mount: "/": from: source + } +} diff --git a/stdlib/java/maven/tests/maven.cue b/stdlib/java/maven/tests/maven.cue new file mode 100644 index 00000000..39bbb411 --- /dev/null +++ b/stdlib/java/maven/tests/maven.cue @@ -0,0 +1,43 @@ +package maven + +import ( + "strings" + + "alpha.dagger.io/dagger" + "alpha.dagger.io/alpine" + "alpha.dagger.io/os" +) + +TestData: dagger.#Artifact + +TestConfig: mavenOpts: strings.Join([ + "-client", + "-XX:+TieredCompilation", + "-XX:TieredStopAtLevel=1", + "-Xverify:none", + "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dorg.slf4j.simpleLogger.showDateTime=true", + "-Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss", +], " ") + +TestSpringBoot: { + project: #Project & { + source: TestData + + phases: ["install"] + + env: MAVEN_OPTS: TestConfig.mavenOpts + + args: ["--batch-mode"] + } + + test: os.#Container & { + image: alpine.#Image & { + package: bash: "=5.1.0-r0" + } + copy: "/build": from: project.build + command: """ + count=$(ls -1 /build/**/*.jar 2>/dev/null | wc -l) + test "$count" != "0" + """ + } +} diff --git a/stdlib/java/maven/tests/testdata/.gitignore b/stdlib/java/maven/tests/testdata/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/stdlib/java/maven/tests/testdata/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/stdlib/java/maven/tests/testdata/pom.xml b/stdlib/java/maven/tests/testdata/pom.xml new file mode 100644 index 00000000..a4516bed --- /dev/null +++ b/stdlib/java/maven/tests/testdata/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.2 + + + io.dagger.maven + spring-boot-test + 0.0.1-SNAPSHOT + spring-boot-test + Dagger maven spring boot test + + 11 + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/stdlib/java/maven/tests/testdata/src/main/java/io/dagger/maven/springboottest/SpringBootTestApplication.java b/stdlib/java/maven/tests/testdata/src/main/java/io/dagger/maven/springboottest/SpringBootTestApplication.java new file mode 100644 index 00000000..68b09e3e --- /dev/null +++ b/stdlib/java/maven/tests/testdata/src/main/java/io/dagger/maven/springboottest/SpringBootTestApplication.java @@ -0,0 +1,13 @@ +package io.dagger.maven.springboottest; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootTestApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootTestApplication.class, args); + } + +} diff --git a/stdlib/java/maven/tests/testdata/src/main/resources/application.properties b/stdlib/java/maven/tests/testdata/src/main/resources/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/stdlib/java/maven/tests/testdata/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/stdlib/java/maven/tests/testdata/src/test/java/io/dagger/maven/springboottest/SpringBootTestApplicationTests.java b/stdlib/java/maven/tests/testdata/src/test/java/io/dagger/maven/springboottest/SpringBootTestApplicationTests.java new file mode 100644 index 00000000..6419b115 --- /dev/null +++ b/stdlib/java/maven/tests/testdata/src/test/java/io/dagger/maven/springboottest/SpringBootTestApplicationTests.java @@ -0,0 +1,13 @@ +package io.dagger.maven.springboottest; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringBootTestApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/stdlib/universe.bats b/stdlib/universe.bats index 7d51ebb1..bc20eb85 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -21,6 +21,10 @@ setup() { dagger -e js-yarn up } +@test "java/maven" { + dagger -e java-maven up +} + @test "alpine" { dagger -e alpine up } From 6690aa411ebf4662393544ef259f4fd553cd9f23 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Tue, 29 Jun 2021 18:10:34 +0200 Subject: [PATCH 2/3] tests: java-maven: use dagger-ci encryption key Signed-off-by: Andrea Luzzardi --- stdlib/.dagger/env/java-maven/values.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/.dagger/env/java-maven/values.yaml b/stdlib/.dagger/env/java-maven/values.yaml index c1c88b39..d2155462 100644 --- a/stdlib/.dagger/env/java-maven/values.yaml +++ b/stdlib/.dagger/env/java-maven/values.yaml @@ -12,17 +12,17 @@ sops: azure_kv: [] hc_vault: [] age: - - recipient: age1frg88gugx9ynthc66rcld7k5frtcddjehz4aw5k0wmntkd9pgsxs2vj5xe + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk enc: | -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA4dWpSS2djbldQTzZQQ3kz - VUt2OU9zaVpCZHREa2plRDJsNFRaeVNOWmdVCnVqOVFZR2pJNXB4bThSUjBYTDZy - WWIzaWp3UTk2d0ErSFAzcHNYK3FRQ2cKLS0tIDhZWjVZZGFvbHVzN2FmTno3QzFx - WWV2Zjhra3AyenBKTVBoV3lNYVVTVWMKZQWIThYlZBEJKn62tGl7g3GkK4UqEfLF - NsY3h5vkK0ScE4DctWS4uSdL8tgfy40W/TyZpjRd2uHnSJkpbf/Amg== + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSB3VURHb25rcVdWRmMyWmVk + c0t4MEZscDdMWEdqMWNPRm0zRG91cnh4cnlvCllCYy9nS2F0ejZFQXBLZzgxU29n + V0tEcEJkQUFzdHczV3MrQjFpUHMzT1kKLS0tIFJvY2QvUjJlRE9hTTJWa1NkK2l4 + UjFhYnZNdUxBNEtzWkVvMUoweUFnREEKbs/IGlNmDk8e3ibJSoIcE95txghXwsso + DL281EMf0V+ARsJY2CiehZsZB+xX7y+YfyQyoWx0xMN7bCgPu2snGg== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-28T07:24:04Z" - mac: ENC[AES256_GCM,data:c70mmWYksMLoDf0Ok+fXz0QYot/x4UTptsrAfgaMJ8Zba50OuvDhashvSfngtmzoXV0wYH0OK7uk0+JwIPV/6dC+6/qOw66Zpt1AF6fZ6FjayNXsdwuyzrG+ykYNS5PmlNm+U54CmGkCG/NdJ33dC1sfEzX6giL5cgSsjXA7FJw=,iv:sEFBzWFvjmR7czlAeNyKpB7uXgL6TBi+9t67Bn5xL/0=,tag:cGBLLp0BOQHZerbdvF/y0g==,type:str] + lastmodified: "2021-06-29T16:06:47Z" + mac: ENC[AES256_GCM,data:DudrYOLr/ymf10B4UzjRfe1+n/hw7KCSSIbzAGcc3kmN/KplkCPYi3n5HCX1XkMOB1mQp9QD+UOQGL5CYPtqnZZKu62JNfbeSqU26BKU97aqL0F2+lPqaYsjSeCAbgUs9O/30A7QErlJiXuzTYC1WcTjpTr0RTeNoHmWKsqZ5ug=,iv:7e1XmOfxyKIOguzDxqQ75nFnV3GZ1vpvz5S5P1O+4Xo=,tag:f6Vb8e721uLyvLfCwE/JEg==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 From 7776e6def35f659d242ae9b84e1013eb0350e66c Mon Sep 17 00:00:00 2001 From: Alvise Date: Tue, 29 Jun 2021 16:26:31 +0000 Subject: [PATCH 3/3] Check if problem is linked with docker from docker Signed-off-by: Alvise --- stdlib/java/maven/maven.cue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/java/maven/maven.cue b/stdlib/java/maven/maven.cue index d86a6748..0cdf3cab 100644 --- a/stdlib/java/maven/maven.cue +++ b/stdlib/java/maven/maven.cue @@ -64,6 +64,6 @@ import ( MAVEN_GOALS: strings.Join(goals, "\n") } dir: "/" - mount: "/": from: source + copy: "/": from: source } }