This repository was archived by the owner on Aug 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpush_precice.py
More file actions
54 lines (47 loc) · 3.03 KB
/
push_precice.py
File metadata and controls
54 lines (47 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import argparse, docker, common
import system_testing
import os
if __name__ == "__main__":
# Parsing flags
parser = argparse.ArgumentParser(description='Build local preCICE image to Docker Hub.')
parser.add_argument('-d', '--dockerfile', type=str, help="Choose Dockerfile you want to build", default="precice/Dockerfile.Ubuntu1804.package")
parser.add_argument('-b', '--branch', help="preCICE branch to use", default="develop")
parser.add_argument('-p', '--petsc', help="set 'yes', if you want to build with PETSc.", default="no", choices={'yes', 'no'})
parser.add_argument('-u', '--docker-username', help="docker username", default=os.environ["DOCKER_USERNAME"] if "DOCKER_USERNAME" in os.environ else "precice")
args = parser.parse_args()
# Check if preCICE build succeeded
# NOTE: requires push_precice.py to be called directly after build command!
job_result = os.environ["TRAVIS_TEST_RESULT"]
job_success = True if (job_result == '0') else False
if job_success:
dockerfile = os.path.basename(args.dockerfile)
assert(dockerfile.split(".")[0] == "Dockerfile") # We have the convention that our Dockerfiles always start with the term "Dockerfile"
# converting features provided in filename to dictionary
features = dict()
i = 0
for feature in dockerfile.split(".")[1:]: # Extract features from filename and join features with "." as separator.
i += 1
if i == 1: # first feature is mandatory always describes the os
assert(feature in ["Ubuntu1604", "Ubuntu1804", "Ubuntu2004", "Arch"]) # we expect that one of the following operating systems is used
features["os"] = feature
if i == 2: # second feature is optional if it exists it describes the preCICE installation
assert(feature in ["package", "home", "sudo"]) # we expect that one of the following installation procedures is used
features["installation"] = feature
if i >= 3: # third and following features are optional
assert(feature in ["mpich"]) # we expect one of these optional features
if feature == "mpich":
features["mpich"] = "yes"
assert(i > 0) # at least one feature (the os) should have been provided
if args.petsc == "yes":
features["petsc"] = "yes"
tag = system_testing.compose_tag(args.docker_username, "precice", features, args.branch)
docker.push_image(tag=tag,
namespace="")
common.save_build_info(build_type='precice')
else:
print("#############################################################\n" +
"No docker image was pushed because the previous job command failed.\n" +
"Check the preceding preCICE build to find out what went wrong.\n" +
"(Note that this script relies on being called *directly* after build_precice.py)\n" +
"#############################################################")
exit(1)