Skip to content

Commit

Permalink
Setting up end-to-end test environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviof committed Sep 21, 2021
1 parent c8174b4 commit 653dc3d
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 6 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
on:
pull_request:
branches:
- main
push:
branches:
- main
name: End-to-End (E2E) Tests
jobs:
e2e:
strategy:
fail-fast: true
matrix:
kubernetes:
- v1.20.7
max-parallel: 1
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Install Tools
run: sudo apt-get update && sudo apt-get install -y make gcc

- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.2.1

- name: Install kubectl
uses: azure/setup-kubectl@v1
with:
version: ${{ matrix.kubernetes }}

- name: Create KinD cluster
uses: helm/kind-action@v1.2.0
with:
version: v0.11.1
node_image: kindest/node:${{ matrix.kubernetes }}
cluster_name: kind
wait: 120s

- name: Verify KinD cluster
run: make verify-kind

- name: Installing Shipwright Build Controller
run: make install-shipwright

- name: Build Application (shp)
run: make build

- name: End-to-End Tests
run: make test-e2e
4 changes: 2 additions & 2 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
- name: Install Tools
run: sudo apt-get update && sudo apt-get install -y make gcc

- name: Build Application
- name: Build Application (shp)
run: make build

- name: Run Unit Tests
run: make test
run: make test-unit
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ GO_TEST_FLAGS ?= -race -cover

ARGS ?=

# Tekton and Shipwright Build Controller versions for CI
TEKTON_VERSION ?= v0.25.0
SHIPWRIGHT_VERSION ?= v0.5.1

.EXPORT_ALL_VARIABLES:

.PHONY: $(BIN)
$(BIN):
go build $(GO_FLAGS) -o $(BIN) $(CMD)
Expand All @@ -36,12 +42,22 @@ clean:
run:
go run $(GO_FLAGS) $(CMD) $(ARGS)

test: test-unit
# runs all tests, unit and end-to-end.
test: test-unit test-e2e

.PHONY: test-unit
test-unit:
go test $(GO_FLAGS) $(GO_TEST_FLAGS) $(CMD) $(PKG) $(ARGS)

travis:
./hack/install-kubectl.sh
./hack/install-kind.sh
# runs all end-to-end tests using bats, it assumes bats is installed
test-e2e:
./test/e2e/e2e.bats

# wait for KinD cluster to be on ready state, so tests can be performed
verify-kind:
./hack/verify-kind.sh

# deploys Tekton and Shipwright Build Controller following the versions exported
install-shipwright:
./hack/install-tekton.sh
./hack/install-shipwright.sh
22 changes: 22 additions & 0 deletions hack/install-shipwright.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# Installs Shipwright Build Controller and Build-Strategies.
#

set -eu

SHIPWRIGHT_HOST="github.com"
SHIPWRIGHT_HOST_PATH="shipwright-io/build/releases/download"
SHIPWRIGHT_VERSION="${SHIPWRIGHT_VERSION:-v0.5.1}"

echo "# Deploying Shipwright Controller '${SHIPWRIGHT_VERSION}'"

kubectl apply -f "https://${SHIPWRIGHT_HOST}/${SHIPWRIGHT_HOST_PATH}/${SHIPWRIGHT_VERSION}/release.yaml"

echo "# Waiting for Build Controller rollout..."

kubectl --namespace="shipwright-build" rollout status deployment shipwright-build-controller --timeout=1m

echo "# Installing upstream Build-Strategies..."

kubectl apply -f "https://${SHIPWRIGHT_HOST}/${SHIPWRIGHT_HOST_PATH}/nightly/default_strategies.yaml"
24 changes: 24 additions & 0 deletions hack/install-tekton.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Installs Tekton Pipelines.
#

set -eu

TEKTON_VERSION="${TEKTON_VERSION:-v0.25.0}"

TEKTON_HOST="github.com"
TEKTON_HOST_PATH="tektoncd/pipeline/releases/download"

function rollout_status () {
kubectl --namespace="tekton-pipelines" rollout status deployment ${1} --timeout=1m
}

echo "# Deploying Tekton Pipelines '${TEKTON_VERSION}'"

kubectl apply -f "https://${TEKTON_HOST}/${TEKTON_HOST_PATH}/${TEKTON_VERSION}/release.yaml"

echo "# Waiting for Tekton components..."

rollout_status "tekton-pipelines-controller"
rollout_status "tekton-pipelines-webhook"
31 changes: 31 additions & 0 deletions hack/verify-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
#
# Make sure a KinD instance is up and running.
#

set -eu

function node_status () {
echo $(kubectl get node kind-control-plane -o json | \
jq -r .'status.conditions[] | select(.type == "Ready") | .status')
}

echo "# Using KinD context..."
kubectl config use-context "kind-kind"

echo "# KinD nodes:"
kubectl get nodes

if [ "$(node_status)" == "True" ]; then
echo "# Kind is Ready!"
else
echo "# Node is not ready:"
kubectl describe node kind-control-plane

echo "# Pods:"
kubectl get pod -A
echo "# Events:"
kubectl get events -A

exit 1
fi

0 comments on commit 653dc3d

Please sign in to comment.