code-server ssh-key path parameter
This commit is contained in:
parent
8d94241389
commit
7c5adf8517
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*/token_file
|
||||
*/*venv
|
||||
*/*venv
|
||||
*/current_ip.txt
|
||||
|
19
code-server/README.md
Normal file
19
code-server/README.md
Normal file
@ -0,0 +1,19 @@
|
||||
# Just some README
|
||||
W celu utworzenia zasobów z wykorzystaniem skryptów zawartych w tym folderze należy:
|
||||
- posiadać zainstalowanego `Pythona` oraz menedżera `pip`
|
||||
- umieścić token dostępu do zasobów Hetznera w pliku `DPZC-Hetzner/tokens/token_file`, obok skryptu `.py` oraz `.sh`
|
||||
- umieścić klucz `id_ed25519.pub` w folderze `~/.ssh/`
|
||||
- zmienić prawa dostępu na wykonywalne dla skryptów bashowych poprzez poniższe komendy:
|
||||
```bash
|
||||
chmod +x clean.sh deploy.sh
|
||||
```
|
||||
- w celu utworzenia zasobów wykonać skrypt
|
||||
```bash
|
||||
./deploy.sh
|
||||
```
|
||||
- w celu usunięcia utworzonych zasobów wykonać skrypt
|
||||
```bash
|
||||
./clean.sh
|
||||
```
|
||||
-----------------
|
||||
To chyba wszystko
|
@ -60,18 +60,17 @@ def create_client(creds_path):
|
||||
return client
|
||||
|
||||
|
||||
def load_key(key_folder, pub_key_name):
|
||||
home_path = Path.home().joinpath(key_folder, pub_key_name)
|
||||
print(f"\t\tUsing the {home_path} file")
|
||||
with open(home_path) as f:
|
||||
def load_key(pub_key_path):
|
||||
print(f"\t\tUsing the {pub_key_path} file")
|
||||
with open(pub_key_path) as f:
|
||||
key = f.readline()
|
||||
print("\t\tThe SSH KEY has been LOADED")
|
||||
return key
|
||||
|
||||
|
||||
def create_key(client, key_name, key_folder, pub_key_name):
|
||||
def create_key(client, key_name, pub_key_path):
|
||||
print("The SSH KEY has been...")
|
||||
key_of_power = load_key(key_folder, pub_key_name)
|
||||
key_of_power = load_key(pub_key_path)
|
||||
key = client.ssh_keys.create(name=key_name, public_key=key_of_power)
|
||||
print("\tCREATED")
|
||||
return key
|
||||
@ -167,10 +166,11 @@ def remove_code_server(client, server_name):
|
||||
if __name__ == "__main__":
|
||||
client = create_client("../tokens/token_file")
|
||||
|
||||
ssh_path = sys.argv[-2]
|
||||
action = sys.argv[-1]
|
||||
|
||||
if action == "--create":
|
||||
ssh_key = create_key(client, key_name, ".ssh", "id_ed25519.pub")
|
||||
ssh_key = create_key(client, key_name, ssh_path)
|
||||
vnet = create_network(client, net_name, "10.10.10.0/24")
|
||||
volume = create_volume(client, volume_name, location)
|
||||
|
||||
@ -182,6 +182,8 @@ if __name__ == "__main__":
|
||||
f"You can access the server (in a few minutes) under the address: http://localhost:8888"
|
||||
)
|
||||
print("\n\n\t\tHave fun!")
|
||||
with open("current_ip.txt", "w") as f:
|
||||
f.write(server.server.data_model.public_net.ipv4.ip)
|
||||
elif action == "--clean":
|
||||
remove_code_server(client, server_name)
|
||||
remove_network(client, net_name)
|
||||
|
@ -10,7 +10,9 @@ echo "--------------------------------------------------------------------------
|
||||
echo " Success! I guess..."
|
||||
echo "############################"
|
||||
echo "Let's spawn some new machines!"
|
||||
python create_code_server.py --create
|
||||
python create_code_server.py $1 --create
|
||||
current_ip=$(<current_ip.txt)
|
||||
echo "Your server's current IP is: $current_ip"
|
||||
echo "Now let's wait for the machines to be ready..."
|
||||
seconds=100
|
||||
start="$(($(date +%s) + $seconds))"
|
||||
@ -18,7 +20,6 @@ while [ "$start" -ge `date +%s` ]; do
|
||||
time="$(( $start - `date +%s` ))"
|
||||
printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
|
||||
done
|
||||
echo "Let's try to get into and start the code-server..."
|
||||
ssh-keygen -f "/home/${USER}/.ssh/known_hosts" -R "65.108.148.162"
|
||||
ssh -oStrictHostKeyChecking=accept-new root@65.108.148.162 -i ~/.ssh/id_ed25519.pub -L 8888:127.0.0.1:8443
|
||||
cd /root/ && docker-compose up -d
|
||||
echo "Let's try to get create a ssh tunnel and play..."
|
||||
ssh-keygen -f "/home/${USER}/.ssh/known_hosts" -R "$current_ip"
|
||||
ssh -oStrictHostKeyChecking=accept-new root@$current_ip -i $1 -L 8888:127.0.0.1:8443
|
||||
|
Loading…
Reference in New Issue
Block a user