Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make integration tests shorter and more stable #1790

Merged
Merged
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
language: go

os:
- linux
- osx

git:
submodules: false

go:
- "1.11.x"
- "1.12.x"

go_import_path: github.com/GoogleContainerTools/skaffold

before_script:
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

script:
- make out/skaffold test
- make out/skaffold
- make test

after_success:
- bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This doc explains the development workflow so you can get started
You must install these tools:

1. [`go`](https://golang.org/doc/install): The language skaffold is
built in
built in (version >= go 1.11)
1. [`git`](https://help.github.com/articles/set-up-git/): For source control
1. [`dep`](https://github.com/golang/dep): For managing external Go
dependencies. - Please Install dep v0.5.0 or greater.
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
clone_folder: c:\gopath\src\github.com\GoogleContainerTools\skaffold
stack: go 1.10
stack: go 1.11
environment:
GOPATH: c:\gopath
build_script:
- go build -o out/skaffold.exe cmd/skaffold/skaffold.go
test_script:
- go test -short -v -timeout 60s ./...
- go test -short -timeout 60s ./...
2 changes: 1 addition & 1 deletion deploy/skaffold/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge
apt-get -y install docker-ce=17.12.0~ce-0~ubuntu && \
rm -rf /var/lib/apt/lists/*

COPY --from=golang:1.10 /usr/local/go /usr/local/go
COPY --from=golang:1.11 /usr/local/go /usr/local/go
ENV PATH /usr/local/go/bin:/go/bin:$PATH
ENV GOPATH /go/

Expand Down
10 changes: 6 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Examples

To run the examples, you either have to manually replace the image repositories in the examples from gcr.io/k8s-skaffold to yours or you can point skaffold to your default image repository in one of the four ways:
To run the examples, you either have to manually replace the image repositories in the examples from `gcr.io/k8s-skaffold`
to yours or you can point Skaffold to your default image repository in one of the four ways:

* flag: `skaffold dev --default-repo <myrepo>`
* env var: `SKAFFOLD_DEFAULT_REPO=<myrepo> skaffold dev`
* global skaffold config (one time): `skaffold config set --global default-repo <myrepo>`
* skaffold config for current kubectl context: `skaffold config set default-repo <myrepo>`

These examples are made to work with the latest release of skaffold.
These examples are made to work with the latest release of Skaffold.

If you are running skaffold at HEAD or have built it from source, please use the examples at integration/examples.
If you are running Skaffold at HEAD or have built it from source, please use the examples at `integration/examples`.

*Note for contributors*: If you wish to make changes to these examples, please edit the ones at integration/examples, as those will be synced on release.
*Note for contributors*: If you wish to make changes to these examples, please edit the ones at `integration/examples`,
as those will be synced on release.
1 change: 0 additions & 1 deletion examples/bazel/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-bazel
context: .
bazel:
target: //:skaffold_example.tar
1 change: 1 addition & 0 deletions examples/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
9 changes: 5 additions & 4 deletions examples/kaniko-local/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM gcr.io/google-appengine/golang
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

WORKDIR /go/src/github.com/GoogleCloudPlatform/skaffold
FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .
1 change: 1 addition & 0 deletions examples/kaniko-local/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
9 changes: 5 additions & 4 deletions examples/kaniko/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM gcr.io/google-appengine/golang
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

WORKDIR /go/src/github.com/GoogleCloudPlatform/skaffold
FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .
1 change: 1 addition & 0 deletions examples/kaniko/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
8 changes: 5 additions & 3 deletions examples/tagging-with-environment-variables/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM golang:1.10.1-alpine3.7
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .
1 change: 0 additions & 1 deletion examples/tagging-with-environment-variables/k8s-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ spec:
containers:
- name: getting-started
image: gcr.io/k8s-skaffold/skaffold-example
imagePullPolicy: IfNotPresent
1 change: 1 addition & 0 deletions examples/tagging-with-environment-variables/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
10 changes: 6 additions & 4 deletions integration/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Examples

To run the examples, you either have to manually replace the image repositories in the examples from gcr.io/k8s-skaffold to yours or you can point skaffold to your default image repository in one of the four ways:
To run the examples, you either have to manually replace the image repositories in the examples from `gcr.io/k8s-skaffold`
to yours or you can point Skaffold to your default image repository in one of the four ways:

* flag: `skaffold dev --default-repo <myrepo>`
* env var: `SKAFFOLD_DEFAULT_REPO=<myrepo> skaffold dev`
* global skaffold config (one time): `skaffold config set --global default-repo <myrepo>`
* skaffold config for current kubectl context: `skaffold config set default-repo <myrepo>`

These examples are made to work with the latest release of skaffold.
These examples are made to work with the latest release of Skaffold.

If you are running skaffold at HEAD or have built it from source, please use the examples at integration/examples.
If you are running Skaffold at HEAD or have built it from source, please use the examples at `integration/examples`.

*Note for contributors*: If you wish to make changes to these examples, please edit the ones at integration/examples, as those will be synced on release.
*Note for contributors*: If you wish to make changes to these examples, please edit the ones at `integration/examples`,
as those will be synced on release.
1 change: 1 addition & 0 deletions integration/examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This documentation has been moved to https://skaffold.dev/docs/references/yaml/
1 change: 0 additions & 1 deletion integration/examples/bazel/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-bazel
context: .
bazel:
target: //:skaffold_example.tar
1 change: 1 addition & 0 deletions integration/examples/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
9 changes: 5 additions & 4 deletions integration/examples/kaniko-local/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM gcr.io/google-appengine/golang
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

WORKDIR /go/src/github.com/GoogleCloudPlatform/skaffold
FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .
1 change: 1 addition & 0 deletions integration/examples/kaniko-local/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
9 changes: 5 additions & 4 deletions integration/examples/kaniko/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM gcr.io/google-appengine/golang
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

WORKDIR /go/src/github.com/GoogleCloudPlatform/skaffold
FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .
1 change: 1 addition & 0 deletions integration/examples/kaniko/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM golang:1.10.1-alpine3.7
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ spec:
containers:
- name: getting-started
image: gcr.io/k8s-skaffold/skaffold-example
imagePullPolicy: IfNotPresent
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
2 changes: 2 additions & 0 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestRun(t *testing.T) {
description: "docker plugin in gcb exec environment",
dir: "testdata/plugin/gcb",
deployments: []string{"leeroy-app", "leeroy-web"},
remoteOnly: true,
}, {
description: "bazel plugin in local exec environment",
dir: "testdata/plugin/local/bazel",
Expand All @@ -111,6 +112,7 @@ func TestRun(t *testing.T) {
dir: "examples/jib",
args: []string{"-p", "gcb"},
deployments: []string{"web"},
remoteOnly: true,
},
}

Expand Down
38 changes: 34 additions & 4 deletions integration/skaffold/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ package skaffold
import (
"bytes"
"context"
"io"
"os"
"os/exec"
"strings"
"testing"
"time"

"github.com/sirupsen/logrus"
)

// RunBuilder is used to build a command line to run `skaffold`.
Expand Down Expand Up @@ -110,16 +114,34 @@ func (b *RunBuilder) WithEnv(env []string) *RunBuilder {
// This also returns a teardown function that stops skaffold.
func (b *RunBuilder) RunBackground(t *testing.T) context.CancelFunc {
t.Helper()
ctx, cancel := context.WithCancel(context.Background())

ctx, cancel := context.WithCancel(context.Background())
cmd := b.cmd(ctx)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

// If the test is killed by a timeout, go test will wait for
// os.Stderr and os.Stdout to close as a result.
//
// However, the `cmd` will stil run in the background
// and hold those descriptors open.
// As a result, go test will hang forever.
//
// Avoid that by wrapping stderr and stdout, breaking the short
// circuit and forcing cmd.Run to use another pipe and goroutine
// to pass along stderr and stdout.
// See https://github.com/golang/go/issues/23019
cmd.Stdout = struct{ io.Writer }{os.Stdout}
cmd.Stderr = struct{ io.Writer }{os.Stderr}

start := time.Now()
if err := cmd.Start(); err != nil {
t.Fatalf("skaffold %s: %v", b.command, err)
}

go func() {
cmd.Wait()
logrus.Infoln("Ran in", time.Since(start))
}()

return func() {
cancel()
cmd.Wait()
Expand All @@ -129,7 +151,15 @@ func (b *RunBuilder) RunBackground(t *testing.T) context.CancelFunc {
// Run runs the skaffold command and returns its output.
func (b *RunBuilder) Run(t *testing.T) ([]byte, error) {
t.Helper()
return b.cmd(context.Background()).Output()

cmd := b.cmd(context.Background())
logrus.Infoln(cmd.Args)

start := time.Now()
out, err := cmd.Output()
logrus.Infoln("Ran in", time.Since(start))

return out, err
}

// RunOrFail runs the skaffold command and fails the test
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM golang:1.10.1-alpine3.7 as builder
FROM busybox
COPY foo /foo
CMD while true; do cat /foo; sleep 1; done
2 changes: 1 addition & 1 deletion integration/testdata/file-sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM alpine
FROM busybox
COPY . .
CMD while true; do cat /foo && sleep 5; done
9 changes: 5 additions & 4 deletions integration/testdata/fix/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.10.1-alpine3.7
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

WORKDIR /go/src/github.com/GoogleContainerTools/skaffold/examples/getting-started
FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .
1 change: 1 addition & 0 deletions integration/testdata/fix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
1 change: 1 addition & 0 deletions integration/testdata/init/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
9 changes: 5 additions & 4 deletions integration/testdata/kaniko-sub-folder/sub/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM gcr.io/google-appengine/golang
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

WORKDIR /go/src/github.com/GoogleCloudPlatform/skaffold
FROM alpine:3.7
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
COPY --from=builder /app .