diff --git a/integration/debug_test.go b/integration/debug_test.go index 38590d8d7ba..c38923a9a7d 100644 --- a/integration/debug_test.go +++ b/integration/debug_test.go @@ -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" ) @@ -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) } }) } @@ -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: diff --git a/integration/testdata/debug/README.md b/integration/testdata/debug/README.md new file mode 100644 index 00000000000..bd3239477b1 --- /dev/null +++ b/integration/testdata/debug/README.md @@ -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. diff --git a/integration/testdata/debug/go/Dockerfile b/integration/testdata/debug/go/Dockerfile index 955d2d8c268..d1a4d643a1a 100644 --- a/integration/testdata/debug/go/Dockerfile +++ b/integration/testdata/debug/go/Dockerfile @@ -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"] diff --git a/integration/testdata/debug/go/app.go b/integration/testdata/debug/go/app.go index 01902f4087d..45f0cbadbb7 100644 --- a/integration/testdata/debug/go/app.go +++ b/integration/testdata/debug/go/app.go @@ -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) } diff --git a/integration/testdata/debug/go/k8s/pod.yaml b/integration/testdata/debug/go/k8s/pod.yaml index c16417a11b3..bd76261649e 100644 --- a/integration/testdata/debug/go/k8s/pod.yaml +++ b/integration/testdata/debug/go/k8s/pod.yaml @@ -4,7 +4,7 @@ metadata: name: go spec: containers: - - name: web + - name: go-web image: skaffold-debug-go ports: - containerPort: 8080 diff --git a/integration/testdata/debug/java/.gitignore b/integration/testdata/debug/java/.gitignore new file mode 100644 index 00000000000..eb5a316cbd1 --- /dev/null +++ b/integration/testdata/debug/java/.gitignore @@ -0,0 +1 @@ +target diff --git a/integration/testdata/debug/jib/.mvn/wrapper/MavenWrapperDownloader.java b/integration/testdata/debug/java/.mvn/wrapper/MavenWrapperDownloader.java similarity index 100% rename from integration/testdata/debug/jib/.mvn/wrapper/MavenWrapperDownloader.java rename to integration/testdata/debug/java/.mvn/wrapper/MavenWrapperDownloader.java diff --git a/integration/testdata/debug/jib/.mvn/wrapper/maven-wrapper.jar b/integration/testdata/debug/java/.mvn/wrapper/maven-wrapper.jar similarity index 100% rename from integration/testdata/debug/jib/.mvn/wrapper/maven-wrapper.jar rename to integration/testdata/debug/java/.mvn/wrapper/maven-wrapper.jar diff --git a/integration/testdata/debug/jib/.mvn/wrapper/maven-wrapper.properties b/integration/testdata/debug/java/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from integration/testdata/debug/jib/.mvn/wrapper/maven-wrapper.properties rename to integration/testdata/debug/java/.mvn/wrapper/maven-wrapper.properties diff --git a/integration/testdata/debug/jib/k8s/web.yaml b/integration/testdata/debug/java/k8s/web.yaml similarity index 73% rename from integration/testdata/debug/jib/k8s/web.yaml rename to integration/testdata/debug/java/k8s/web.yaml index 9600a966e55..a5ff4b69992 100644 --- a/integration/testdata/debug/jib/k8s/web.yaml +++ b/integration/testdata/debug/java/k8s/web.yaml @@ -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 diff --git a/integration/testdata/debug/jib/mvnw b/integration/testdata/debug/java/mvnw similarity index 100% rename from integration/testdata/debug/jib/mvnw rename to integration/testdata/debug/java/mvnw diff --git a/integration/testdata/debug/jib/mvnw.cmd b/integration/testdata/debug/java/mvnw.cmd similarity index 100% rename from integration/testdata/debug/jib/mvnw.cmd rename to integration/testdata/debug/java/mvnw.cmd diff --git a/integration/testdata/debug/java/pom.xml b/integration/testdata/debug/java/pom.xml new file mode 100644 index 00000000000..878f93a334e --- /dev/null +++ b/integration/testdata/debug/java/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + org.skaffold + hello-java + 0.1.0 + Simple Java server with Skaffold and Jib + + + 2.4.0 + 1.8 + 1.8 + + + + hello + + + com.google.cloud.tools + jib-maven-plugin + ${jib.maven-plugin-version} + + + openjdk + + + + -Djava.security.egd=file:/dev/./urandom + + /app + + + + + scripts + /workspace/scripts + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + libs/ + hello.Application + + + + + + + diff --git a/integration/testdata/debug/jib/src/main/jib/check-jdwp.sh b/integration/testdata/debug/java/scripts/check-jdwp.sh similarity index 100% rename from integration/testdata/debug/jib/src/main/jib/check-jdwp.sh rename to integration/testdata/debug/java/scripts/check-jdwp.sh diff --git a/integration/testdata/debug/jib/src/main/java/hello/Application.java b/integration/testdata/debug/java/src/main/java/hello/Application.java similarity index 100% rename from integration/testdata/debug/jib/src/main/java/hello/Application.java rename to integration/testdata/debug/java/src/main/java/hello/Application.java diff --git a/integration/testdata/debug/jib/pom.xml b/integration/testdata/debug/jib/pom.xml deleted file mode 100644 index 4b1043c66c0..00000000000 --- a/integration/testdata/debug/jib/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - org.skaffold - hello-java - 0.1.0 - Simple Java server with Skaffold and Jib - - - 2.4.0 - 1.8 - 1.8 - - - - hello - - - com.google.cloud.tools - jib-maven-plugin - ${jib.maven-plugin-version} - - - openjdk - - - - -Djava.security.egd=file:/dev/./urandom - - - - - - - diff --git a/integration/testdata/debug/kustomization.yaml b/integration/testdata/debug/kustomization.yaml index a4abc55f55a..25c3745769a 100644 --- a/integration/testdata/debug/kustomization.yaml +++ b/integration/testdata/debug/kustomization.yaml @@ -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 diff --git a/integration/testdata/debug/nodejs/Procfile b/integration/testdata/debug/nodejs/Procfile new file mode 100644 index 00000000000..550413efa9f --- /dev/null +++ b/integration/testdata/debug/nodejs/Procfile @@ -0,0 +1 @@ +web: node src/index.js diff --git a/integration/testdata/debug/nodejs/k8s/pod.yaml b/integration/testdata/debug/nodejs/k8s/pod.yaml index d7f4c37e2c9..9a33d50cb95 100644 --- a/integration/testdata/debug/nodejs/k8s/pod.yaml +++ b/integration/testdata/debug/nodejs/k8s/pod.yaml @@ -4,7 +4,7 @@ metadata: name: nodejs spec: containers: - - name: web + - name: nodejs-web image: skaffold-debug-nodejs ports: - containerPort: 3000 diff --git a/integration/testdata/debug/npm/k8s/pod.yaml b/integration/testdata/debug/npm/k8s/pod.yaml index 05388e224ac..ec86b23a8be 100644 --- a/integration/testdata/debug/npm/k8s/pod.yaml +++ b/integration/testdata/debug/npm/k8s/pod.yaml @@ -4,7 +4,7 @@ metadata: name: npm spec: containers: - - name: web + - name: npm-web image: skaffold-debug-npm ports: - containerPort: 3000 diff --git a/integration/testdata/debug/npm/project.toml b/integration/testdata/debug/npm/project.toml new file mode 100644 index 00000000000..6c250ce7fd2 --- /dev/null +++ b/integration/testdata/debug/npm/project.toml @@ -0,0 +1,3 @@ +[[build.env]] +name = "GOOGLE_ENTRYPOINT" +value = "npm start" diff --git a/integration/testdata/debug/python3/Procfile b/integration/testdata/debug/python3/Procfile new file mode 100644 index 00000000000..4106ba60fdf --- /dev/null +++ b/integration/testdata/debug/python3/Procfile @@ -0,0 +1 @@ +web: python3 app.py diff --git a/integration/testdata/debug/python3/k8s/pod.yaml b/integration/testdata/debug/python3/k8s/pod.yaml index 44a926831be..2c9381f921d 100644 --- a/integration/testdata/debug/python3/k8s/pod.yaml +++ b/integration/testdata/debug/python3/k8s/pod.yaml @@ -4,7 +4,7 @@ metadata: name: python3 spec: containers: - - name: web + - name: python3-web image: skaffold-debug-python3 ports: - containerPort: 5000 diff --git a/integration/testdata/debug/skaffold.yaml b/integration/testdata/debug/skaffold.yaml index eb66712619e..90e1c7a64bd 100644 --- a/integration/testdata/debug/skaffold.yaml +++ b/integration/testdata/debug/skaffold.yaml @@ -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 @@ -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'" diff --git a/integration/util.go b/integration/util.go index 06e96db2ba9..946cd955fbb 100644 --- a/integration/util.go +++ b/integration/util.go @@ -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()