Skip to content

Commit

Permalink
cypress: use 'docker compose' for tests
Browse files Browse the repository at this point in the history
this'll get squashed back into the original commit, it's just here for
reviews :)

Release note: None
  • Loading branch information
sjbarag committed Aug 11, 2022
1 parent 16e2ccc commit d1365a5
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 223 deletions.
2 changes: 1 addition & 1 deletion build/deploy/cockroach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# set -m: enable job control.
set -eum

cockroach_entrypoint="/cockroach/cockroach"
cockroach_entrypoint=${COCKROACH:-"/cockroach/cockroach"}

certs_dir="certs"
url=
Expand Down
18 changes: 7 additions & 11 deletions build/teamcity/cockroach/ci/tests/ui_e2e_test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ source "$build/teamcity/cockroach/ci/tests/ui_e2e_test_impl.sh"

tc_prepare

tc_start_block "Build Docker image"
build_docker_image
tc_end_block "Build Docker image"
tc_start_block "Load cockroachdb/cockroach-ci image"
load_cockroach_docker_image
tc_end_block "Load cockroachdb/cockroach-ci image"

# TeamCity doesn't restore permissions for files retrieved from artifact
# dependencies, so ensure the cockroach binary is executable before running it
# in a Docker container.
chmod a+x upstream_artifacts/cockroach

tc_start_block "Run all Cypress tests"
run_tests
tc_end_block "Run all Cypress tests"
tc_start_block "Run Cypress health checks"
cd $root/pkg/ui/workspaces/e2e-tests
run_tests health
tc_end_block "Run Cypress health checks"
12 changes: 4 additions & 8 deletions build/teamcity/cockroach/ci/tests/ui_e2e_test_health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ source "$build/teamcity/cockroach/ci/tests/ui_e2e_test_impl.sh"

tc_prepare

tc_start_block "Build Docker image"
build_docker_image
tc_end_block "Build Docker image"

# TeamCity doesn't restore permissions for files retrieved from artifact
# dependencies, so ensure the cockroach binary is executable before running it
# in a Docker container.
chmod a+x upstream_artifacts/cockroach
tc_start_block "Load cockroachdb/cockroach-ci image"
load_cockroach_docker_image
tc_end_block "Load cockroachdb/cockroach-ci image"

tc_start_block "Run Cypress health checks"
cd $root/pkg/ui/workspaces/e2e-tests
run_tests health
tc_end_block "Run Cypress health checks"
19 changes: 4 additions & 15 deletions build/teamcity/cockroach/ci/tests/ui_e2e_test_impl.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/usr/bin/env bash
function build_docker_image() {
# Buffer noisy output and only print it on failure.
DOCKER_BUILDKIT=1 run docker build \
-f ./pkg/ui/workspaces/e2e-tests/Dockerfile \
-t cockroachdb/cockroach-cypress \
--progress=plain \
$PWD &> artifacts/docker-build.log || (cat artifacts/docker-build.log && false)
rm artifacts/docker-build.log
function load_cockroach_docker_image() {
docker load --input upstream_artifacts/cockroach-docker-image.tar.gz &> artifacts/docker-load.log || (cat artifacts/docker-load.log && false)
rm artifacts/docker-load.log
}

function run_tests() {
Expand All @@ -15,11 +10,5 @@ function run_tests() {
SPEC_ARG="--spec 'cypress/e2e/health-check/**'"
fi

run docker run \
--rm \
-v $PWD/upstream_artifacts:/upstream_artifacts \
-v $PWD/artifacts:/artifacts \
cockroachdb/cockroach-cypress \
--reporter teamcity \
$SPEC_ARG
run docker compose run cypress -- $SPEC_ARG
}
6 changes: 3 additions & 3 deletions pkg/cmd/dev/testdata/datadriven/ui
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bazel info workspace --color=no
bazel info workspace --color=no
bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests install
bazel build //pkg/cmd/cockroach:cockroach --config=with_ui
crdb-checkout/pkg/ui/workspaces/e2e-tests/build/start-crdb-movr.sh bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests cy:run
crdb-checkout/pkg/ui/workspaces/e2e-tests/build/start-crdb-then.sh bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests cy:run

exec
dev ui e2e ./foo/bar
Expand All @@ -162,7 +162,7 @@ bazel info workspace --color=no
bazel info workspace --color=no
bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests install
bazel build //pkg/cmd/cockroach:cockroach --config=with_ui
crdb-checkout/pkg/ui/workspaces/e2e-tests/build/start-crdb-movr.sh bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests cy:run ./foo/bar
crdb-checkout/pkg/ui/workspaces/e2e-tests/build/start-crdb-then.sh bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests cy:run ./foo/bar

exec
dev ui e2e --headed
Expand All @@ -171,4 +171,4 @@ bazel info workspace --color=no
bazel info workspace --color=no
bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests install
bazel build //pkg/cmd/cockroach:cockroach --config=with_ui
crdb-checkout/pkg/ui/workspaces/e2e-tests/build/start-crdb-movr.sh bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests cy:debug
crdb-checkout/pkg/ui/workspaces/e2e-tests/build/start-crdb-then.sh bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/e2e-tests cy:debug
6 changes: 3 additions & 3 deletions pkg/cmd/dev/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,19 @@ launching test in a real browser. Extra flags are passed directly to the
}

// Run Cypress tests, passing any extra args through to 'cypress'
startCrdbMovrSh := path.Join(uiDirs.e2eTests, "build/start-crdb-movr.sh")
startCrdbThenSh := path.Join(uiDirs.e2eTests, "build/start-crdb-then.sh")
runCypressArgv := append(
[]string{"bazel"},
buildBazelYarnArgv("--silent", "--cwd", uiDirs.e2eTests, yarnTarget)...,
)
runCypressArgv = append(runCypressArgv, cmd.Flags().Args()...)

logCommand(startCrdbMovrSh, runCypressArgv...)
logCommand(startCrdbThenSh, runCypressArgv...)
env := append(
os.Environ(),
fmt.Sprintf("COCKROACH=%s", path.Join(workspace, "cockroach")),
)
err = d.exec.CommandContextWithEnv(ctx, env, startCrdbMovrSh, runCypressArgv...)
err = d.exec.CommandContextWithEnv(ctx, env, startCrdbThenSh, runCypressArgv...)
if err != nil {
return fmt.Errorf("error while running Cypress tests: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/workspaces/e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
artifacts
videos
screenshots
51 changes: 0 additions & 51 deletions pkg/ui/workspaces/e2e-tests/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/ui/workspaces/e2e-tests/Dockerfile.dockerignore

This file was deleted.

20 changes: 11 additions & 9 deletions pkg/ui/workspaces/e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ For "headed" test development, in which the Cypress UI and a browser are
visible, run `dev ui e2e --headed` and choose a test file in the Cypress UI.

## Running Tests in TeamCity
For CI purposes, these tests are also run in TeamCity via Docker. Debugging that
container is slightly more complicated, and is out-of-scope for this README. See
[Dockerfile](./Dockerfile) for more details and examples.
For CI purposes, these tests are also run in TeamCity via Docker's [Compose
V2](https://docs.docker.com/compose) by combining the [CockroachDB Docker
image](https://github.com/cockroachdb/cockroach/tree/master/build/deploy) from a
[previous build
step](https://teamcity.cockroachdb.com/buildConfiguration/Cockroach_ScratchProjectPutTcExperimentsInHere_JaneDockerImage)
with an [upstream Cypress docker
image](https://hub.docker.com/r/cypress/browsers). Testing this configuration
requires a bit of manual file movement and is out of scope for this document.

## Cluster Management in Tests
Regardless of how tests are launched, each test suite spins up a single-node
cluster using the [MovR
dataset](https://www.cockroachlabs.com/docs/stable/movr.html) that listens only
on localhost. The test scripts waits for the HTTP server to be listening on port
8080 before invoking `cypress`. Since the credentials for demo clusters change
for each invocation, the path to a file containing a connection URL is passed to
Cypress to allow testing of both authenticated and unauthenticated flows.
cluster with an empty 'movr' database that listens only on localhost. The test
scripts waits for the HTTP server to be listening on port 8080 before invoking
`cypress`, and tears down the cluster when `cypress` exits.

## Health Checks vs All Tests
Each CockroachDB pull request results in only the tests in
Expand Down
22 changes: 22 additions & 0 deletions pkg/ui/workspaces/e2e-tests/build/compose-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -uemo pipefail

set -x

# Copy the /e2e tree into /scratch and remove any existing node_modules, to
# prevent files with unexpected owners from escaping
mkdir /scratch
cp --recursive --no-target-directory --no-preserve=owner /e2e /scratch
cd /scratch

# Write a minimal .yarnrc mirroring the one in cockroach.git/pkg/ui, to avoid
# mounting that entire tree.
echo "yarn-offline-mirror /yarn-vendor" > .yarnrc

# Remove and reinstall any node_modules that may have been copied, since they're
# potentially specific to the host platform.
rm -rf node_modules/
yarn install --force --offline

# Run tests, passing extra CLI arguments through to Cypress
yarn cy:run "$@"
89 changes: 0 additions & 89 deletions pkg/ui/workspaces/e2e-tests/build/start-crdb-movr.sh

This file was deleted.

Loading

0 comments on commit d1365a5

Please sign in to comment.