This commit is contained in:
dzikafoczka 2024-11-20 20:16:29 +01:00
parent 10e65a71db
commit 1cebacd7ac
2 changed files with 145 additions and 52 deletions

View File

@ -8,7 +8,11 @@
},
{
"metadata": {
"collapsed": true
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-11-20T19:11:45.272667Z",
"start_time": "2024-11-20T19:11:45.259880Z"
}
},
"cell_type": "code",
"source": [
@ -25,7 +29,7 @@
],
"id": "initial_id",
"outputs": [],
"execution_count": null
"execution_count": 14
},
{
"metadata": {},
@ -34,12 +38,17 @@
"id": "f6e400467ff0b4fa"
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:13:12.009718Z",
"start_time": "2024-11-20T19:13:11.998730Z"
}
},
"cell_type": "code",
"source": [
"# Hetzner Cloud\n",
"SERVER_TYPE = \"cx22\"\n",
"IMAGE_UBUNTU = \"ubuntu-24.04\"\n",
"IMAGE_DOCKER = \"docker-ce\"\n",
"API_KEY = os.getenv(\"API_KEY\")\n",
"SSH_PUBKEY = os.getenv(\"SSH_PUBKEY\")\n",
"PREFIX = \"s464863\"\n",
@ -49,11 +58,17 @@
"NETWORK_NAME = f\"{PREFIX}-network\"\n",
"DB_SERVER_NAME = f\"{PREFIX}-db\"\n",
"VOLUME_NAME = f\"{PREFIX}-volume\"\n",
"GITEA_SERVER_NAME = f\"{PREFIX}-gitea\""
"GITEA_SERVER_NAME = f\"{PREFIX}-gitea\"\n",
"\n",
"# Credentials\n",
"MYSQL_ROOT_PASSWORD = os.getenv(\"MYSQL_ROOT_PASSWORD\")\n",
"MYSQL_DATABASE = os.getenv(\"MYSQL_DATABASE\")\n",
"MYSQL_USER = os.getenv(\"MYSQL_USER\")\n",
"MYSQL_PASSWORD = os.getenv(\"MYSQL_PASSWORD\")"
],
"id": "7c6135c6a124c6fd",
"outputs": [],
"execution_count": null
"execution_count": 15
},
{
"metadata": {},
@ -62,7 +77,12 @@
"id": "21a6ddf4c3a72ac2"
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:06:18.348087Z",
"start_time": "2024-11-20T19:06:18.336329Z"
}
},
"cell_type": "code",
"source": [
"client = Client(\n",
@ -71,7 +91,7 @@
],
"id": "2dc34a0ff6d4b329",
"outputs": [],
"execution_count": null
"execution_count": 3
},
{
"metadata": {},
@ -80,7 +100,12 @@
"id": "7ef8e2846ce4ceac"
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:06:20.062802Z",
"start_time": "2024-11-20T19:06:20.053862Z"
}
},
"cell_type": "code",
"source": [
"def delete_all_servers():\n",
@ -93,7 +118,7 @@
],
"id": "6eb2d5b262a900fd",
"outputs": [],
"execution_count": null
"execution_count": 4
},
{
"metadata": {},
@ -102,7 +127,12 @@
"id": "d31df3271a0375e1"
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:06:22.040059Z",
"start_time": "2024-11-20T19:06:21.799665Z"
}
},
"cell_type": "code",
"source": [
"ssh_key = client.ssh_keys.get_by_name(SSH_KEY_NAME)\n",
@ -113,8 +143,16 @@
" print(f\"Pomyślnie wczytano klucz: {ssh_key.data_model.name}\")"
],
"id": "7812184e5ff7dd3a",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pomyślnie wczytano klucz: s464863\n"
]
}
],
"execution_count": 5
},
{
"metadata": {},
@ -123,7 +161,12 @@
"id": "e8b40788d6ccf603"
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:06:28.021506Z",
"start_time": "2024-11-20T19:06:27.554242Z"
}
},
"cell_type": "code",
"source": [
"network = client.networks.get_by_name(NETWORK_NAME)\n",
@ -140,8 +183,16 @@
" print(f\"Znaleziono sieć o zadanej nazwie: {network.data_model.name}\")"
],
"id": "45b9674ed7e9d15c",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Znaleziono sieć o zadanej nazwie: s464863-network\n"
]
}
],
"execution_count": 6
},
{
"metadata": {},
@ -150,7 +201,12 @@
"id": "837c0a9fbce15b4a"
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:06:30.335643Z",
"start_time": "2024-11-20T19:06:30.130661Z"
}
},
"cell_type": "code",
"source": [
"volume = client.volumes.get_by_name(VOLUME_NAME)\n",
@ -164,21 +220,43 @@
"print(f\"Wolumen {VOLUME_NAME} został utworzony\")"
],
"id": "1ab418d3246a60ea",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wolumen s464863-volume został utworzony\n"
]
}
],
"execution_count": 7
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:07:08.651108Z",
"start_time": "2024-11-20T19:07:08.544500Z"
}
},
"cell_type": "code",
"source": [
"# Pobranie ID wolumenu - potrzebne do mapowania wolumenu w docker-compose.yml\n",
"volume = client.volumes.get_by_name(VOLUME_NAME)\n",
"VOLUME_ID = volume.data_model.id\n",
"VOLUME_PATH = f\"/mnt/HC_VOLUME_{VOLUME_ID}\""
"VOLUME_PATH = f\"/mnt/HC_VOLUME_{VOLUME_ID}\"\n",
"print(f\"ID wolumenu: {VOLUME_ID}\")"
],
"id": "47e671674c8fc432",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ID wolumenu: 101646483\n"
]
}
],
"execution_count": 9
},
{
"metadata": {},
@ -187,10 +265,15 @@
"id": "230997b301366c"
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T19:07:20.661390Z",
"start_time": "2024-11-20T19:07:20.649960Z"
}
},
"cell_type": "code",
"source": [
"cloud_init_db = r'''#cloud-config\n",
"cloud_init_db = f'''#cloud-config\n",
"packages:\n",
" - apt-transport-https\n",
" - ca-certificates\n",
@ -209,20 +292,14 @@
" ports:\n",
" - \"10.10.10.2:3306:3306\"\n",
" environment:\n",
" MYSQL_ROOT_PASSWORD: gitea\n",
" MYSQL_DATABASE: gitea\n",
" MYSQL_USER: gitea\n",
" MYSQL_PASSWORD: gitea\n",
" MYSQL_ROOT_PASSWORD: {MYSQL_ROOT_PASSWORD}\n",
" MYSQL_DATABASE: {MYSQL_DATABASE}\n",
" MYSQL_USER: {MYSQL_USER}\n",
" MYSQL_PASSWORD: {MYSQL_PASSWORD}\n",
" volumes:\n",
" - db_data:/var/lib/mysql\n",
" \n",
" phpmyadmin:\n",
" image: phpmyadmin\n",
" restart: always\n",
" ports:\n",
" - \"8080:80\"\n",
" volumes:\n",
" db_data: {}\n",
" db_data: {{}}\n",
"\n",
"runcmd:\n",
" - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -\n",
@ -238,13 +315,13 @@
],
"id": "60f3510e656643a1",
"outputs": [],
"execution_count": null
"execution_count": 10
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T17:20:46.112931Z",
"start_time": "2024-11-20T17:20:40.905064Z"
"end_time": "2024-11-20T19:07:27.235546Z",
"start_time": "2024-11-20T19:07:21.367480Z"
}
},
"cell_type": "code",
@ -272,7 +349,7 @@
]
}
],
"execution_count": 131
"execution_count": 11
},
{
"metadata": {},
@ -283,8 +360,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T17:23:14.455275Z",
"start_time": "2024-11-20T17:23:14.444015Z"
"end_time": "2024-11-20T19:10:07.110489Z",
"start_time": "2024-11-20T19:10:07.097888Z"
}
},
"cell_type": "code",
@ -315,9 +392,9 @@
" environment:\n",
" GITEA__database__DB_TYPE: mysql\n",
" GITEA__database__HOST: \"10.10.10.2:3306\"\n",
" GITEA__database__NAME: gitea\n",
" GITEA__database__USER: gitea\n",
" GITEA__database__PASSWD: gitea\n",
" GITEA__database__NAME: {MYSQL_DATABASE}\n",
" GITEA__database__USER: {MYSQL_USER}\n",
" GITEA__database__PASSWD: {MYSQL_PASSWORD}\n",
"\n",
"runcmd:\n",
" - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -\n",
@ -333,13 +410,13 @@
],
"id": "212f2d6a64597bdc",
"outputs": [],
"execution_count": 132
"execution_count": 12
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T17:23:21.444861Z",
"start_time": "2024-11-20T17:23:15.533075Z"
"end_time": "2024-11-20T19:10:15.067640Z",
"start_time": "2024-11-20T19:10:08.560697Z"
}
},
"cell_type": "code",
@ -368,15 +445,29 @@
]
}
],
"execution_count": 133
"execution_count": 13
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-20T17:27:30.341628Z",
"start_time": "2024-11-20T17:27:29.295978Z"
}
},
"cell_type": "code",
"source": "delete_all_servers()",
"id": "ec5f64ced2185519",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Usuwanie serwera s464863-db (95.216.200.81): running\n",
"Usuwanie serwera s464863-gitea (65.21.149.208): running\n"
]
}
],
"execution_count": 134
},
{
"metadata": {},

View File

@ -0,0 +1,2 @@
hcloud
python-dotenv