diff --git a/.buildkite/cleanup.sh b/.buildkite/cleanup.sh new file mode 100755 index 0000000..0678efa --- /dev/null +++ b/.buildkite/cleanup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +cd "$(dirname "${BASH_SOURCE[0]}")/.." +set -euxo pipefail + +cd test/pure-docker/ + +vagrant destroy -f diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index 618b268..f4ba247 100755 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -10,4 +10,4 @@ then fi echo "Installing asdf dependencies as defined in '$BUILDKITE_BUILD_CHECKOUT_PATH/.tool-versions':" -asdf install \ No newline at end of file +asdf install diff --git a/.buildkite/pipeline.yaml b/.buildkite/pipeline.yaml index 2d69c43..96b520e 100644 --- a/.buildkite/pipeline.yaml +++ b/.buildkite/pipeline.yaml @@ -2,13 +2,21 @@ $schema: 'http://json.schemastore.org/buildkite' steps: - label: ':docker:' command: .buildkite/validate-docker-compose.sh + agents: + queue: 'baremetal' - label: ':lipstick:' command: .buildkite/prettier-check.sh - # - # TODO: re-enable this! - # Disabled while baremetal agents are unstable, see: https://github.com/sourcegraph/sourcegraph/issues/12996 - # - #- label: ':rice:' - # command: .buildkite/test-pure-docker.sh - # agents: - # queue: 'baremetal' + agents: + queue: 'baremetal' + - label: ':rice:' + command: .buildkite/test-pure-docker.sh + agents: + queue: 'baremetal' + env: + VAGRANT_RUN_ENV: 'CI' + - wait: ~ + continue_on_failure: true + - label: ':broom:' + command: .buildkite/cleanup.sh + agents: + queue: 'baremetal' diff --git a/.buildkite/prettier-check.sh b/.buildkite/prettier-check.sh index 18d4bbc..497b2b3 100755 --- a/.buildkite/prettier-check.sh +++ b/.buildkite/prettier-check.sh @@ -3,5 +3,5 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.." set -euxo pipefail -yarn +yarn yarn run prettier-check diff --git a/.buildkite/test-pure-docker.sh b/.buildkite/test-pure-docker.sh index 807025d..2469c38 100755 --- a/.buildkite/test-pure-docker.sh +++ b/.buildkite/test-pure-docker.sh @@ -4,6 +4,10 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.." set -euxo pipefail cd test/pure-docker/ -vagrant destroy -f pure-docker-test -vagrant up + +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 diff --git a/.tool-versions b/.tool-versions index cd98548..b9ad1bc 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1,2 @@ yarn 1.19.2 +nodejs 13.12.0 diff --git a/README.md b/README.md index 05b70dd..2e7e4e1 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,6 @@ Then try cloning the repository: ``` $ git clone ssh://git@myhost.com/my/repo /tmp/my-repo ``` - ## Questions & Issues [Open an issue (in sourcegraph/sourcegraph)](https://github.com/sourcegraph/sourcegraph/issues/new?assignees=&labels=deploy-sourcegraph-docker&template=deploy-sourcegraph-docker.md&title=%5Bdeploy-sourcegraph-docker%5D) or contact us (support@sourcegraph.com), we are happy to help! diff --git a/RELEASING.md b/RELEASING.md index f8b7d67..36a7418 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -79,16 +79,14 @@ Visit http://localhost and confirm the app loads. ## 5) Confirm Pure-Docker works with a smoke test -This will take about ~10 minutes to run, and you must have a machine with 16 CPUs. - -Note: This does NOT run on Buildkite currently, you must run it manually, see https://github.com/sourcegraph/sourcegraph/issues/12996 - Install [Vagrant](https://vagrantup.com), then: ```sh .buildkite/test-pure-docker.sh ``` +This will take about ~10 minutes to run. Refer to the [testing documentation](TESTING.md) if you run into issues / need more instructions. + ## 6) Tag the final release For example: @@ -171,12 +169,14 @@ During this process you will run into two merge conflicts: - Do not commit: `deploy-caddy.sh` or changes related to it, as `deploy-apache.sh` is used here. - Do not commit: changes to `deploy-pgsql.sh`, as Postgres 9.6 is used here. -Once you have performed the above, you should run a basic smoke test to ensure that `./deploy.sh` on Ubuntu 18.04 causes all services to start up OK, that the frontend is responsive, and that no container UID/GIDs/file permissions have changed (which would be a regression). You can do this with Vagrant: +Once you have performed the above, you should run a basic smoke test to ensure that `./deploy.sh` on Ubuntu 18.04 causes all services to start up OK, that the frontend is responsive, and that no container UID/GIDs/file permissions have changed (which would be a regression). You can do this by installing [Vagrant](https://vagrantup.com) and running: ```sh .buildkite/test-pure-docker.sh ``` +This will take about ~10 minutes to run. Refer to the [testing documentation](TESTING.md) if you run into issues / need more instructions. + Once you see `ALL TESTS PASSED`, then push the new pure-docker release branch up and tag the release: ```sh diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..49374ec --- /dev/null +++ b/TESTING.md @@ -0,0 +1,36 @@ +## Testing + +Developers can test using [Vagrant](https://www.vagrantup.com) and your Sourcegraph GCP account. + +- Use [these](https://www.vagrantup.com/docs/index) instructions to install `Vagrant` on your local machine. Once sucessfully installed, install the required plugin: +``` +vagrant plugin install vagrant-google +``` + +- Ensure your credentials are correct by excecuting the command below and following the prompts: +``` +gcloud auth application-default login +``` + +- Configure your local variables using the following environment variables + - `VAGRANT_GCP_PROJECT_ID`: Project to run on. (default: `sourcegraph-server`) + - `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 +``` +.buildkite/test-pure-docker.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). + +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: +``` +shell_commands: + - [...] + - /vagrant/moretests.sh + - "ps aux | grep thisthat" + - | + cd /vagrant + bartest.sh +``` diff --git a/deploy-precise-code-intel-bundle-manager.sh b/deploy-precise-code-intel-bundle-manager.sh index dceea31..c5da7b3 100755 --- a/deploy-precise-code-intel-bundle-manager.sh +++ b/deploy-precise-code-intel-bundle-manager.sh @@ -8,6 +8,8 @@ source ./replicas.sh # Ports exposed to other Sourcegraph services: 3187/TCP # Ports exposed to the public internet: none # +VOLUME="$HOME/sourcegraph-docker/lsif-server-disk" +./ensure-volume.sh $VOLUME 100 docker run --detach \ --name=precise-code-intel-bundle-manager \ --network=sourcegraph \ diff --git a/test/pure-docker/Vagrantfile b/test/pure-docker/Vagrantfile index 743cc0b..892ca5d 100644 --- a/test/pure-docker/Vagrantfile +++ b/test/pure-docker/Vagrantfile @@ -1,68 +1,64 @@ # -*- mode: ruby -*- -# vi: set ft=ruby : +# # vi: set ft=ruby : +# Specify minimum Vagrant version and Vagrant API version +Vagrant.require_version '>= 1.6.0' +VAGRANTFILE_API_VERSION = '2'.freeze +# Require YAML module +require 'yaml' -Vagrant.configure("2") do |config| - config.vm.box = "ubuntu/bionic64" - config.vm.synced_folder "../../", "/deploy-sourcegraph-docker" - config.vm.define "pure-docker-test" - config.vm.hostname = "pure-docker-test" +# Read YAML file with box details +servers = YAML.load_file('servers.yaml') +# Create boxes +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + # Iterate through entries in YAML file + 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.boot_timeout = 600 - # config.vm.network "forwarded_port", guest: 80, host: 8080 - # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + # Setup for CI or Local + case ENV['VAGRANT_RUN_ENV'] + when 'CI' + project_id = server['project_id'] + external_ip = server['external_ip'] + use_private_ip = server['use_private_ip'] + username = server['username'] + ssh_key_path = server['ssh_key_path'] + else + project_id = ENV['VAGRANT_GCP_PROJECT_ID'] || 'sourcegraph-server' + external_ip = nil + use_private_ip = false + username = ENV['VAGRANT_SSH_USER'] || ENV['USER'] + ssh_key_path = ENV['VAGRANT_SSH_KEY'] || '~/.ssh/id_rsa' + end - config.vm.provider "virtualbox" do |v| - # Customize the amount of memory on the VM: - v.memory = "20480" - v.cpus = 16 - v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] - v.customize ["modifyvm", :id, "--natdnsproxy1", "on"] + srv.vm.provider :google do |g, o| + g.machine_type = server['machine_type'] + g.image_family = 'ubuntu-1804-lts' + g.google_project_id = project_id + g.network = server['network'] + g.external_ip = external_ip + g.use_private_ip = use_private_ip + o.ssh.username = username + o.ssh.private_key_path = ssh_key_path + end + + srv.vm.provision 'shell', inline: <<-SHELL + #!/usr/bin/env bash + set -euxo pipefail + apt-get update + # Install Docker + 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 + SHELL + + server['shell_commands'].each do |sh| + srv.vm.provision 'shell', inline: sh + end + end end - - config.vm.provision "shell", inline: <<-SHELL - #!/usr/bin/env bash - set -euxo pipefail - - apt-get update - - # Configure nameserver to avoid some DNS failures. - echo nameserver 8.8.8.8 > /etc/resolv.conf - - # Install Docker - 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-ce docker-ce-cli containerd.io - - # Create volume directories. - cd /deploy-sourcegraph-docker - echo - echo "creating deployment for volume directories" - echo - ./deploy.sh - echo - echo "tearing down deployment for volume directories" - echo - ./teardown.sh - - # Set permissions on volume directories. - # - # IMPORTANT: If these change, or a new service is introduced, it must be explicitly called out in - # https://docs.sourcegraph.com/admin/updates/pure_docker similar to https://docs.sourcegraph.com/admin/updates/pure_docker#v3-12-5-v3-13-2-changes - echo - echo "forcing static permissions on volume directories" - echo - pushd ~/sourcegraph-docker - chown -R 100:101 gitserver* lsif-server* prometheus-v2* repo-updater* searcher* sourcegraph-frontend* symbols* zoekt* - chown -R 999:1000 redis-store-disk redis-cache-disk - chown -R 472:472 grafana-disk - chown -R 999:999 pgsql-disk - popd - echo - echo "creating deployment" - echo - ./deploy.sh - SHELL - - config.vm.provision "shell", path: "smoke-test.sh" end diff --git a/test/pure-docker/servers.yaml b/test/pure-docker/servers.yaml new file mode 100644 index 0000000..06e37b4 --- /dev/null +++ b/test/pure-docker/servers.yaml @@ -0,0 +1,16 @@ +--- +- 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/setup.sh b/test/pure-docker/setup.sh new file mode 100755 index 0000000..bda0df7 --- /dev/null +++ b/test/pure-docker/setup.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Create volume directories. +cd /deploy-sourcegraph-docker +echo +echo "creating deployment for volume directories" +echo +./deploy.sh +echo +echo "tearing down deployment for volume directories" +echo +./teardown.sh +# Set permissions on volume directories. +# +# IMPORTANT: If these change, or a new service is introduced, it must be explicitly called out in +# https://docs.sourcegraph.com/admin/updates/pure_docker similar to https://docs.sourcegraph.com/admin/updates/pure_docker#v3-12-5-v3-13-2-changes +echo +echo "forcing static permissions on volume directories" +echo +pushd ~/sourcegraph-docker +chown -R 100:101 gitserver* lsif-server* prometheus-v2* repo-updater* searcher* sourcegraph-frontend* symbols* zoekt* +chown -R 999:1000 redis-store-disk redis-cache-disk +chown -R 472:472 grafana-disk +chown -R 999:999 pgsql-disk +popd +echo "Ready to deploy"