Skip to content

Commit

Permalink
skaffold init supports Java/Buildpacks projects (#4318)
Browse files Browse the repository at this point in the history
* `skaffold init` supports Java/Buildpacks projects

Signed-off-by: David Gageot <david@gageot.net>

* Test all buildpacks samples

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jun 17, 2020
1 parent 6f2e834 commit 92667f1
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 7 deletions.
7 changes: 7 additions & 0 deletions integration/examples/buildpacks-java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Example: buildpacks (Java)

This is an example demonstrating:

* **building** a Java app built with [Cloud Native Buildpacks](https://buildpacks.io/)
* **tagging** using the default tagPolicy (`gitCommit`)
* **deploying** a single container pod using `kubectl`
30 changes: 30 additions & 0 deletions integration/examples/buildpacks-java/k8s/web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: Service
metadata:
name: web
spec:
ports:
- port: 8080
name: http
type: LoadBalancer
selector:
app: web
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: skaffold-buildpacks
ports:
- containerPort: 8080
36 changes: 36 additions & 0 deletions integration/examples/buildpacks-java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.skaffold</groupId>
<artifactId>hello-spring-boot</artifactId>
<version>0.1.0</version>
<description>Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<finalName>hello</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
15 changes: 15 additions & 0 deletions integration/examples/buildpacks-java/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: skaffold/v2beta5
kind: Config
build:
artifacts:
- image: skaffold-buildpacks
buildpacks:
builder: "gcr.io/buildpacks/builder:v1"
env:
- GOOGLE_RUNTIME_VERSION=8
sync:
auto: {}
profiles:
- name: gcb
build:
googleCloudBuild: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hello;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Hello, World!";
}
}
17 changes: 16 additions & 1 deletion integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,25 @@ func TestRun(t *testing.T) {
pods: []string{"getting-started"},
},
{
description: "buildpacks",
description: "buildpacks Go",
dir: "examples/buildpacks",
deployments: []string{"web"},
},
{
description: "buildpacks NodeJS",
dir: "examples/buildpacks-node",
deployments: []string{"web"},
},
{
description: "buildpacks Python",
dir: "examples/buildpacks-python",
deployments: []string{"web"},
},
{
description: "buildpacks Java",
dir: "examples/buildpacks-java",
deployments: []string{"web"},
},
{
description: "kustomize",
dir: "examples/getting-started-kustomize",
Expand Down
15 changes: 9 additions & 6 deletions pkg/skaffold/build/buildpacks/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,27 @@ func (c ArtifactConfig) Path() string {
func validate(path string) bool {
valid := false

file := filepath.Base(path)
switch {
switch filepath.Base(path) {
// Buildpacks project descriptor.
case file == "project.toml":
case "project.toml":
valid = true

// NodeJS.
case file == "package.json":
case "package.json":
valid = true

// Go.
case file == "go.mod":
case "go.mod":
valid = true

// Java.
case "pom.xml", "build.gradle", "build.gradle.kts":
valid = true

// Python.
// TODO(dgageot): When the Procfile is missing, we might want to inform the user
// that this still might be a valid python project.
case file == "requirements.txt":
case "requirements.txt":
if _, err := os.Stat(filepath.Join(filepath.Dir(path), "Procfile")); err == nil {
valid = true
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/skaffold/build/buildpacks/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ func TestValidate(t *testing.T) {
},
expectedValid: true,
},
{
description: "Java Maven",
path: filepath.Join("path", "to", "pom.xml"),
expectedValid: true,
},
{
description: "Java Gradle",
path: filepath.Join("path", "to", "build.gradle"),
expectedValid: true,
},
{
description: "Java Gradle Kotlin",
path: filepath.Join("path", "to", "build.gradle.kts"),
expectedValid: true,
},
{
description: "Buildpacks",
path: "project.toml",
Expand Down

0 comments on commit 92667f1

Please sign in to comment.