Skip to content

Configure ide integration test to run automatically #7380

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

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .werft/integration-tests-startup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
pod:
serviceAccount: werft
nodeSelector:
dev/workload: builds
imagePullSecrets:
- name: eu-gcr-io-pull-secret
volumes:
- name: gcp-sa
secret:
secretName: gcp-sa-gitpod-dev-deployer
- name: config
emptyDir: {}
containers:
- name: gcloud
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:prs-ws-man-bridge-audit.10
workingDir: /workspace
imagePullPolicy: Always
env:
- name: NODENAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: gcp-sa
mountPath: /mnt/secrets/gcp-sa
readOnly: true
- name: config
mountPath: /config
readOnly: false
command:
- bash
- -c
- |
set -euo pipefail

function cleanup ()
{
werft log phase "cleanup preview environment" "cleanup preview environment"
BUILD_ID=$(werft run github -a namespace=staging-gitpod-test-main -j .werft/wipe-devstaging.yaml github.com/gitpod-io/gitpod:main)

echo "start cleanup preview environment, job name: ${BUILD_ID}" | werft log slice "cleanup"
werft log result -d "cleanup job" url "https://werft.gitpod-dev.com/job/${BUILD_ID}"

werft job logs ${BUILD_ID} | werft log slice "cleanup"
}

echo "preparing config." | werft log slice prepare
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/legacy_credentials/cd-gitpod-deployer@gitpod-core-dev.iam.gserviceaccount.com/adc.json"
export DOCKER_HOST=tcp://$NODENAME:2375
echo "copied config..." | werft log slice prepare
werft log slice prepare --done

werft log phase "build preview environment" "build preview environment"
# this is because we don't want to increate gitpod-build-main number, we can choose a name
sudo cp .werft/build.yaml .werft/test.yaml
# version is actual namespace that werft is build, --job-file should be same with above
VERSION=$(werft run github -j .werft/test.yaml -s .werft/test.yaml github.com/gitpod-io/gitpod:main)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use --follow-with-prefix, the run will wait until the other job is done and integrate the log output correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main purpose here is to get the build ID in order to get the version number of the corresponding integration-test in the next step

echo "start build preview environment, job name: ${VERSION}, this will take long time" | werft log slice "build test environment"
werft log result -d "build job" url "https://werft.gitpod-dev.com/job/${VERSION}"

if ! werft job logs ${VERSION} | werft log slice "build test environment";
then
echo "build failed" | werft log slice "build test environment"
exit 1
fi
echo "build success" | werft log slice "build test environment"
werft log slice "build test environment" --done

# clean preview environment when the script exits
trap cleanup SIGINT SIGTERM EXIT

werft log phase "integration test" "integration test"
# we need get integration-test version like: jp-run-integration-test.61
INTEGRATION_VERSION=$(docker run eu.gcr.io/gitpod-core-dev/build/versions:${VERSION} cat versions.yaml | yq r - 'components.integrationTest.version')

echo "using integration-test image: ${INTEGRATION_VERSION}" | werft log slice "test"


TEST_BUILD_ID=$(werft run github -a version=${INTEGRATION_VERSION} -a namespace=staging-gitpod-test-main -j .werft/run-integration-tests-ide.yaml -a testPattern=ide.test github.com/gitpod-io/gitpod:main)

echo "running integration, job name: ${TEST_BUILD_ID}" | werft log slice "test"
werft log result -d "integration test job" url "https://werft.gitpod-dev.com/job/${TEST_BUILD_ID}"

if ! werft job logs ${TEST_BUILD_ID} | werft log slice "test";
then
echo "ingetration test failed" | werft log slice "test"
exit 1
fi
echo "ingetration test success" | werft log slice "test"
103 changes: 103 additions & 0 deletions .werft/run-integration-tests-ide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
args:
- name: version
desc: "The version of the integration tests to use"
required: true
- name: namespace
desc: "The namespace to run the integration test against"
required: true
- name: testPattern
desc: "The test file pattern to filter the tests to run"
required: false
pod:
serviceAccount: werft
nodeSelector:
dev/workload: builds
imagePullSecrets:
- name: eu-gcr-io-pull-secret
volumes:
- name: gcp-sa
secret:
secretName: gcp-sa-gitpod-dev-deployer
- name: integration-test-user
secret:
secretName: integration-test-user
- name: config
emptyDir: {}
initContainers:
- name: gcloud
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:prs-ws-man-bridge-audit.10
workingDir: /workspace
imagePullPolicy: Always
volumeMounts:
- name: gcp-sa
mountPath: /mnt/secrets/gcp-sa
readOnly: true
- name: config
mountPath: /config
readOnly: false
command:
- bash
- -c
- |

echo "[prep] preparing config."

gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
cp -R /home/gitpod/.config/gcloud /config/gcloud
cp /home/gitpod/.kube/config /config/kubeconfig

echo "[prep] copied config..."
containers:
- name: tests
image: eu.gcr.io/gitpod-core-dev/build/integration-tests:{{ .Annotations.version }}
workingDir: /workspace
imagePullPolicy: Always
volumeMounts:
- name: config
mountPath: /config
readOnly: true
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: integration-test-user
key: username
- name: USER_TOKEN
valueFrom:
secretKeyRef:
name: integration-test-user
key: token
command:
- /bin/bash
- -c
- |
sleep 1
set -Eeuo pipefail

echo "[prep] receiving config..."
export GOOGLE_APPLICATION_CREDENTIALS="/config/gcloud/legacy_credentials/cd-gitpod-deployer@gitpod-core-dev.iam.gserviceaccount.com/adc.json"
echo "[prep] received config."

echo "[prep] using username: $USERNAME"

TEST_PATTERN="{{ .Annotations.testPattern }}"
if [[ "$TEST_PATTERN" == "<no value>" ]]; then
TEST_PATTERN=""
fi
echo "[prep] using testPattern: $TEST_PATTERN"

args=()
[[ "$TEST_PATTERN" != "" ]] && args+=( "-testPattern=$TEST_PATTERN" )
args+=( '-kubeconfig=/config/kubeconfig' )
args+=( "-namespace={{ .Annotations.namespace }}" )
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
echo "[prep|DONE]"

/entrypoint.sh "${args[@]}" 2>&1 | ts "[int-tests] "

RC=${PIPESTATUS[0]}
if [ $RC -eq 1 ]; then
echo "[int-tests|FAIL]"
else
echo "[int-tests|DONE]"
fi
16 changes: 14 additions & 2 deletions test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@
# there are many test binaries, each can have failures
set -x

export PATH=$PATH:/tests
test_pattern="*.test"
for i in "$@"; do
case $i in
-testPattern=*|--testPattern=*)
test_pattern="${i#*=}"
shift
;;
*)
;;
esac
done

export PATH="$PATH:/tests"

FAILURE_COUNT=0
# shellcheck disable=SC2045
for i in $(find /tests/ -name "*.test" | sort); do
for i in $(find /tests/ -name "$test_pattern" | sort); do
echo "running test: $i"
"$i" "$@";
TEST_STATUS=$?
Expand Down
9 changes: 6 additions & 3 deletions test/leeway-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ export CGO_ENABLED=0
mkdir -p bin

for AGENT in pkg/agent/*; do
echo building agent "$AGENT"
echo "building agent $AGENT"
base=$(basename "$AGENT")
go build -trimpath -ldflags="-buildid= -w -s" -o bin/gitpod-integration-test-"${base%_agent}"-agent ./"$AGENT"
done

for COMPONENT in tests/components/*; do
echo building test "$COMPONENT"
echo "building test $COMPONENT"
OUTPUT=$(basename "$COMPONENT")
go test -trimpath -ldflags="-buildid= -w -s" -c -o bin/"$OUTPUT".test ./"$COMPONENT"
done

echo building test tests/workspace
echo "building test tests/workspace"
go test -trimpath -ldflags="-buildid= -w -s" -o bin/workspace.test -c ./tests/workspace

echo "building test tests/ide"
go test -trimpath -ldflags="-buildid= -w -s" -o bin/ide.test -c ./tests/ide
Loading