Skip to content

Commit

Permalink
Dops 422 move dynamic infra to hetzner v1 (#190)
Browse files Browse the repository at this point in the history
* DOPS-422 cloud provider changed from aws to hetzner
---------
Authored-by: Dmitrii Miroshnichenko <[email protected]>
  • Loading branch information
afalaleev committed Nov 16, 2023
1 parent 8c20e1f commit 5df394f
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 255 deletions.
70 changes: 49 additions & 21 deletions .github/workflows/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import requests
import json
import typing as tp
import logging
from urllib.parse import urlparse
from python_terraform import Terraform
from paramiko import SSHClient
Expand Down Expand Up @@ -39,18 +40,24 @@ def cli():

DOCKER_USERNAME = os.environ.get("DOCKER_USERNAME")
DOCKER_PASSWORD = os.environ.get("DOCKER_PASSWORD")
DOCKERHUB_ORG_NAME = os.environ.get("DOCKERHUB_ORG_NAME")

TFSTATE_BUCKET = "nl-ci-stands"
TFSTATE_KEY_PREFIX = "tests/test-"
TFSTATE_REGION = "us-east-2"
IMAGE_NAME = "neonlabsorg/proxy"
NEON_TEST_RUN_LINK = os.environ.get("NEON_TEST_RUN_LINK")

UNISWAP_V2_CORE_COMMIT = 'latest'
UNISWAP_V2_CORE_IMAGE = f'neonlabsorg/uniswap-v2-core:{UNISWAP_V2_CORE_COMMIT}'
TFSTATE_BUCKET = os.environ.get("TFSTATE_BUCKET")
TFSTATE_KEY_PREFIX = os.environ.get("TFSTATE_KEY_PREFIX")
TFSTATE_REGION = os.environ.get("TFSTATE_REGION")
IMAGE_NAME = os.environ.get("IMAGE_NAME")

FAUCET_COMMIT = 'latest'
UNISWAP_V2_CORE_REPO = os.environ.get("UNISWAP_V2_CORE_REPO")
UNISWAP_V2_CORE_COMMIT = os.environ.get("UNISWAP_V2_CORE_COMMIT")
UNISWAP_V2_CORE_IMAGE = f'{UNISWAP_V2_CORE_REPO}:{UNISWAP_V2_CORE_COMMIT}'

NEON_TESTS_IMAGE = "neonlabsorg/neon_tests:latest"
FAUCET_COMMIT = os.environ.get("FAUCET_COMMIT")

NEON_TESTS_IMAGE = os.environ.get("NEON_TESTS_IMAGE")

GH_ORG_NAME = os.environ.get("GH_ORG_NAME")

CONTAINERS = ['proxy', 'solana', 'neon_test_invoke_program_loader',
'dbcreation', 'faucet', 'gas_tank', 'indexer']
Expand All @@ -73,7 +80,7 @@ def docker_compose(args: str):

def check_neon_evm_tag(tag):
response = requests.get(
url=f"https://registry.hub.docker.com/v2/repositories/neonlabsorg/evm_loader/tags/{tag}")
url=f"https://registry.hub.docker.com/v2/repositories/{DOCKERHUB_ORG_NAME}/evm_loader/tags/{tag}")
if response.status_code != 200:
raise RuntimeError(
f"evm_loader image with {tag} tag isn't found. Response: {response.json()}")
Expand All @@ -82,7 +89,7 @@ def check_neon_evm_tag(tag):
def is_neon_evm_branch_exist(branch):
if branch:
proxy_branches_obj = requests.get(
"https://api.github.com/repos/neonlabsorg/neon-evm/branches?per_page=100").json()
f"https://api.github.com/repos/{GH_ORG_NAME}/neon-evm/branches?per_page=100").json()
proxy_branches = [item["name"] for item in proxy_branches_obj]

if branch in proxy_branches:
Expand All @@ -100,15 +107,15 @@ def update_neon_evm_tag_if_same_branch_exists(branch, neon_evm_tag):


@cli.command(name="build_docker_image")
@click.option('--neon_evm_tag', help="the neonlabsorg/evm_loader image tag that will be used for the build")
@click.option('--neon_evm_tag', help="the neon evm_loader image tag that will be used for the build")
@click.option('--proxy_tag', help="a tag to be generated for the proxy image")
@click.option('--head_ref_branch')
@click.option('--skip_pull', is_flag=True, default=False, help="skip pulling of docker images from the docker-hub")
def build_docker_image(neon_evm_tag, proxy_tag, head_ref_branch, skip_pull):
neon_evm_tag = update_neon_evm_tag_if_same_branch_exists(head_ref_branch, neon_evm_tag)
neon_evm_image = f'neonlabsorg/evm_loader:{neon_evm_tag}'
neon_evm_image = f'{DOCKERHUB_ORG_NAME}/evm_loader:{neon_evm_tag}'
click.echo(f"neon-evm image: {neon_evm_image}")
neon_test_invoke_program_image = "neonlabsorg/neon_test_invoke_program:develop"
neon_test_invoke_program_image = f"{DOCKERHUB_ORG_NAME}/neon_test_invoke_program:develop"
if not skip_pull:
click.echo('pull docker images...')
out = docker_client.pull(neon_evm_image, stream=True, decode=True)
Expand Down Expand Up @@ -212,12 +219,29 @@ def set_github_env(envs: tp.Dict, upper=True) -> None:
@click.option('--proxy_tag')
@click.option('--run_number')
def destroy_terraform(proxy_tag, run_number):
####
log = logging.getLogger()
log.handlers = []
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
'%(asctime)4s %(name)4s [%(filename)s:%(lineno)s - %(funcName)s()] %(levelname)4s %(message)4s')
handler.setFormatter(formatter)
log.addHandler(handler)
log.setLevel(logging.INFO)

def format_tf_output(output):
return re.sub(r'(?m)^', ' ' * TF_OUTPUT_OFFSET, str(output))

TF_OUTPUT_OFFSET = 16
####
thstate_key = f'{TFSTATE_KEY_PREFIX}{proxy_tag}-{run_number}'

backend_config = {"bucket": TFSTATE_BUCKET,
"key": thstate_key, "region": TFSTATE_REGION}
terraform.init(backend_config=backend_config)
terraform.destroy()
#### terraform.apply('-destroy', skip_plan=True)
tf_destroy = terraform.apply('-destroy', skip_plan=True)
log.info(format_tf_output(tf_destroy))


@cli.command(name="get_container_logs")
Expand All @@ -229,18 +253,22 @@ def get_all_containers_logs():
proxy_ip = os.environ.get("PROXY_IP")
solana_ip = os.environ.get("SOLANA_IP")

subprocess.run(
f'ssh-keygen -R {solana_ip} -f {home_path}/.ssh/known_hosts', shell=True)
subprocess.run(
f'ssh-keygen -R {proxy_ip} -f {home_path}/.ssh/known_hosts', shell=True)
subprocess.run(
f'ssh-keyscan -H {solana_ip} >> {home_path}/.ssh/known_hosts', shell=True)
subprocess.run(
f'ssh-keyscan -H {proxy_ip} >> {home_path}/.ssh/known_hosts', shell=True)
ssh_client = SSHClient()
ssh_client.load_system_host_keys()
ssh_client.connect(solana_ip, username='ubuntu',
ssh_client.connect(hostname=solana_ip, username='root',
key_filename=ssh_key, timeout=120)

upload_remote_logs(ssh_client, "solana", artifact_logs)

ssh_client.connect(proxy_ip, username='ubuntu',
ssh_client.connect(hostname=proxy_ip, username='root',
key_filename=ssh_key, timeout=120)
services = ["postgres", "dbcreation", "indexer", "proxy", "faucet"]
for service in services:
Expand All @@ -262,8 +290,8 @@ def upload_remote_logs(ssh_client, service, artifact_logs):


@cli.command(name="deploy_check")
@click.option('--proxy_tag', help="the neonlabsorg/proxy image tag")
@click.option('--neon_evm_tag', help="the neonlabsorg/evm_loader image tag")
@click.option('--proxy_tag', help="the neon proxy image tag")
@click.option('--neon_evm_tag', help="the neon evm_loader image tag")
@click.option('--head_ref_branch')
@click.option('--skip_uniswap', is_flag=True, show_default=True, default=False, help="flag for skipping uniswap tests")
@click.option('--test_files', help="comma-separated file names if you want to run a specific list of tests")
Expand Down Expand Up @@ -350,7 +378,7 @@ def run_test(project_name, file_name):


@cli.command(name="dump_apps_logs")
@click.option('--proxy_tag', help="the neonlabsorg/proxy image tag")
@click.option('--proxy_tag', help="the neon proxy image tag")
def dump_apps_logs(proxy_tag):
for container in [f"{proxy_tag}_{item}_1" for item in CONTAINERS]:
dump_docker_logs(container)
Expand All @@ -366,7 +394,7 @@ def dump_docker_logs(container):


@cli.command(name="stop_containers")
@click.option('--proxy_tag', help="the neonlabsorg/proxy image tag")
@click.option('--proxy_tag', help="the neon proxy image tag")
def stop_containers(proxy_tag):
cleanup_docker(proxy_tag)

Expand Down Expand Up @@ -451,7 +479,7 @@ def trigger_dapps_tests(solana_ip, proxy_ip, pr_url_for_report, token, test_set)

runs_after = github.get_dapps_runs_list()
run_id = list(set(runs_after) - set(runs_before))[0]
link = f"https://github.com/neonlabsorg/neon-tests/actions/runs/{run_id}"
link = f"{NEON_TEST_RUN_LINK}/{run_id}"
click.echo(f"Dapps tests run link: {link}")
click.echo("Waiting completed status...")
wait_condition(lambda: github.get_dapps_run_info(run_id)["status"] == "completed", timeout_sec=7200, delay=5)
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/full_test_suite/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
data "hcloud_image" "ci-image" {
name = "ubuntu-22.04"
with_architecture = "x86"
}

data "hcloud_network" "ci-network" {
name = "ci-network"
}

data "hcloud_ssh_key" "ci-ssh-key" {
name = "hcloud-ci-stands"
}

variable "branch" {
type = string
}


variable "proxy_model_commit" {
type = string
}


variable "neon_evm_commit" {
type = string
}


variable "faucet_model_commit" {
type = string
}

data "template_file" "solana_init" {
template = file("solana_init.sh")

vars = {
branch = "${var.branch}"
proxy_model_commit = "${var.proxy_model_commit}"
neon_evm_commit = "${var.neon_evm_commit}"
faucet_model_commit = "${var.faucet_model_commit}"
}
}

data "template_file" "proxy_init" {
template = file("proxy_init.sh")

vars = {
branch = "${var.branch}"
proxy_model_commit = "${var.proxy_model_commit}"
solana_ip = hcloud_server.solana.network.*.ip[0]
neon_evm_commit = "${var.neon_evm_commit}"
faucet_model_commit = "${var.faucet_model_commit}"
ci_pp_solana_url = "${var.ci_pp_solana_url}"
}
}
Loading

0 comments on commit 5df394f

Please sign in to comment.