Merge pull request #751 from Alvise88/add-initial-maven-support

This commit is contained in:
Andrea Luzzardi 2021-06-29 18:39:58 +02:00 committed by GitHub
commit 0ba7c1fb44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 280 additions and 0 deletions

View File

@ -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

View File

@ -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 |

View File

@ -0,0 +1,2 @@
# dagger state
state/**

View File

@ -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: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSB3VURHb25rcVdWRmMyWmVk
c0t4MEZscDdMWEdqMWNPRm0zRG91cnh4cnlvCllCYy9nS2F0ejZFQXBLZzgxU29n
V0tEcEJkQUFzdHczV3MrQjFpUHMzT1kKLS0tIFJvY2QvUjJlRE9hTTJWa1NkK2l4
UjFhYnZNdUxBNEtzWkVvMUoweUFnREEKbs/IGlNmDk8e3ibJSoIcE95txghXwsso
DL281EMf0V+ARsJY2CiehZsZB+xX7y+YfyQyoWx0xMN7bCgPu2snGg==
-----END AGE ENCRYPTED FILE-----
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

View File

@ -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: "/"
copy: "/": from: source
}
}

View File

@ -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"
"""
}
}

View File

@ -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/

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.dagger.maven</groupId>
<artifactId>spring-boot-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-test</name>
<description>Dagger maven spring boot test</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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() {
}
}

View File

@ -21,6 +21,10 @@ setup() {
dagger -e js-yarn up
}
@test "java/maven" {
dagger -e java-maven up
}
@test "alpine" {
dagger -e alpine up
}