fix constants

This commit is contained in:
nlitkowski 2021-11-27 14:13:05 +01:00
parent 6f726905f7
commit 555aeb0bac
2 changed files with 11 additions and 56 deletions

View File

@ -3,14 +3,14 @@ SSH_KEY_FNAME = "ssh_key.pub"
CLOUD_INIT_DB_FNAME = "cloud_init_db" CLOUD_INIT_DB_FNAME = "cloud_init_db"
CLOUD_INIT_GITEA_FNAME = "cloud_init_gitea" CLOUD_INIT_GITEA_FNAME = "cloud_init_gitea"
SSH_KEY_NAME = "s440054_3_2_ssh_key" SSH_KEY_NAME = "s440054"
IP_RANGE = "10.10.10.0/24" IP_RANGE = "10.10.10.0/24"
NETWORK_ZONE = "eu-central" NETWORK_ZONE = "eu-central"
NETWORK_TYPE = "cloud" NETWORK_TYPE = "cloud"
VNET_NAME = "s440054_3_2_vnet" VNET_NAME = "s440054-3-2-vnet"
DB_SERVER_NAME = "s440054_3_2_db" DB_SERVER_NAME = "s440054-3-2-db"
VOL_NAME = "s440054_3_2_vol" VOL_NAME = "s440054-3-2-vol"
GITEA_SERVER_NAME = "s440054_3_2_gitea" GITEA_SERVER_NAME = "s440054-3-2-gitea"
MACHINE_TYPE = "cx11" MACHINE_TYPE = "cx11"
MACHINE_LOCATION = "hel1" MACHINE_LOCATION = "hel1"

View File

@ -55,60 +55,15 @@ def create_db_server(client: Client, vnet: BoundNetwork, ssh_key: BoundSSHKey) -
print( print(
f"Serwer: {db_server.data_model.name}\n\tpubliczne IP: {db_server.data_model.public_net.ipv4.ip}\n\tprywatne IP: {db_server.data_model.private_net[0].ip}") f"Serwer: {db_server.data_model.name}\n\tpubliczne IP: {db_server.data_model.public_net.ipv4.ip}\n\tprywatne IP: {db_server.data_model.private_net[0].ip}")
return db_server return db_server
# with open(CLOUD_INIT_DB_FNAME) as f: with open(CLOUD_INIT_DB_FNAME) as f:
# cloud_init_db = f.read() cloud_init_db = f.read()
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
'''
db_server_resp = client.servers.create( db_server_resp = client.servers.create(
name='s440054_3_2_db', name=DB_SERVER_NAME,
server_type=ServerType('cx11'), server_type=ServerType(MACHINE_TYPE),
image=Image(name='ubuntu-20.04'), image=Image(name=MACHINE_OS),
ssh_keys=[ssh_key], ssh_keys=[ssh_key],
networks=[vnet], networks=[vnet],
location=Location('hel1'), location=Location(MACHINE_LOCATION),
user_data=cloud_init_db user_data=cloud_init_db
) )