Skip to content

Commit

Permalink
artipie#18 - docker benchmarks results reported properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Aug 12, 2020
1 parent 205691b commit faaf579
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ssh ubuntu@$PUBLIC_CLIENT_IP_ADDR "source instance-env.sh; /home/ubuntu/upload.p
ssh ubuntu@$PUBLIC_SERVER_IP_ADDR "source instance-env.sh; /home/ubuntu/upload.py stop_registry"

# Download results
scp ubuntu@$PUBLIC_SERVER_IP_ADDR:/home/ubuntu/*.json ./
scp ubuntu@$PUBLIC_CLIENT_IP_ADDR:/home/ubuntu/*.json ./

# Stop AWS infrastructure
../aws-infrastructure/stop.sh
7 changes: 4 additions & 3 deletions docker/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def run(args):
subprocess.run(args, check=True)


def start_artipie():
def start_artipie(version=os.getenv("ARTIPIE_VERSION", "latest")):
"""
Start artipie docker image
:param version: The artipie version to start
:return: nothing
"""
print("Starting artipie")
Expand Down Expand Up @@ -49,7 +50,7 @@ def start_artipie():
f.write(my_docker)
run([
"bash", "-c",
"docker run -d --rm --name artipie -it -v $(pwd)/artipie.yaml:/etc/artipie.yml -v $(pwd):/var/artipie -p 8080:80 artipie/artipie:latest"
f"docker run -d --rm --name artipie -it -v $(pwd)/artipie.yaml:/etc/artipie.yml -v $(pwd):/var/artipie -p 8080:80 artipie/artipie:{version}"
])


Expand Down Expand Up @@ -121,7 +122,7 @@ def upload_benchmark(images, address, registry):
time = measure(lambda: run(push))
print(f"Pushing {full_image}; Elapsed: {time}")
result["docker"]["single-upload"][registry]["images"].append({image: time})
with open(f"benchmark-results-{registry}.json", "w+") as f:
with open(f"{registry}-benchmark-results.json", "w+") as f:
f.write(json.dumps(result, indent=4, sort_keys=True))


Expand Down
50 changes: 26 additions & 24 deletions entry-point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import os
import subprocess
import collections
import collections.abc
import json
import glob


def dict_merge(dct, merge_dct):
Expand All @@ -14,31 +15,32 @@ def dict_merge(dct, merge_dct):
"""
for key, value in merge_dct.items():
if (key in dct and isinstance(dct[key], dict)
and isinstance(merge_dct[key], collections.Mapping)):
and isinstance(merge_dct[key], collections.abc.Mapping)):
dict_merge(dct[key], merge_dct[key])
else:
dct[key] = merge_dct[key]


# Directories included into benchmarking suit
directories = ["sample"]

# JSON data, containing all the benchmarking results
result = {}

# Run benchmarks for each directory and collect everything into a single JSON
for directory in directories:
os.chdir(directory)
subprocess.run(["bash", "-x", "run.sh"])
file = open("benchmark-results.json", "r")
dict_merge(json.loads(file.read()), result)
file.close()
os.chdir("-")

# Write result into a file
json_str = json.dumps(result)
file = open("benchmark-results.json", "w+")
file.write(json_str)
file.close()
# Fill Github Action output variable
subprocess.run(["echo", f"::set-output name=report::benchmark-results.json"])
if __name__ == '__main__':
# Directories included into benchmarking suit
directories = ["docker", "sample"]

# JSON data, containing all the benchmarking results
result = {}

# Run benchmarks for each directory and collect everything into a single JSON
for directory in directories:
os.chdir(directory)
subprocess.run(["bash", "-x", "run.sh"])
for bench_result in glob.glob("*benchmark-results.json"):
file = open(bench_result, "r")
dict_merge(result, json.loads(file.read()))
file.close()
os.chdir("..")

# Write result into a file
with open("benchmark-results.json", "w+") as file:
file.write(json.dumps(result, indent=4, sort_keys=True))
file.close()
# Fill Github Action output variable
subprocess.run(["echo", f"::set-output name=report::benchmark-results.json"])

0 comments on commit faaf579

Please sign in to comment.