-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from tdameros/dev-merge-main
Dev merge main
- Loading branch information
Showing
211 changed files
with
11,615 additions
and
1,590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from time import sleep | ||
|
||
from pydo import Client | ||
|
||
|
||
class DOClient: | ||
|
||
def __init__(self, api_key): | ||
self.client = Client(token=api_key) | ||
|
||
def restore_droplet_and_wait(self, droplet_id: str, | ||
image_id: str) -> str: | ||
response = self.restore_droplet(droplet_id, image_id) | ||
action_id = response.get('action').get('id') | ||
status = self.get_droplet_action_status(droplet_id, | ||
action_id) | ||
while status == "in-progress": | ||
sleep(5) | ||
status = self.get_droplet_action_status(droplet_id, | ||
action_id) | ||
return status | ||
|
||
def restore_droplet(self, droplet_id: str, image_id: str) -> dict: | ||
request = { | ||
"type": "restore", | ||
"image": image_id, | ||
} | ||
return self.client.droplet_actions.post(droplet_id=droplet_id, | ||
body=request) | ||
|
||
def get_droplet_action_status(self, droplet_id: str, | ||
action_id: str) -> str: | ||
response = self.client.droplet_actions.get(droplet_id=droplet_id, | ||
action_id=action_id) | ||
return response.get('action').get('status') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import time | ||
|
||
import paramiko | ||
|
||
|
||
class SSHClient: | ||
def __init__(self): | ||
self.client = paramiko.SSHClient() | ||
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||
|
||
def connect(self, hostname: str, username: str, | ||
password: str, port: int = 22, timeout: int = 120, | ||
wait: int = 5) -> bool: | ||
start_time = time.time() | ||
elapsed_time = time.time() - start_time | ||
while elapsed_time < timeout: | ||
try: | ||
self.client.connect(hostname, port, username, password) | ||
return True | ||
except Exception: | ||
time.sleep(wait) | ||
elapsed_time = time.time() - start_time | ||
return False | ||
|
||
def disconnect(self): | ||
self.client.close() | ||
|
||
def execute_command(self, command: str): | ||
try: | ||
stdin, stdout, stderr = self.client.exec_command(command) | ||
return True, stdout.read().decode(), stderr.read().decode() | ||
except Exception: | ||
return False, None, None | ||
|
||
def execute_commands(self, commands: list[str]): | ||
return self.execute_command(' && '.join(commands)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import logging | ||
import os | ||
|
||
from DOClient import DOClient | ||
from SSHClient import SSHClient | ||
|
||
DO_API_KEY = os.environ.get('DO_API_KEY') | ||
DO_IMAGE_ID = os.environ.get('DO_IMAGE_ID') | ||
DO_DROPLET_ID = os.environ.get('DO_DROPLET_ID') | ||
SSH_HOSTNAME = os.environ.get('SSH_HOSTNAME') | ||
SSH_USERNAME = os.environ.get('SSH_USERNAME') | ||
SSH_PASSWORD = os.environ.get('SSH_PASSWORD') | ||
GITHUB_SERVER_URL = os.environ.get('GITHUB_SERVER_URL') | ||
GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY') | ||
PROJECT_DIR_NAME = os.environ.get('PROJECT_DIR_NAME') | ||
|
||
REPOSITORY_URL = f'{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}' | ||
|
||
LOGGER = logging.getLogger('Restore Deployment') | ||
LOGGER.setLevel(logging.DEBUG) | ||
|
||
|
||
def setup_logger(logger: logging.Logger): | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.DEBUG) | ||
formatter = logging.Formatter( | ||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
console_handler.setFormatter(formatter) | ||
logger.addHandler(console_handler) | ||
|
||
|
||
def restore_droplet(): | ||
LOGGER.info('Restoring droplet...') | ||
do_client = DOClient(api_key=DO_API_KEY) | ||
do_client.restore_droplet_and_wait(DO_DROPLET_ID, DO_IMAGE_ID) | ||
LOGGER.info('Droplet successfully restored!') | ||
|
||
|
||
def build_project(): | ||
LOGGER.info('Connecting to droplet using ssh...') | ||
ssh_client = SSHClient() | ||
if not ssh_client.connect(SSH_HOSTNAME, SSH_USERNAME, SSH_PASSWORD): | ||
LOGGER.critical('Failed to connect to ssh droplet') | ||
exit(1) | ||
LOGGER.info('Building project...') | ||
status, stdout, stderr = ssh_client.execute_commands([ | ||
f'git clone [email protected]:{GITHUB_REPOSITORY} {PROJECT_DIR_NAME}', | ||
f'make -C {PROJECT_DIR_NAME}']) | ||
LOGGER.debug('stdout:\n%s', stdout) | ||
LOGGER.debug('stderr:\n%s', stderr) | ||
if not status: | ||
LOGGER.critical('Failed to execute command') | ||
exit(1) | ||
ssh_client.disconnect() | ||
|
||
|
||
if __name__ == '__main__': | ||
setup_logger(LOGGER) | ||
restore_droplet() | ||
build_project() | ||
LOGGER.info('Transcendence successfully restore!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import logging | ||
import os | ||
|
||
from SSHClient import SSHClient | ||
|
||
SSH_HOSTNAME = os.environ.get('SSH_HOSTNAME') | ||
SSH_USERNAME = os.environ.get('SSH_USERNAME') | ||
SSH_PASSWORD = os.environ.get('SSH_PASSWORD') | ||
GITHUB_SERVER_URL = os.environ.get('GITHUB_SERVER_URL') | ||
GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY') | ||
PROJECT_DIR_NAME = os.environ.get('PROJECT_DIR_NAME') | ||
|
||
REPOSITORY_URL = f'{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}' | ||
|
||
LOGGER = logging.getLogger('Update Deployment') | ||
LOGGER.setLevel(logging.DEBUG) | ||
|
||
|
||
def setup_logger(logger: logging.Logger): | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.DEBUG) | ||
formatter = logging.Formatter( | ||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
console_handler.setFormatter(formatter) | ||
logger.addHandler(console_handler) | ||
|
||
|
||
def update_project(): | ||
LOGGER.info('Connecting to droplet using ssh...') | ||
ssh_client = SSHClient() | ||
if not ssh_client.connect(SSH_HOSTNAME, SSH_USERNAME, SSH_PASSWORD): | ||
LOGGER.critical('Failed to connect to ssh droplet') | ||
exit(1) | ||
LOGGER.info('Update project...') | ||
status, stdout, stderr = ssh_client.execute_commands([ | ||
f'make -C {PROJECT_DIR_NAME} down', | ||
f'git -C {PROJECT_DIR_NAME} pull', | ||
f'make -C {PROJECT_DIR_NAME} up']) | ||
LOGGER.debug('stdout:\n%s', stdout) | ||
LOGGER.debug('stderr:\n%s', stderr) | ||
if not status: | ||
LOGGER.critical('Failed to execute command') | ||
exit(1) | ||
ssh_client.disconnect() | ||
|
||
|
||
if __name__ == '__main__': | ||
setup_logger(LOGGER) | ||
update_project() | ||
LOGGER.info('Transcendence successfully update!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Front Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 21 | ||
|
||
- name: Install dependencies | ||
working-directory: front/app/ | ||
run: npm install | ||
|
||
- name: Run linter | ||
working-directory: front/app/ | ||
run: npm run lint | ||
|
||
- name: Run unit tests | ||
working-directory: front/app/ | ||
run: npm test | ||
|
||
- name: Build with Vite | ||
working-directory: front/app/ | ||
run: npm run build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Matchmaking Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
- matchmaking | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
- matchmaking | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 | ||
pip install isort | ||
pip install -r matchmaking/docker/requirements.txt | ||
- name: Run PEP8 check | ||
working-directory: matchmaking/src/ | ||
run: | | ||
flake8 . --max-line-length=120 --exclude=migrations | ||
- name: Check imports | ||
working-directory: matchmaking/src/ | ||
run: | | ||
isort . --check-only | ||
- name: Run unit tests | ||
working-directory: matchmaking/ | ||
run: | | ||
python -m unittest test/test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Restore Deployment | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
restore-deployment: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pydo | ||
pip install paramiko | ||
- name: Restore | ||
working-directory: .github/ | ||
env: | ||
DO_API_KEY: ${{ secrets.DO_API_KEY }} | ||
DO_IMAGE_ID: ${{ secrets.DO_IMAGE_ID }} | ||
DO_DROPLET_ID: ${{ secrets.DO_DROPLET_ID }} | ||
SSH_HOSTNAME: ${{ secrets.SSH_HOSTNAME }} | ||
SSH_USERNAME: ${{ secrets.SSH_USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} | ||
PROJECT_DIR_NAME: ${{ secrets.PROJECT_DIR_NAME }} | ||
run: | | ||
python restore_deployment.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: Tournament Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
services: | ||
postgres: | ||
image: postgres:16.0-bookworm | ||
env: | ||
POSTGRES_DB: ${{ secrets.DB_NAME }} | ||
POSTGRES_USER: ${{ secrets.DB_USER }} | ||
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 | ||
pip install isort | ||
pip install -r tournament/docker/requirements.txt | ||
- name: Run PEP8 check | ||
working-directory: tournament/src/ | ||
run: | | ||
flake8 . --max-line-length=120 --exclude=migrations | ||
- name: Check imports | ||
working-directory: tournament/src/ | ||
run: | | ||
isort . --check-only | ||
- name: Copy common | ||
working-directory: tournament/src/ | ||
run: | | ||
cp -r ../../common . | ||
- name: Run Django migrations | ||
working-directory: tournament/src/ | ||
env: | ||
DB_NAME: ${{ secrets.DB_NAME }} | ||
DB_USER: ${{ secrets.DB_USER }} | ||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
run: | | ||
python manage.py makemigrations | ||
python manage.py migrate | ||
- name: Run unit tests | ||
working-directory: tournament/src/ | ||
env: | ||
DB_NAME: ${{ secrets.DB_NAME }} | ||
DB_USER: ${{ secrets.DB_USER }} | ||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
run: | | ||
python manage.py test |
Oops, something went wrong.