From 09eedf3a8fb2077a4862e7cb3bedbee3efa1d955 Mon Sep 17 00:00:00 2001 From: Sammers21 Date: Mon, 3 Aug 2020 11:35:47 +0300 Subject: [PATCH] #18 - docker benchmarks on a dedicated machine --- aws-infrastructure/set-env.sh | 5 ++++- docker/run.sh | 21 +++++++++++++++++++ docker/upload.py | 38 +++++++++++++++++++++++++---------- 3 files changed, 52 insertions(+), 12 deletions(-) create mode 100755 docker/run.sh diff --git a/aws-infrastructure/set-env.sh b/aws-infrastructure/set-env.sh index 101b55f..b280956 100755 --- a/aws-infrastructure/set-env.sh +++ b/aws-infrastructure/set-env.sh @@ -6,4 +6,7 @@ cd "$( dirname "${BASH_SOURCE[0]}" )" export PRIVATE_CLIENT_IP_ADDR=$(terraform output private_client_ip_addr) export PRIVATE_SERVER_IP_ADDR=$(terraform output private_server_ip_addr) export PUBLIC_CLIENT_IP_ADDR=$(terraform output public_client_ip_addr) -export PUBLIC_SERVER_IP_ADDR=$(terraform output public_server_ip_addr) \ No newline at end of file +export PUBLIC_SERVER_IP_ADDR=$(terraform output public_server_ip_addr) + +# Get back to the caller directory +cd - \ No newline at end of file diff --git a/docker/run.sh b/docker/run.sh new file mode 100755 index 0000000..3484dc0 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -x + +# Enter script-located dir, whaterver the script is called from +cd "$( dirname "${BASH_SOURCE[0]}" )" + +# Start AWS infrastructure +../aws-infrastructure/start.sh + +# Setup env variables with VMm's ip +source ../aws-infrastructure/set-env.sh + +# Pull images and tag them on client VM +scp -i ../aws-infrastructure/aws_ssh_key -oStrictHostKeyChecking=no ./upload.py ubuntu@$PUBLIC_CLIENT_IP_ADDR:/home/ubuntu/upload.py +ssh -i ../aws-infrastructure/aws_ssh_key -oStrictHostKeyChecking=no ubuntu@$PUBLIC_CLIENT_IP_ADDR <<'ENDSSH' +set -x +/home/ubuntu/upload.py +ENDSSH + +# Stop AWS infrastructure +../aws-infrastructure/stop.sh \ No newline at end of file diff --git a/docker/upload.py b/docker/upload.py index e44c567..85bcb27 100755 --- a/docker/upload.py +++ b/docker/upload.py @@ -1,9 +1,11 @@ #!/usr/bin/python3 import subprocess +import sys import os import time import json +images = ["ubuntu", "graphiteapp/graphite-statsd", "g4s8/artipie-base"] # Start artipie with preconfigured docker repo def start_artipie(): @@ -92,19 +94,33 @@ def perform_benchmarks(images): # Pull images form docker hub and tag them for subsequent pushes -def pull_and_tag(images): +def pull_and_tag(images, host = "localhost"): for image in images: subprocess.run(["docker", "pull", image]) - subprocess.run(["docker", "tag", image, f"localhost:5000/{image}"]) - subprocess.run(["docker", "tag", image, f"localhost:8080/my-docker/{image}"]) - + subprocess.run(["docker", "tag", image, f"{host}:5000/{image}"]) + subprocess.run(["docker", "tag", image, f"{host}:8080/my-docker/{image}"]) # Entry point if __name__ == '__main__': - images = ["ubuntu", "graphiteapp/graphite-statsd", "g4s8/artipie-base"] - pull_and_tag(images) - start_registry() - start_artipie() - perform_benchmarks(images) - subprocess.run(["docker", "stop", "registry"]) - subprocess.run(["docker", "stop", "artipie"]) + arguments = len(sys.argv) - 1 + # Run benchmark locally + if arguments == 0: + pull_and_tag(images) + start_registry() + start_artipie() + perform_benchmarks(images) + subprocess.run(["docker", "stop", "registry"]) + subprocess.run(["docker", "stop", "artipie"]) + # Run only pulling and tagging + elif sys.argv[1] == "pull": + pull_and_tag(images, host = os.getenv("PUBLIC_SERVER_IP_ADDR", "localhost")) + # Start only registry + elif sys.argv[1] == "start_registry": + start_registry() + elif sys.argv[1] == "start_artipie": + start_artipie() + elif sys.argv[1] == "stop_registry": + subprocess.run(["docker", "stop", "registry"]) + elif sys.argv[1] == "stop_artipie": + subprocess.run(["docker", "stop", "artipie"]) +