Skip to content

Commit

Permalink
Extend skaffold debug integration tests to buildpacks (#4352)
Browse files Browse the repository at this point in the history
Extends integration tests to test `debug` with GCP Buildpacks using
both Procfiles and the new project.toml.
  • Loading branch information
briandealwis authored Jun 23, 2020
2 parents d18604e + e6bf12c commit 22135d7
Show file tree
Hide file tree
Showing 25 changed files with 171 additions and 65 deletions.
52 changes: 40 additions & 12 deletions integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ limitations under the License.
package integration

import (
"encoding/json"
"testing"
"time"

"github.com/GoogleContainerTools/skaffold/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/debug"
"github.com/GoogleContainerTools/skaffold/proto"
)

Expand All @@ -29,42 +31,68 @@ func TestDebug(t *testing.T) {

tests := []struct {
description string
dir string
config string
args []string
deployments []string
pods []string
}{
{
description: "kubectl",
dir: "testdata/debug",
deployments: []string{"jib"},
deployments: []string{"java"},
pods: []string{"nodejs", "npm", "python3", "go"},
},
{
description: "kustomize",
args: []string{"--profile", "kustomize"},
dir: "testdata/debug",
deployments: []string{"jib"},
deployments: []string{"java"},
pods: []string{"nodejs", "npm", "python3", "go"},
},
{
description: "buildpacks",
args: []string{"--profile", "buildpacks"},
deployments: []string{"java"},
pods: []string{"nodejs", "npm", "python3", "go"},
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
// Run skaffold build first to fail quickly on a build failure
skaffold.Build(test.args...).InDir(test.dir).RunOrFail(t)
skaffold.Build(test.args...).InDir("testdata/debug").RunOrFail(t)

ns, client := SetupNamespace(t)

skaffold.Debug(test.args...).InDir(test.dir).InNs(ns.Name).RunBackground(t)
skaffold.Debug(test.args...).InDir("testdata/debug").InNs(ns.Name).RunBackground(t)

verifyDebugAnnotations := func(annotations map[string]string) {
var configs map[string]debug.ContainerDebugConfiguration
if anno, found := annotations["debug.cloud.google.com/config"]; !found {
t.Errorf("deployment missing debug annotation: %v", annotations)
} else if err := json.Unmarshal([]byte(anno), &configs); err != nil {
t.Errorf("error unmarshalling debug annotation: %v: %v", anno, err)
} else {
for k, config := range configs {
if config.WorkingDir == "" {
t.Errorf("debug config for %q missing WorkingDir: %v: %v", k, anno, config)
}
if config.Runtime == "" {
t.Errorf("debug config for %q missing Runtime: %v: %v", k, anno, config)
}
}
}
}

for _, podName := range test.pods {
pod := client.GetPod(podName)

annotations := pod.Annotations
verifyDebugAnnotations(annotations)
}

client.WaitForPodsReady(test.pods...)
for _, depName := range test.deployments {
deploy := client.GetDeployment(depName)

annotations := deploy.Spec.Template.GetAnnotations()
if _, found := annotations["debug.cloud.google.com/config"]; !found {
t.Errorf("deployment missing debug annotation: %v", annotations)
}
verifyDebugAnnotations(annotations)
}
})
}
Expand Down Expand Up @@ -107,7 +135,7 @@ func waitForDebugEvent(t *testing.T, client *NSKubernetesClient, rpcAddr string)
for {
select {
case <-timeout:
t.Fatalf("timed out waiting for port debugging event")
t.Fatalf("timed out waiting for debugging event")
case entry := <-entries:
switch entry.Event.GetEventType().(type) {
case *proto.Event_DebuggingContainerEvent:
Expand Down
9 changes: 9 additions & 0 deletions integration/testdata/debug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Integration Tests for `skaffold debug`

These are a set of test projects for `skaffold debug`. There are two
configurations:

- `skaffold.yaml` configures docker- and jib-based builders
- `skaffold-bp.yaml` configures buildpacks-based builders

The test projects endeavour to support both docker or jib, and buildpacks.
1 change: 1 addition & 0 deletions integration/testdata/debug/go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN eval go build "${GOGCFLAGS}" -o /app .
FROM gcr.io/distroless/base
# `skaffold debug` uses GOTRACEBACK as an indicator of the Go runtime
ENV GOTRACEBACK=all
WORKDIR /
EXPOSE 8080
COPY --from=builder /app .
CMD ["/app"]
2 changes: 1 addition & 1 deletion integration/testdata/debug/go/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
}

func main() {
log.Print("example web app ready on port 8080")
log.Print("Go web app ready on port 8080")
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
2 changes: 1 addition & 1 deletion integration/testdata/debug/go/k8s/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: go
spec:
containers:
- name: web
- name: go-web
image: skaffold-debug-go
ports:
- containerPort: 8080
Expand Down
1 change: 1 addition & 0 deletions integration/testdata/debug/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: jib
name: java
spec:
selector:
matchLabels:
app: jibweb
app: javaweb
template:
metadata:
labels:
app: jibweb
app: javaweb
spec:
containers:
- name: web
image: skaffold-debug-jib
- name: java-web
image: skaffold-debug-java
ports:
- containerPort: 8080
# connect to the JDWP port
readinessProbe:
exec:
command: ["sh", "/check-jdwp.sh", "5005"]
command: ["sh", "/workspace/scripts/check-jdwp.sh", "5005"]
initialDelaySeconds: 2
periodSeconds: 10
# connect to the app port
Expand Down
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions integration/testdata/debug/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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-java</artifactId>
<version>0.1.0</version>
<description>Simple Java server with Skaffold and Jib</description>

<properties>
<jib.maven-plugin-version>2.4.0</jib.maven-plugin-version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<finalName>hello</finalName>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib.maven-plugin-version}</version>
<configuration>
<from>
<image>openjdk</image> <!-- has jdb -->
</from>
<container>
<jvmFlags>
<jvmFlag>-Djava.security.egd=file:/dev/./urandom</jvmFlag>
</jvmFlags>
<workingDirectory>/app</workingDirectory>
</container>
<extraDirectories>
<paths>
<path>
<from>scripts</from>
<into>/workspace/scripts</into>
</path>
</paths>
</extraDirectories>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>hello.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
36 changes: 0 additions & 36 deletions integration/testdata/debug/jib/pom.xml

This file was deleted.

2 changes: 1 addition & 1 deletion integration/testdata/debug/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resources:
- jib/k8s/web.yaml
- java/k8s/web.yaml
- nodejs/k8s/pod.yaml
- npm/k8s/pod.yaml
- python3/k8s/pod.yaml
Expand Down
1 change: 1 addition & 0 deletions integration/testdata/debug/nodejs/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node src/index.js
2 changes: 1 addition & 1 deletion integration/testdata/debug/nodejs/k8s/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: nodejs
spec:
containers:
- name: web
- name: nodejs-web
image: skaffold-debug-nodejs
ports:
- containerPort: 3000
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/debug/npm/k8s/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: npm
spec:
containers:
- name: web
- name: npm-web
image: skaffold-debug-npm
ports:
- containerPort: 3000
Expand Down
3 changes: 3 additions & 0 deletions integration/testdata/debug/npm/project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[build.env]]
name = "GOOGLE_ENTRYPOINT"
value = "npm start"
1 change: 1 addition & 0 deletions integration/testdata/debug/python3/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python3 app.py
2 changes: 1 addition & 1 deletion integration/testdata/debug/python3/k8s/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: python3
spec:
containers:
- name: web
- name: python3-web
image: skaffold-debug-python3
ports:
- containerPort: 5000
Expand Down
37 changes: 32 additions & 5 deletions integration/testdata/debug/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: skaffold/v2beta5
kind: Config
build:
artifacts:
- image: skaffold-debug-jib
context: jib
- image: skaffold-debug-java
context: java
jib:
args:
- --no-transfer-progress
Expand All @@ -22,13 +22,40 @@ build:
deploy:
kubectl:
manifests:
- jib/k8s/web.yaml
- java/k8s/web.yaml
- nodejs/k8s/pod.yaml
- npm/k8s/pod.yaml
- python3/k8s/pod.yaml
- go/k8s/pod.yaml

profiles:
- name: kustomize
deploy:
- name: kustomize
deploy:
kustomize: {}
kubectl: {}
# use GCP Buildpacks to build the individual projects
- name: buildpacks
build:
artifacts:
- image: skaffold-debug-java
context: java
buildpacks:
builder: "gcr.io/buildpacks/builder:v1"
- image: skaffold-debug-npm
context: npm
buildpacks:
builder: "gcr.io/buildpacks/builder:v1"
- image: skaffold-debug-nodejs
context: nodejs
buildpacks:
builder: "gcr.io/buildpacks/builder:v1"
- image: skaffold-debug-python3
context: python3
buildpacks:
builder: "gcr.io/buildpacks/builder:v1"
- image: skaffold-debug-go
context: go
buildpacks:
builder: "gcr.io/buildpacks/builder:v1"
env:
- GOOGLE_GCFLAGS="-gcflags='all=-N -l'"
12 changes: 12 additions & 0 deletions integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ func (k *NSKubernetesClient) WaitForPodsInPhase(expectedPhase v1.PodPhase, podNa
}
}

// GetDeployment gets a deployment by name.
func (k *NSKubernetesClient) GetPod(podName string) *v1.Pod {
k.t.Helper()
k.WaitForPodsReady(podName)

pod, err := k.Pods().Get(podName, metav1.GetOptions{})
if err != nil {
k.t.Fatalf("Could not find pod: %s in namespace %s", podName, k.ns)
}
return pod
}

// GetDeployment gets a deployment by name.
func (k *NSKubernetesClient) GetDeployment(depName string) *appsv1.Deployment {
k.t.Helper()
Expand Down

0 comments on commit 22135d7

Please sign in to comment.