cibuild: add docker tag calculation to environ

This commit is contained in:
Aldo Cortesi 2018-05-24 21:59:45 +12:00
parent bae4a3393f
commit 0afff3a952
2 changed files with 18 additions and 4 deletions

View File

@ -158,6 +158,12 @@ class BuildEnviron:
def dist_dir(self):
return os.path.join(self.release_dir, "dist")
@property
def docker_tag(self):
if self.branch == "master":
return "dev"
return self.version
def archive(self, path):
# ZipFile and tarfile have slightly different APIs. Fix that.
if self.system == "Windows":
@ -222,6 +228,7 @@ def build_docker_image(be: BuildEnviron, whl: str): # pragma: no cover
subprocess.check_call([
"docker",
"build",
"--tag", be.docker_tag,
"--build-arg", "WHEEL_MITMPROXY={}".format(whl),
"--build-arg", "WHEEL_BASENAME_MITMPROXY={}".format(os.path.basename(whl)),
"--file", "docker/Dockerfile",
@ -373,9 +380,7 @@ def upload(): # pragma: no cover
be.has_docker_creds,
)
if upload_docker:
docker_tag = "dev" if be.branch == "master" else be.version
click.echo("Uploading Docker image to tag={}...".format(docker_tag))
click.echo("Uploading Docker image to tag={}...".format(be.docker_tag))
subprocess.check_call([
"docker",
"login",
@ -385,7 +390,7 @@ def upload(): # pragma: no cover
subprocess.check_call([
"docker",
"push",
"mitmproxy/mitmproxy:{}".format(docker_tag),
"mitmproxy/mitmproxy:{}".format(be.docker_tag),
])

View File

@ -53,6 +53,14 @@ def test_buildenviron_pr():
assert be.is_pull_request
def test_buildenviron_commit():
be = cibuild.BuildEnviron(
travis_branch = "master",
travis_pull_request = "false",
)
assert be.docker_tag == "dev"
def test_buildenviron_tag():
be = cibuild.BuildEnviron(
system = "Linux",
@ -65,6 +73,7 @@ def test_buildenviron_tag():
assert be.branch == "v0.x"
assert be.version == "0.0.1"
assert be.upload_dir == "0.0.1"
assert be.docker_tag == "0.0.1"
def test_buildenviron_branch():