2023-01-02 00:10:51 +01:00
|
|
|
from hcloud import Client
|
|
|
|
from hcloud.networks.domain import NetworkSubnet
|
|
|
|
from hcloud.locations.domain import Location
|
|
|
|
from hcloud.images.domain import Image
|
|
|
|
from hcloud.server_types.domain import ServerType
|
|
|
|
|
|
|
|
|
2023-01-03 09:28:06 +01:00
|
|
|
INDEKS = "s444455"
|
2023-01-02 00:10:51 +01:00
|
|
|
|
2023-01-03 09:28:06 +01:00
|
|
|
hetzner_token = ""
|
|
|
|
ssh_name = f"{INDEKS}-key"
|
|
|
|
db_server_name = f"{INDEKS}-db"
|
|
|
|
gitea_server_name = f"{INDEKS}-gitea"
|
|
|
|
vnet_name = f"{INDEKS}-pzc-vnet"
|
2023-01-02 00:10:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
with open("token.txt", "r") as file:
|
2023-01-03 09:28:06 +01:00
|
|
|
hetzner_token = file.read().strip()
|
2023-01-02 00:10:51 +01:00
|
|
|
|
2023-01-03 09:28:06 +01:00
|
|
|
client = Client(token=hetzner_token)
|
2023-01-02 00:10:51 +01:00
|
|
|
|
|
|
|
|
2023-01-03 09:28:06 +01:00
|
|
|
vnet = client.networks.get_by_name(vnet_name)
|
|
|
|
print("Vnet: done")
|
2023-01-02 00:10:51 +01:00
|
|
|
|
2023-01-03 09:28:06 +01:00
|
|
|
ssh_key = client.ssh_keys.get_by_name(ssh_name)
|
|
|
|
print("Key: checked")
|
2023-01-02 00:10:51 +01:00
|
|
|
|
|
|
|
cloud_init_db=r'''
|
|
|
|
#cloud-config
|
|
|
|
packages:
|
|
|
|
- apt-transport-https
|
|
|
|
- ca-certificates
|
|
|
|
- curl
|
|
|
|
- gnupg-agent
|
|
|
|
- software-properties-common
|
|
|
|
write_files:
|
|
|
|
- path: /root/docker-compose.yml
|
|
|
|
content: |
|
|
|
|
version: '3.9'
|
|
|
|
services:
|
|
|
|
db:
|
|
|
|
image: mysql:5.7
|
|
|
|
restart: always
|
|
|
|
ports:
|
|
|
|
- "10.10.10.2:3306:3306"
|
|
|
|
environment:
|
|
|
|
MYSQL_ROOT_PASSWORD: gitea
|
|
|
|
MYSQL_DATABASE: gitea
|
|
|
|
MYSQL_USER: gitea
|
|
|
|
MYSQL_PASSWORD: gitea
|
|
|
|
volumes:
|
|
|
|
- db_data:/var/lib/mysql
|
|
|
|
phpmyadmin:
|
|
|
|
image: phpmyadmin
|
|
|
|
restart: always
|
|
|
|
ports:
|
|
|
|
- "8080:80"
|
|
|
|
volumes:
|
|
|
|
db_data: {}
|
|
|
|
runcmd:
|
|
|
|
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
|
|
|
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
|
|
|
- apt-get update -y
|
|
|
|
- apt-get install -y docker-ce docker-ce-cli containerd.io
|
|
|
|
- curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
|
|
- chmod +x /usr/local/bin/docker-compose
|
|
|
|
- systemctl start docker
|
|
|
|
- systemctl enable docker
|
|
|
|
- cd /root/ && docker-compose up -d
|
|
|
|
'''
|
|
|
|
|
|
|
|
gitea_cloud_init=r'''#cloud-config
|
|
|
|
packages:
|
|
|
|
- apt-transport-https
|
|
|
|
- ca-certificates
|
|
|
|
- curl
|
|
|
|
- gnupg-agent
|
|
|
|
- software-properties-common
|
|
|
|
write_files:
|
|
|
|
- path: /root/docker-compose.yml
|
|
|
|
content: |
|
|
|
|
version: '3.9'
|
|
|
|
services:
|
|
|
|
server:
|
|
|
|
image: gitea/gitea:1.15.6-rootless
|
|
|
|
environment:
|
|
|
|
GITEA_database_DB_TYPE: mysql
|
|
|
|
GITEA_database_HOST: 10.10.10.2:3306
|
|
|
|
GITEA_database_NAME: gitea
|
|
|
|
GITEA_database_USER: gitea
|
2023-01-03 09:28:06 +01:00
|
|
|
GITEA_database_PASSWD: gitea
|
2023-01-02 00:10:51 +01:00
|
|
|
restart: always
|
|
|
|
volumes:
|
|
|
|
- ./data:/root/gitea
|
|
|
|
- ./config:/root/gitea/config
|
|
|
|
- /etc/timezone:/etc/timezone:ro
|
|
|
|
- /etc/localtime:/etc/localtime:ro
|
|
|
|
- /mnt/volume:/data
|
|
|
|
ports:
|
|
|
|
- "3000:3000"
|
2023-01-03 09:28:06 +01:00
|
|
|
- "222:22"
|
2023-01-02 00:10:51 +01:00
|
|
|
runcmd:
|
|
|
|
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
|
|
|
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
|
|
|
- apt-get update -y
|
|
|
|
- apt-get install -y docker-ce docker-ce-cli containerd.io
|
|
|
|
- curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
|
|
- chmod +x /usr/local/bin/docker-compose
|
|
|
|
- systemctl start docker
|
|
|
|
- systemctl enable docker
|
|
|
|
- cd /root/ && docker-compose up -d
|
|
|
|
'''
|
|
|
|
|
|
|
|
db_server = client.servers.create(
|
|
|
|
name=db_server_name,
|
|
|
|
server_type=ServerType("cx11"),
|
|
|
|
image=Image(name="ubuntu-20.04"),
|
|
|
|
ssh_keys=[ssh_key],
|
|
|
|
networks=[vnet],
|
|
|
|
location=Location("hel1"),
|
|
|
|
user_data=cloud_init_db
|
|
|
|
)
|
|
|
|
|
|
|
|
db_server.action.wait_until_finished()
|
|
|
|
db_server = client.servers.get_by_name(db_server_name)
|
2023-01-03 09:28:06 +01:00
|
|
|
print("Serwer db: done")
|
2023-01-02 00:10:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
gitea_server = client.servers.create(
|
|
|
|
name=gitea_server_name,
|
|
|
|
server_type=ServerType("cpx11"),
|
|
|
|
image=Image(name="ubuntu-20.04"),
|
|
|
|
ssh_keys=[ssh_key],
|
|
|
|
networks=[vnet],
|
|
|
|
location=Location("hel1"),
|
|
|
|
user_data=gitea_cloud_init,
|
|
|
|
)
|
|
|
|
|
|
|
|
gitea_server.action.wait_until_finished()
|
|
|
|
gitea_server = client.servers.get_by_name(gitea_server_name)
|
2023-01-03 09:28:06 +01:00
|
|
|
print("Serwer gitea: done")
|