feat(build runner): added in context, dockerfile_location
this is a new feature meant to allow people to use any file as a dockerfile and any folder as a context directory
This commit is contained in:
parent
90b130fe16
commit
e6d201e0b0
29 changed files with 531 additions and 111 deletions
|
@ -0,0 +1,85 @@
|
|||
"""back fill build expand_config
|
||||
|
||||
Revision ID: a6c463dfb9fe
|
||||
Revises: e2894a3a3c19
|
||||
Create Date: 2017-03-17 10:00:19.739858
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
import json
|
||||
import os
|
||||
|
||||
from data.database import RepositoryBuildTrigger
|
||||
|
||||
revision = 'a6c463dfb9fe'
|
||||
down_revision = 'e2894a3a3c19'
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
def upgrade(tables):
|
||||
repostioryBuildTriggers = RepositoryBuildTrigger.select()
|
||||
for repositoryBuildTrigger in repostioryBuildTriggers:
|
||||
config = json.loads(repositoryBuildTrigger.config)
|
||||
repositoryBuildTrigger.config = json.dumps(get_config_expand(config))
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
repostioryBuildTriggers = RepositoryBuildTrigger.select()
|
||||
for repositoryBuildTrigger in repostioryBuildTriggers:
|
||||
config = json.loads(repositoryBuildTrigger.config)
|
||||
repositoryBuildTrigger.config = json.dumps(get_config_expand(config))
|
||||
|
||||
|
||||
def create_context(current_subdir):
|
||||
if current_subdir == "":
|
||||
current_subdir = os.path.sep + current_subdir
|
||||
|
||||
if current_subdir[len(current_subdir) - 1] != os.path.sep:
|
||||
current_subdir += os.path.sep
|
||||
|
||||
context, _ = os.path.split(current_subdir)
|
||||
return context
|
||||
|
||||
|
||||
def create_dockerfile_path(current_subdir):
|
||||
if current_subdir == "":
|
||||
current_subdir = os.path.sep + current_subdir
|
||||
|
||||
if current_subdir[len(current_subdir) - 1] != os.path.sep:
|
||||
current_subdir += os.path.sep
|
||||
|
||||
return current_subdir + "Dockerfile"
|
||||
|
||||
|
||||
def get_config_expand(config):
|
||||
""" A function to transform old records into new records """
|
||||
if not config:
|
||||
return config
|
||||
|
||||
# skip records that have been updated
|
||||
if "context" in config or "dockerfile_path" in config:
|
||||
return config
|
||||
|
||||
config_expand = {}
|
||||
if "subdir" in config:
|
||||
config_expand = dict(config)
|
||||
config_expand["context"] = create_context(config["subdir"])
|
||||
config_expand["dockerfile_path"] = create_dockerfile_path(config["subdir"])
|
||||
|
||||
return config_expand
|
||||
|
||||
|
||||
def get_config_contract(config):
|
||||
""" A function to delete context and dockerfile_path from config """
|
||||
if not config:
|
||||
return config
|
||||
|
||||
if "context" in config:
|
||||
del config["context"]
|
||||
|
||||
if "dockerfile_path" in config:
|
||||
del config["dockerfile_path"]
|
||||
|
||||
return config
|
|
@ -18,10 +18,14 @@ PHASES_NOT_ALLOWED_TO_CANCEL_FROM = (BUILD_PHASE.PUSHING, BUILD_PHASE.COMPLETE,
|
|||
ARCHIVABLE_BUILD_PHASES = [BUILD_PHASE.COMPLETE, BUILD_PHASE.ERROR, BUILD_PHASE.CANCELLED]
|
||||
|
||||
|
||||
def update_build_trigger(trigger, config, auth_token=None):
|
||||
def update_build_trigger(trigger, config, auth_token=None, write_token=None):
|
||||
trigger.config = json.dumps(_get_config_expand(config or {}))
|
||||
if auth_token is not None:
|
||||
trigger.auth_token = auth_token
|
||||
|
||||
if write_token is not None:
|
||||
trigger.write_token = write_token
|
||||
|
||||
trigger.save()
|
||||
|
||||
|
||||
|
|
|
@ -1,44 +1,9 @@
|
|||
import os
|
||||
|
||||
|
||||
def _get_config_expand(config):
|
||||
""" Get config with both context and dockerfile_path written to it """
|
||||
if config and "subdir" in config and "context" not in config:
|
||||
config_expand = dict(config)
|
||||
config_expand["context"] = _create_context(config["subdir"])
|
||||
config_expand["dockerfile_path"] = _create_dockerfile_path(config["subdir"])
|
||||
return config_expand
|
||||
return config or {}
|
||||
if not config:
|
||||
return {}
|
||||
if 'context' in config:
|
||||
config['subdir'] = config['context']
|
||||
|
||||
|
||||
def _create_context(current_subdir):
|
||||
""" Create context from current subdir """
|
||||
if current_subdir.endswith("Dockerfile"):
|
||||
context, _ = os.path.split(current_subdir)
|
||||
if context == "":
|
||||
return os.path.sep
|
||||
|
||||
return context
|
||||
|
||||
if current_subdir == "":
|
||||
current_subdir = os.path.sep + current_subdir
|
||||
|
||||
if current_subdir[len(current_subdir) - 1] != os.path.sep:
|
||||
current_subdir += os.path.sep
|
||||
|
||||
context, _ = os.path.split(current_subdir)
|
||||
return context
|
||||
|
||||
|
||||
def _create_dockerfile_path(current_subdir):
|
||||
""" Create dockefile path from current subdir """
|
||||
if current_subdir.endswith("Dockerfile"):
|
||||
return current_subdir
|
||||
|
||||
if current_subdir == "":
|
||||
current_subdir = os.path.sep + current_subdir
|
||||
|
||||
if current_subdir[len(current_subdir) - 1] != os.path.sep:
|
||||
current_subdir += os.path.sep
|
||||
|
||||
return current_subdir + "Dockerfile"
|
||||
return config
|
||||
|
|
|
@ -4,27 +4,11 @@ from data.model.helpers.build_helper import _get_config_expand
|
|||
|
||||
|
||||
@pytest.mark.parametrize('org_config,expected', [
|
||||
# Empty config
|
||||
(None, {}),
|
||||
|
||||
# No subdir in config
|
||||
({}, {}),
|
||||
|
||||
({"subdir": ""}, {"context": "/", "dockerfile_path": "/Dockerfile", "subdir": ""}),
|
||||
({"subdir": "/"}, {"context": "/", "dockerfile_path": "/Dockerfile", "subdir": "/"}),
|
||||
({"subdir": "/Dockerfile"}, {"context": "/", "dockerfile_path": "/Dockerfile", "subdir": "/Dockerfile"}),
|
||||
({"subdir": "a"}, {"context": "a", "dockerfile_path": "a/Dockerfile", "subdir": "a"}),
|
||||
({"subdir": "Dockerfile"}, {"context": "/", "dockerfile_path": "Dockerfile", "subdir": "Dockerfile"}),
|
||||
({"subdir": "server.Dockerfile"},
|
||||
{"context": "/", "dockerfile_path": "server.Dockerfile", "subdir": "server.Dockerfile"}),
|
||||
({"subdir": "/a/b/Dockerfile"},
|
||||
{"context": "/a/b", "dockerfile_path": "/a/b/Dockerfile", "subdir": "/a/b/Dockerfile"}),
|
||||
({"subdir": "/a/b/server.Dockerfile"},
|
||||
{"context": "/a/b", "dockerfile_path": "/a/b/server.Dockerfile", "subdir": "/a/b/server.Dockerfile"}),
|
||||
({"subdir": "a/b/Dockerfile"}, {"context": "a/b", "dockerfile_path": "a/b/Dockerfile", "subdir": "a/b/Dockerfile"}),
|
||||
({"subdir": "a/b/server.Dockerfile"},
|
||||
{"context": "a/b", "dockerfile_path": "a/b/server.Dockerfile", "subdir": "a/b/server.Dockerfile"}),
|
||||
({"subdir": "/a/b/c", "context": "slime"}, {"context": "slime", "subdir": "/a/b/c"}),
|
||||
({'some other key': 'some other value'}, {'some other key': 'some other value'}),
|
||||
({'context': 'some/context', 'dockerfile_path': 'some/context/with/Dockerfile'},
|
||||
{'context': 'some/context', 'dockerfile_path': 'some/context/with/Dockerfile', 'subdir': 'some/context'}),
|
||||
])
|
||||
def test_super_user_build_endpoints(org_config, expected):
|
||||
assert _get_config_expand(org_config) == expected
|
||||
|
|
Reference in a new issue