-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
import paramiko | ||
from google.auth import compute_engine | ||
from googleapiclient import discovery | ||
from google.oauth2.service_account import Credentials | ||
|
||
def authenticate_vm(creds): | ||
credentials = Credentials.from_service_account_info(creds) | ||
return discovery.build('compute', 'v1', credentials=credentials) | ||
def start_runner(document, pkey, id = "gpu-insatnce", zone='us-central1-a', instance='demos-tests'): | ||
compute = authenticate_vm(document) | ||
compute.instances().start(project=id, zone=zone, instance=instance).execute() | ||
request = compute.instances().get(project=id, zone=zone, instance=instance) | ||
response = request.execute() | ||
|
||
# Extract the external IP address of the instance | ||
external_ip = response['networkInterfaces'][0]['accessConfigs'][0]['natIP'] | ||
|
||
# Establish an SSH connection to the instance | ||
ssh = paramiko.SSHClient() | ||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||
ssh.connect(external_ip, pkey = key) | ||
|
||
# Execute the command on the instance | ||
stdin, stdout, stderr = ssh.exec_command('cd actions-runner; nohup ./run.sh') | ||
|
||
# Read the output of the command | ||
output = stdout.read().decode() | ||
|
||
# Close the SSH connection | ||
ssh.close() | ||
|
||
return output | ||
|
||
if __name__ == "__main__": | ||
creds, key = sys.argv[0], sys.argv[1] | ||
# Start the instance | ||
start_runner(creds, key) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,21 @@ jobs: | |
activate-vm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: 'auth' | ||
uses: 'google-github-actions/[email protected]' | ||
- name: Checkout Demos🛎 | ||
uses: actions/checkout@v2 | ||
with: | ||
credentials_json: '${{ secrets.GCP_AUTH }}' | ||
path: demos | ||
persist-credentials: false | ||
submodules: "recursive" | ||
fetch-depth: 1 | ||
|
||
- name: 'Set up Cloud SDK' | ||
uses: 'google-github-actions/setup-gcloud@v1' | ||
with: | ||
version: '>= 363.0.0' | ||
|
||
- name: 'Start VM instance' | ||
run: 'gcloud compute instances start demos-tests --zone us-central1-a' | ||
- name: Install clients | ||
runs: | ||
pip install google-api-python-client paramiko | ||
|
||
- name: 'SSH into the instance' | ||
run: | | ||
gcloud compute ssh demos-tests --quiet --zone us-central1-a --ssh-key-file ${{ secrets.SSH_KEY }} --command "cd actions-runner; ./run.sh" | ||
- name: Start GPU VM | ||
runs: | | ||
python3 .github/auth/vm_auth.py ${{ secrets.GCP_AUTH }} ${{ secrets.SSH_KEY }} | ||
run-test: | ||
needs: activate-vm | ||
|