Skip to content

Commit

Permalink
Build fix, alpine-base update, and test fixes (#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg committed May 11, 2020
1 parent 3a8a3bb commit c034abb
Show file tree
Hide file tree
Showing 16 changed files with 525 additions and 256 deletions.
62 changes: 50 additions & 12 deletions .github/workflows/ci.yaml
Expand Up @@ -12,7 +12,7 @@ env:
REPO_NAME: nuclio
NUCLIO_LABEL: ${{ github.run_number }}
NAMESPACE: nuclio
NUCTL_REGISTRY: localhost:5000
NUCLIO_GO_TEST_TIMEOUT: "20m"

jobs:
lint:
Expand Down Expand Up @@ -74,13 +74,13 @@ jobs:
env:
NUCLIO_NUCTL_CREATE_SYMLINK: false

- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v2
with:
name: nuctl-bin
path: nuctl

build_docker_images:
name: Build nuclio docker images
name: Build docker images
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
| pigz --fast > nuclio_docker_images.tar.gz
- name: Upload
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: nuclio-docker-images
path: nuclio_docker_images.tar.gz
Expand All @@ -123,7 +123,6 @@ jobs:
runs-on: ubuntu-latest
needs:
- build_docker_images
- build_nuctl
steps:
- uses: actions/checkout@v2

Expand All @@ -145,15 +144,16 @@ jobs:
github token: ${{ github.token }}

- name: Fetch nuclio docker images
uses: actions/download-artifact@v1
uses: actions/download-artifact@v2
with:
name: nuclio-docker-images

- name: Prepare k8s cluster
run: |
kubectl create namespace ${NAMESPACE}
docker run -d -p 5000:5000 registry:2
docker load -i nuclio-docker-images/nuclio_docker_images.tar.gz
docker load -i nuclio_docker_images.tar.gz
rm nuclio_docker_images.tar.gz
- name: Install nuclio helm chart
run: |
Expand All @@ -164,13 +164,51 @@ jobs:
- name: Run nuctl tests
run: |
set -o pipefail
make test-k8s-nuctl 2>&1 | tee nuctl-test-results-${NUCLIO_LABEL}.log
make test-k8s-nuctl 2>&1 | tee test-k8s-nuctl-${NUCLIO_LABEL}.log
env:
NUCLIO_DASHBOARD_DEFAULT_ONBUILD_REGISTRY_URL: ${{ env.REPO }}
NUCTL_REGISTRY: "localhost:5000"

- uses: actions/upload-artifact@v1
- name: Upload test results
uses: actions/upload-artifact@v2
if: always()
with:
name: Nuctl tests results
path: nuctl-test-results-${{ env.NUCLIO_LABEL }}.log
if: ${{ always() }}
name: test-results
path: test-k8s-nuctl-${{ env.NUCLIO_LABEL }}.log

test_docker_nuctl:
name: Test Docker nuctl
runs-on: ubuntu-latest
needs:
- build_docker_images
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Fetch nuclio docker images
uses: actions/download-artifact@v2
with:
name: nuclio-docker-images

- name: Prepare
run: |
docker load -i nuclio_docker_images.tar.gz
rm nuclio_docker_images.tar.gz
- name: Run nuctl tests
run: |
set -o pipefail
make test-docker-nuctl 2>&1 | tee test-docker-nuctl-${NUCLIO_LABEL}.log
- name: Upload test results
uses: actions/upload-artifact@v2
if: always()
with:
name: test-results
path: test-docker-nuctl-${{ env.NUCLIO_LABEL }}.log
18 changes: 15 additions & 3 deletions Makefile
Expand Up @@ -67,6 +67,9 @@ NUCLIO_BUILD_ARGS_VERSION_INFO_FILE = --build-arg NUCLIO_VERSION_INFO_FILE_CONTE
# Docker client version to be used
DOCKER_CLI_VERSION := 18.09.6

# Nuclio test timeout
NUCLIO_GO_TEST_TIMEOUT ?= "10m"

#
# Must be first target
#
Expand Down Expand Up @@ -375,7 +378,7 @@ lint: modules

.PHONY: test-undockerized
test-undockerized: ensure-gopath
go test -v ./cmd/... ./pkg/... -p 1
go test -v --parallel 1 --timeout $(NUCLIO_GO_TEST_TIMEOUT) ./cmd/... ./pkg/...

.PHONY: test
test: ensure-gopath build-base
Expand All @@ -393,6 +396,11 @@ test: ensure-gopath build-base
--volume /tmp:/tmp \
--workdir $(GO_BUILD_TOOL_WORKDIR) \
--env NUCLIO_TEST_HOST=$(NUCLIO_TEST_HOST) \
--env NUCLIO_VERSION_GIT_COMMIT=$(NUCLIO_VERSION_GIT_COMMIT) \
--env NUCLIO_LABEL=$(NUCLIO_LABEL) \
--env NUCLIO_ARCH=$(NUCLIO_ARCH) \
--env NUCLIO_OS=$(NUCLIO_OS) \
--env NUCLIO_GO_TEST_TIMEOUT=$(NUCLIO_GO_TEST_TIMEOUT) \
$(NUCLIO_DOCKER_TEST_TAG) \
/bin/bash -c "make test-undockerized"

Expand All @@ -405,13 +413,17 @@ test-python:
test-short: modules ensure-gopath
go test -v ./cmd/... ./pkg/... -short

.PHONY: test-nuctl
.PHONY: test-k8s-nuctl
test-k8s-nuctl:
NUCTL_EXTERNAL_IP_ADDRESSES=$(if $(NUCTL_EXTERNAL_IP_ADDRESSES),$(NUCTL_EXTERNAL_IP_ADDRESSES),"localhost") \
NUCTL_RUN_REGISTRY=$(NUCTL_REGISTRY) \
NUCTL_PLATFORM=kube \
NAMESPACE=$(if $(NAMESPACE),$(NAMESPACE),"default")
go test -v github.com/nuclio/nuclio/pkg/nuctl/... -p 1
go test -v github.com/nuclio/nuclio/pkg/nuctl/... -p 1 --timeout $(NUCLIO_GO_TEST_TIMEOUT)

.PHONY: test-docker-nuctl
test-docker-nuctl:
NUCTL_PLATFORM=local go test -v github.com/nuclio/nuclio/pkg/nuctl/... -p 1 --timeout $(NUCLIO_GO_TEST_TIMEOUT)

.PHONY: build-base
build-base: build-builder
Expand Down
18 changes: 15 additions & 3 deletions docs/devel/contributing.md
Expand Up @@ -45,15 +45,27 @@ make build
You should now have quite a few `nuclio/<something>` images tagged as `latest-amd64`, along with `nuctl-latest-<os>-amd64` with a `nuctl` symbolic link under `$GOPATH/bin`. Now, run a few tests:

```sh
make lint test
make lint test-short
```

This may take a while (over 10 minutes) and requires only Docker.
This is a short test suite, and requires only Docker.

To run a limited kubernetes nuctl suite (Also runs in CI):
To run integration tests (currently support docker platform, and may take a while ~60 minutes), run:

```sh
make test
```

On Nuclio CI, we run nuctl test suites against both Docker and Kubernetes platforms

To run kubernetes nuctl suite locally:

`NUCTL_REGISTRY=<registry> make test-k8s-nuctl`

To run docker nuctl suite locally:

`make test-docker-nuctl`

Running more comprehensive end-to-end tests on kubernetes is currently done manually.

When you're done, create a feature branch from the `development` branch; (Nuclio follows the GitFlow branching model):
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/runtimes/nodejs/nodejs-reference.md
Expand Up @@ -25,7 +25,7 @@ See [Deploying Functions from a Dockerfile](/docs/tasks/deploy-functions-from-do
```
ARG NUCLIO_LABEL=0.5.6
ARG NUCLIO_ARCH=amd64
ARG NUCLIO_BASE_IMAGE=node:10.3-alpine
ARG NUCLIO_BASE_IMAGE=node:10.20-alpine
ARG NUCLIO_ONBUILD_IMAGE=nuclio/handler-builder-nodejs-onbuild:${NUCLIO_LABEL}-${NUCLIO_ARCH}
# Supplies processor uhttpc, used for healthcheck
Expand Down
77 changes: 71 additions & 6 deletions pkg/common/helper.go
Expand Up @@ -111,20 +111,70 @@ func RemoveANSIColorsFromString(s string) string {

// RetryUntilSuccessful calls callback every interval for duration until it returns true
func RetryUntilSuccessful(duration time.Duration, interval time.Duration, callback func() bool) error {
return retryUntilSuccessful(duration, interval, func() (bool, error) {

// callback results indicate whether to retry
return !callback(), nil
})
}

// RetryUntilSuccessfulOnErrorPatterns calls callback every interval for duration as long as error pattern is matched
func RetryUntilSuccessfulOnErrorPatterns(duration time.Duration,
interval time.Duration,
errorRegexPatterns []string,
callback func() string) error {

return retryUntilSuccessful(duration, interval, func() (bool, error) {
callbackErrorStr := callback()
if callbackErrorStr == "" {

// no error message means no error, succeeded
return false, nil
}

// find a matching error pattern
errorPatternFound, matchingErr := MatchStringPatterns(errorRegexPatterns, callbackErrorStr)
if matchingErr != nil {
return false, errors.Wrap(matchingErr, "Failed to match string patterns")
}

// no error pattern found, dont retry, bail
if !errorPatternFound {
return false, errors.Errorf("Failed matching an error pattern for callback: %s", callbackErrorStr)
}

return true, nil

})
}

// retryUntilSuccessful calls callback every interval until duration as long as it should retry
func retryUntilSuccessful(duration time.Duration,
interval time.Duration,
callback func() (bool, error)) error {
var lastErr error
timedOutErrorMessage := "Timed out waiting until successful"
deadline := time.Now().Add(duration)

// while we haven't passed the deadline
for !time.Now().After(deadline) {

// if callback returns true, we're done
if callback() {
return nil
shouldRetry, err := callback()
lastErr = err
if !shouldRetry {
return err
}

time.Sleep(interval)
continue

}
if lastErr != nil {

// wrap last error
return errors.Wrapf(lastErr, timedOutErrorMessage)
}

return errors.New("Timed out waiting until successful")
// duration expired without any last error
return errors.Errorf(timedOutErrorMessage)
}

// RunningInContainer returns true if currently running in a container, false otherwise
Expand Down Expand Up @@ -324,3 +374,18 @@ func ByteSliceToString(b []byte) string {
// !! use with caution as returned string is mutable !!
return *(*string)(unsafe.Pointer(&b))
}

func MatchStringPatterns(patterns []string, s string) (bool, error) {
for _, pattern := range patterns {
matched, err := regexp.MatchString(pattern, s)
if err != nil {
return false, errors.Wrapf(err, "Failed to match string pattern: %s", pattern)
}
if matched {

// one matching pattern is enough
return true, nil
}
}
return false, nil
}

0 comments on commit c034abb

Please sign in to comment.