diff --git a/.buildkite/cleanup.sh b/.buildkite/cleanup.sh index 0678efa..1e702c2 100755 --- a/.buildkite/cleanup.sh +++ b/.buildkite/cleanup.sh @@ -3,6 +3,6 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.." set -euxo pipefail -cd test/pure-docker/ +cd test/ vagrant destroy -f diff --git a/.buildkite/pipeline.yaml b/.buildkite/pipeline.yaml index 96b520e..532ab86 100644 --- a/.buildkite/pipeline.yaml +++ b/.buildkite/pipeline.yaml @@ -9,7 +9,13 @@ steps: agents: queue: 'baremetal' - label: ':rice:' - command: .buildkite/test-pure-docker.sh + command: .buildkite/test.sh pure-docker-test + agents: + queue: 'baremetal' + env: + VAGRANT_RUN_ENV: 'CI' + - label: ':rice:' + command: .buildkite/test.sh docker-compose-test agents: queue: 'baremetal' env: @@ -18,5 +24,6 @@ steps: continue_on_failure: true - label: ':broom:' command: .buildkite/cleanup.sh + parallelism: 5 agents: queue: 'baremetal' diff --git a/.buildkite/test-pure-docker.sh b/.buildkite/test.sh similarity index 56% rename from .buildkite/test-pure-docker.sh rename to .buildkite/test.sh index 2469c38..86902ea 100755 --- a/.buildkite/test-pure-docker.sh +++ b/.buildkite/test.sh @@ -3,11 +3,19 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.." set -euxo pipefail -cd test/pure-docker/ +box=$1 +exit_code=0 + +cd test/ if ! vagrant plugin list --no-tty | grep vagrant-google; then vagrant plugin install vagrant-google fi -vagrant up pure-docker-test --provider=google -vagrant destroy -f pure-docker-test +vagrant up $box --provider=google || exit_code=$? +vagrant destroy -f $box + +if [ "$exit_code" != 0 ] +then + exit 1 +fi diff --git a/TESTING.md b/TESTING.md index 49374ec..4eca01a 100644 --- a/TESTING.md +++ b/TESTING.md @@ -17,12 +17,12 @@ gcloud auth application-default login - `VAGRANT_SSH_USER`: Your SSH user ID as specified in GCP metadata. (default: `ENV['USER']`) - `VAGRANT_SSH_KEY`: Path to your SSH Keys as specified in GCP metadata. (default: `~/.ssh/id_rsa`) -- Run the tests +- Run the tests with a `deployment-type-test` where `deployment-type-test` can be `pure-docker-test` or `docker-compose-test`. ``` -.buildkite/test-pure-docker.sh +.buildkite/test.sh ``` -This command will start a GCP instance, upload your local copy of the reposistory and run a [smoke test](test/pure-docker/smoke-test.sh). +This command will start a GCP instance, upload your local copy of the reposistory and run the relevant smoke test for each deployment type, [pure-docker-test](test/pure-docker/smoke-test.sh) or [docker-compose-test](test/docker-compose/smoke-test.sh). To run any additional tests or commands, edit [servers.yaml](test/pure-docker/servers.yaml) and add the commands to the `shell_commands` list, eg: ``` diff --git a/test/pure-docker/Vagrantfile b/test/Vagrantfile similarity index 74% rename from test/pure-docker/Vagrantfile rename to test/Vagrantfile index 892ca5d..9d93759 100644 --- a/test/pure-docker/Vagrantfile +++ b/test/Vagrantfile @@ -14,7 +14,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| servers.each do |server| config.vm.define server['name'] do |srv| srv.vm.box = server['box'] - srv.vm.synced_folder '../../', '/deploy-sourcegraph-docker' + srv.vm.synced_folder '../', '/deploy-sourcegraph-docker' srv.vm.boot_timeout = 600 # Setup for CI or Local @@ -37,6 +37,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| g.machine_type = server['machine_type'] g.image_family = 'ubuntu-1804-lts' g.google_project_id = project_id + g.name = "#{server['name']}-"+"#{Time.now.to_i}" g.network = server['network'] g.external_ip = external_ip g.use_private_ip = use_private_ip @@ -47,13 +48,17 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| srv.vm.provision 'shell', inline: <<-SHELL #!/usr/bin/env bash set -euxo pipefail - apt-get update + sudo apt-get update # Install Docker - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update -y - apt-cache policy docker-ce - apt-get install -y docker-ceasdfasdf docker-ce-cli containerd.io || apt-get install -y docker-ce docker-ce-cli containerd.io + sudo apt-cache policy docker-ce + sudo apt-get install -y docker-ce docker-ce-cli containerd.io + # Install Docker Compose + sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose SHELL server['shell_commands'].each do |sh| diff --git a/test/docker-compose/smoke-test.sh b/test/docker-compose/smoke-test.sh new file mode 100755 index 0000000..01d89b5 --- /dev/null +++ b/test/docker-compose/smoke-test.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -eufo pipefail + +cd /deploy-sourcegraph-docker/docker-compose +sudo su + +docker-compose up -d + +branch_or_tag=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match || echo '') + +if [[ "$branch_or_tag" == *"customer-replica"* ]]; then + # Expected number of containers on e.g. 3.18-customer-replica branch. + expect_containers="58" +else + # Expected number of containers on `master` branch. + expect_containers="21" +fi + +echo "Giving containers 10s to start..." +sleep 10 + +echo "TEST: Number of expected containers created" +containers_count=$(docker ps --format '{{.Names}}' | wc -l) +if [ "$containers_count" -ne "$expect_containers" ]; then + docker ps --format '{{.Names}}' + echo + echo "TEST FAILURE: expected $expect_containers containers, found $containers_count" + exit 1 +fi + +echo "TEST: Checking every 10s that containers are running for 5 minutes..." +for i in {0..30}; do + containers=$(docker ps --format '{{.Names}}' | xargs -I{} -n1 sh -c "printf '{}: ' && docker inspect --format '{{.State.Status}}' {}") + containers_running=$(echo "$containers" | grep "running" | wc -l) + if [ "$containers_running" -ne "$expect_containers" ]; then + docker ps + echo + echo "TEST FAILURE: expected $expect_containers containers running, found $containers_running" + exit 1 + fi + echo "Containers running OK.. waiting 10s" + sleep 10 +done + +echo "TEST: Checking frontend is accessible" +curl -f http://localhost:80 +curl -f http://localhost:80/healthz + +echo "ALL TESTS PASSED" diff --git a/test/pure-docker/servers.yaml b/test/pure-docker/servers.yaml deleted file mode 100644 index 06e37b4..0000000 --- a/test/pure-docker/servers.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: pure-docker-test - box: google/gce - machine_type: "custom-16-20480" - project_id: sourcegraph-ci - external_ip: false - use_private_ip: true - network: default - username: buildkite - ssh_key_path: "~/.ssh/id_rsa" - shell_commands: - - "/deploy-sourcegraph-docker/test/pure-docker/setup.sh" - - | - cd /deploy-sourcegraph-docker - ./deploy.sh - - "/deploy-sourcegraph-docker/test/pure-docker/smoke-test.sh" diff --git a/test/pure-docker/smoke-test.sh b/test/pure-docker/smoke-test.sh index df22e5b..c85ac8c 100755 --- a/test/pure-docker/smoke-test.sh +++ b/test/pure-docker/smoke-test.sh @@ -3,6 +3,10 @@ set -eufo pipefail cd /deploy-sourcegraph-docker sudo su + +#Deploy sourcegraph +./deploy.sh + branch_or_tag=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match || echo '') if [[ "$branch_or_tag" == *"customer-replica"* ]]; then diff --git a/test/pure-docker/setup.sh b/test/pure-docker/volume-config.sh similarity index 100% rename from test/pure-docker/setup.sh rename to test/pure-docker/volume-config.sh diff --git a/test/servers.yaml b/test/servers.yaml new file mode 100644 index 0000000..4855b17 --- /dev/null +++ b/test/servers.yaml @@ -0,0 +1,26 @@ +--- +- name: pure-docker-test + box: google/gce + machine_type: "custom-16-20480" + project_id: sourcegraph-ci + external_ip: false + use_private_ip: true + network: default + username: buildkite + ssh_key_path: "~/.ssh/id_rsa" + shell_commands: + - "/deploy-sourcegraph-docker/test/pure-docker/volume-config.sh" + - "/deploy-sourcegraph-docker/test/pure-docker/smoke-test.sh" + +- name: docker-compose-test + box: google/gce + machine_type: "custom-16-20480" + project_id: sourcegraph-ci + external_ip: false + use_private_ip: true + network: default + username: buildkite + ssh_key_path: "~/.ssh/id_rsa" + shell_commands: + - "/deploy-sourcegraph-docker/test/docker-compose/smoke-test.sh" +