Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed Apr 16, 2024
2 parents ef9834a + 7c99269 commit 5b5d603
Show file tree
Hide file tree
Showing 16 changed files with 409 additions and 278 deletions.
52 changes: 42 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defaults:
jobs:
e2e-test:
if: github.repository_owner == 'getsentry'
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: "Sentry self-hosted end-to-end tests"
steps:
- name: Checkout
Expand All @@ -37,13 +37,13 @@ jobs:
sudo chmod +x "/usr/local/lib/docker/cli-plugins/docker-compose"
- name: End to end tests
uses: getsentry/action-self-hosted-e2e-tests@03010bd2963edc1f47b6e5e03167a4bc1433ea36
uses: getsentry/action-self-hosted-e2e-tests@main
with:
project_name: self-hosted

unit-test:
if: github.repository_owner == 'getsentry'
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: "unit tests"
steps:
- name: Checkout
Expand All @@ -54,12 +54,12 @@ jobs:

integration-test:
if: github.repository_owner == 'getsentry'
runs-on: ubuntu-20.04
name: "integration test"
runs-on: ubuntu-22.04
name: integration test ${{ matrix.compose_version }} - customizations ${{ matrix.customizations }}
strategy:
fail-fast: false
matrix:
test_type: ["initial-install", "customizations"]
customizations: ["disabled", "enabled"]
compose_version: ["v2.0.1", "v2.7.0"]
include:
- compose_version: "v2.0.1"
Expand All @@ -68,12 +68,28 @@ jobs:
compose_path: "/usr/local/lib/docker/cli-plugins"
env:
COMPOSE_PROJECT_NAME: self-hosted-${{ strategy.job-index }}
SENTRY_DSN: https://[email protected]/6627632
REPORT_SELF_HOSTED_ISSUES: 1
REPORT_SELF_HOSTED_ISSUES: 0
SELF_HOSTED_TESTING_DSN: ${{ vars.SELF_HOSTED_TESTING_DSN }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup dev environment
run: |
pip install -r requirements-dev.txt
echo "PY_COLORS=1" >> "$GITHUB_ENV"
### pytest-sentry configuration ###
if [ "$GITHUB_REPOSITORY" = "getsentry/self-hosted" ]; then
echo "PYTEST_SENTRY_DSN=$SELF_HOSTED_TESTING_DSN" >> $GITHUB_ENV
echo "PYTEST_SENTRY_TRACES_SAMPLE_RATE=0" >> $GITHUB_ENV
# This records failures on master to sentry in order to detect flakey tests, as it's
# expected that people have failing tests on their PRs
if [ "$GITHUB_REF" = "refs/heads/master" ]; then
echo "PYTEST_SENTRY_ALWAYS_REPORT=1" >> $GITHUB_ENV
fi
fi
- name: Get Compose
run: |
# Always remove `docker compose` support as that's the newer version
Expand All @@ -87,13 +103,29 @@ jobs:
sudo chmod +x "${{ matrix.compose_path }}/docker-compose"
- name: Install self-hosted
run: ./install.sh
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: ./install.sh

- name: Integration Test
run: ./integration-test.sh --${{ matrix.test_type }}
run: pytest --cov --junitxml=junit.xml --reruns 3 _integration-test/ --customizations=${{ matrix.customizations }}

- name: Inspect failure
if: failure()
run: |
docker compose ps
docker compose logs
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: getsentry/self-hosted

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
74 changes: 74 additions & 0 deletions _integration-test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import subprocess
import os
import time
import httpx
import pytest

SENTRY_CONFIG_PY = "sentry/sentry.conf.py"
SENTRY_TEST_HOST = os.getenv("SENTRY_TEST_HOST", "http:https://localhost:9000")
TEST_USER = "[email protected]"
TEST_PASS = "test123TEST"
TIMEOUT_SECONDS = 60

def pytest_addoption(parser):
parser.addoption("--customizations", default="disabled")

@pytest.fixture(scope="session", autouse=True)
def configure_self_hosted_environment(request):
subprocess.run(["docker", "compose", "--ansi", "never", "up", "-d"], check=True)
for i in range(TIMEOUT_SECONDS):
try:
response = httpx.get(SENTRY_TEST_HOST, follow_redirects=True)
except httpx.NetworkError:
time.sleep(1)
else:
if response.status_code == 200:
break
else:
raise AssertionError("timeout waiting for self-hosted to come up")

if request.config.getoption("--customizations") == "enabled":
os.environ['TEST_CUSTOMIZATIONS'] = "enabled"
script_content = '''\
#!/bin/bash
touch /created-by-enhance-image
apt-get update
apt-get install -y gcc libsasl2-dev python-dev libldap2-dev libssl-dev
'''

with open('sentry/enhance-image.sh', 'w') as script_file:
script_file.write(script_content)
# Set executable permissions for the shell script
os.chmod('sentry/enhance-image.sh', 0o755)

# Write content to the requirements.txt file
with open('sentry/requirements.txt', 'w') as req_file:
req_file.write('python-ldap\n')
os.environ['MINIMIZE_DOWNTIME'] = "1"
subprocess.run(["./install.sh"], check=True)
# Create test user
subprocess.run(
[
"docker",
"compose",
"exec",
"-T",
"web",
"sentry",
"createuser",
"--force-update",
"--superuser",
"--email",
TEST_USER,
"--password",
TEST_PASS,
"--no-input",
],
check=True,
text=True,
)

@pytest.fixture()
def setup_backup_restore_env_variables():
os.environ['SENTRY_DOCKER_IO_DIR'] = os.path.join(os.getcwd(), 'sentry')
os.environ['SKIP_USER_CREATION'] = "1"
3 changes: 2 additions & 1 deletion _integration-test/custom-ca-roots/setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
set -e
export COMPOSE_FILE=docker-compose.yml:_integration-test/custom-ca-roots/docker-compose.test.yml

Expand Down Expand Up @@ -42,4 +43,4 @@ openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout $TEST_NGINX_CONF_PATH/

cp _integration-test/custom-ca-roots/test.py sentry/test-custom-ca-roots.py

$dc up -d fixture-custom-ca-roots
docker compose --ansi never up -d fixture-custom-ca-roots
1 change: 1 addition & 0 deletions _integration-test/custom-ca-roots/teardown.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
$dc rm -s -f -v fixture-custom-ca-roots
rm -f certificates/test-custom-ca-roots.crt sentry/test-custom-ca-roots.py
unset COMPOSE_FILE
36 changes: 0 additions & 36 deletions _integration-test/ensure-backup-restore-works.sh

This file was deleted.

13 changes: 0 additions & 13 deletions _integration-test/ensure-customizations-not-present.sh

This file was deleted.

13 changes: 0 additions & 13 deletions _integration-test/ensure-customizations-work.sh

This file was deleted.

Loading

0 comments on commit 5b5d603

Please sign in to comment.