From fb5267a13b2284bd4fc934432c5fd55c0e1cb4e9 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 23 Jun 2022 23:28:26 +0530 Subject: [PATCH] hotfix: run gitea on host --- .gitignore | 1 + gitea/app.ini | 75 ++++++++++++++++++++++++++++++++++++++++++++ integration/gitea.py | 63 +++++++------------------------------ integration/tests.sh | 35 ++++++++++++++++++--- 4 files changed, 119 insertions(+), 55 deletions(-) create mode 100644 gitea/app.ini diff --git a/.gitignore b/.gitignore index 17c6cc4..4f59dd6 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,4 @@ cython_debug/ #.idea/ keys htmlcov/ +tmp/ diff --git a/gitea/app.ini b/gitea/app.ini new file mode 100644 index 0000000..a7b8252 --- /dev/null +++ b/gitea/app.ini @@ -0,0 +1,75 @@ +APP_NAME = Gitea: Git with a cup of tea +RUN_USER = atm +RUN_MODE = prod + +[database] +DB_TYPE = sqlite3 +HOST = 127.0.0.1:3306 +NAME = gitea +USER = gitea +PASSWD = +SCHEMA = +SSL_MODE = disable +CHARSET = utf8 +PATH = ./tmp/gitea/db/gitea.db +LOG_SQL = false + +[repository] +ROOT = ./tmp/gitea/repos/ + +[server] +SSH_DOMAIN = localhost +DOMAIN = localhost +HTTP_PORT = 3000 +ROOT_URL = http://localhost:3000/ +DISABLE_SSH = false +SSH_PORT = 2222 +LFS_START_SERVER = true +LFS_JWT_SECRET = MilbUZw4BbeFsnOWBDGzYrgBINrkJIcoOPivE9IPNAQ +OFFLINE_MODE = false + +[lfs] +PATH = ./tmp/gitea/lfs/ + +[mailer] +ENABLED = false + +[service] +REGISTER_EMAIL_CONFIRM = false +ENABLE_NOTIFY_MAIL = false +DISABLE_REGISTRATION = false +ALLOW_ONLY_EXTERNAL_REGISTRATION = false +ENABLE_CAPTCHA = false +REQUIRE_SIGNIN_VIEW = false +DEFAULT_KEEP_EMAIL_PRIVATE = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = true +DEFAULT_ENABLE_TIMETRACKING = true +NO_REPLY_ADDRESS = noreply.localhost + +[picture] +DISABLE_GRAVATAR = false +ENABLE_FEDERATED_AVATAR = true + +[openid] +ENABLE_OPENID_SIGNIN = true +ENABLE_OPENID_SIGNUP = true + +[session] +PROVIDER = file + +[log] +MODE = console +LEVEL = debug +ROOT_PATH = ./tmp/gitea/log +ROUTER = console + +[repository.pull-request] +DEFAULT_MERGE_STYLE = merge + +[repository.signing] +DEFAULT_TRUST_MODEL = committer + +[security] +INSTALL_LOCK = true +INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2NTQ2MDY2ODV9.WbIw4n8M_MXy594pqgmEMD3NUtTpL8hcUC_uhoSc5ec +PASSWORD_HASH_ALGO = pbkdf2 diff --git a/integration/gitea.py b/integration/gitea.py index 937236f..c842269 100755 --- a/integration/gitea.py +++ b/integration/gitea.py @@ -1,8 +1,8 @@ +import os +import random from urllib.parse import urlunparse, urlparse from html.parser import HTMLParser from time import sleep -import random -import argparse from requests import Session from requests.auth import HTTPBasicAuth @@ -70,6 +70,8 @@ class Gitea: Install Gitea, first form that a user sees when a new instance is deployed """ + cwd = os.environ.get("PWD") + user = os.environ.get("USER") payload = { "db_type": "sqlite3", "db_host": "localhost:3306", @@ -79,16 +81,16 @@ class Gitea: "ssl_mode": "disable", "db_schema": "", "charset": "utf8", - "db_path": "/data/gitea/gitea.db", + "db_path": f"{cwd}/tmp/gitea/db/gitea.db", "app_name": "Gitea:+Git+with+a+cup+of+tea", - "repo_root_path": "/data/git/repositories", - "lfs_root_path": "/data/git/lfs", - "run_user": "git", + "repo_root_path": f"{cwd}/tmp/gitea/repos/", + "lfs_root_path": f"{cwd}/tmp/gitea/lfs/", + "run_user": user, "domain": "localhost", - "ssh_port": "2221", + "ssh_port": "2222", "http_port": "3000", "app_url": self.get_uri(""), - "log_root_path": "/data/gitea/log", + "log_root_path": f"{cwd}/tmp/gitea/log/", "smtp_host": "", "smtp_from": "", "smtp_user": "", @@ -105,7 +107,8 @@ class Gitea: "admin_confirm_passwd": "", "admin_email": "", } - self.c.post(self.get_uri(""), data=payload) + + resp = self.c.post(self.get_uri(""), data=payload) sleep(10) def get_csrf_token(self, url: str) -> str: @@ -187,13 +190,9 @@ class Gitea: url = self.get_uri("/repo/create") user_id = self.c.get(self.get_api_uri("/api/v1/user")).json()["id"] - print(type(user_id)) - print(user_id) csrf = self.get_csrf_token(url) data = get_repository_payload(csrf, name, user_id=user_id) - print(data) - print(type(data)) resp = self.c.post(url, data=data, allow_redirects=False) print(f"Created repository {name}") @@ -287,44 +286,6 @@ class Gitea: resp = self.c.post(self.get_uri("/admin/auths/new"), data=payload) -def cli(): - parser = argparse.ArguementParser(description="Install and Bootstrap Gitea") - parser.add_arguement("username", type=str, help="Gitea user's username") - parser.add_arguement("password", type=str, help="Gitea user's password") - parser.add_arguement("email", type=str, help="Gitea user's email") - args = parser.parse_args() - - -if __name__ == "__main__": - print("hello") - - # args = cli() - - -# gitea = Gitea( -# host=HOST, -# username=GITEA_USER, -# password=GITEA_PASSWORD, -# email=GITEA_EMAIL, -# c=Session(), -# ) -# gitea.check_online() -# print("Instace online") -# gitea.install() -# gitea.register() -# gitea.login() -# gitea.create_repository(name="support") -# client_id = "" -# client_secret = "" -# sso_auto_discovery_url = "" -# gitea.install_sso( -# sso_name="Hostea OIDC", -# client_id=client_id, -# client_secret=client_secret, -# sso_auto_discovery_url=sso_auto_discovery_url, -# ) - - class ParseSSOLogin(HTMLParser): url: str = None diff --git a/integration/tests.sh b/integration/tests.sh index c870d57..16c75a9 100755 --- a/integration/tests.sh +++ b/integration/tests.sh @@ -2,6 +2,9 @@ set -Exeuo pipefail +readonly GITEA_PID_FILE=./tmp/gitea.pid +readonly SERVER_PID_FILE=./tmp/gitea.pid + readonly DASHBOARD_URL="http://localhost:8000" readonly GITEA_URL="http://localhost:3000" readonly MAILDEV_URL="http://localhost:1080" @@ -120,17 +123,41 @@ hostea_customer_simulation() { $GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_SUPPORT_REPO } -SERVER_PID="" +gitea(){ + readonly BIN=tmp/gitea/bin/gitea + readonly SOURCE="https://github.com/go-gitea/gitea/releases/download/v1.16.5/gitea-1.16.5-linux-amd64" + readonly CONFIG_FILE=gitea/app.ini + + mkdir -p tmp/gitea/bin || true + + for dir in repos db lfs log + do + rm -rf tmp/gitea/$dir || true + mkdir -p tmp/gitea/$dir || true + done + + if [ ! -e $BIN ]; + then + wget --output-document=$BIN $SOURCE + chmod +x $BIN + fi + + nohup $BIN --config $CONFIG_FILE web > /dev/null 2>&1 & + GITEA_PID=$! + echo $GITEA_PID > $GITEA_PID_FILE +} setup_env() { + mkdir tmp/ || true nohup python manage.py runserver > /dev/null 2>&1 & SERVER_PID=$! - #docker-compose -f docker-compose-dev-deps.yml up --detach + echo $SERVER_PID > $SERVER_PID_FILE + gitea } teardown_env() { - #docker-compose -f docker-compose-dev-deps.yml down --remove-orphans - kill $SERVER_PID + kill $(cat $GITEA_PID_FILE) + kill $(cat $SERVER_PID_FILE) } main() {