Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huge refactor for the new datahub build/deploy CI/CD github actions workflow #117

Merged
merged 40 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
63ed8e2
huge refactor:
shaneknapp Jun 27, 2024
e0efb87
removing unused imports
shaneknapp Jun 27, 2024
8a92d85
disable some tests as we arent building or pushing anymore
shaneknapp Jun 27, 2024
88be478
update build python
shaneknapp Jun 27, 2024
7d5491e
add a little more messaging about tagging
shaneknapp Jun 27, 2024
2ea0e83
wording etc
shaneknapp Jun 27, 2024
758c6ed
add ability to override image and tag via the command line
shaneknapp Jun 28, 2024
acf5209
finish up image overrides
shaneknapp Jun 28, 2024
a665f21
more error checking
shaneknapp Jun 28, 2024
36f4db6
belay that, i was already error checking XD
shaneknapp Jun 28, 2024
355ecfd
be clear about tags w/overrides
shaneknapp Jun 29, 2024
1541cc1
the old deploy method is not needed any more
shaneknapp Jun 29, 2024
bf0c963
utils.py is no longer needed
shaneknapp Jun 29, 2024
4e72251
commitrange.py is no longer needed
shaneknapp Jun 29, 2024
22cc0d7
removing unnecessary imports
shaneknapp Jun 29, 2024
8bdaea7
every CLI arg now has help text!
shaneknapp Jul 1, 2024
0cd4295
reorder imports
shaneknapp Jul 1, 2024
3b3b5fc
ran through ruff delinter and fixed everything
shaneknapp Jul 1, 2024
f0d2bc1
minor formatting of help strings
shaneknapp Jul 1, 2024
1c2f459
add help text for --force
shaneknapp Jul 1, 2024
cc534cc
bump version, and udpate package metadata
shaneknapp Jul 2, 2024
fa7122f
remove all tests and circleci workflows
shaneknapp Jul 3, 2024
c3e5b43
better handling of no image tags
shaneknapp Aug 7, 2024
63b33f9
remove container registry auth code
shaneknapp Aug 16, 2024
c05f093
exit if CI environment is detected with helm debug or dry run specified
shaneknapp Aug 23, 2024
fca6412
explain CI limitations in help strings
shaneknapp Aug 23, 2024
9352e22
add env var requirement for helm debug and dry-run args
shaneknapp Aug 23, 2024
bd9902f
add comprehensive debugging/verbose output for auth module
shaneknapp Aug 31, 2024
3bed611
remove this line
shaneknapp Aug 31, 2024
683fc68
final bits of debugging/info output
shaneknapp Aug 31, 2024
19802d4
fixing typo in help text
shaneknapp Sep 3, 2024
beb6343
fixing typo in help text
shaneknapp Sep 25, 2024
3cdb8f7
re-add aws auth contextmanager, coz who knows if we'll ever need it
shaneknapp Sep 30, 2024
d267768
fixing newlines at EOF
shaneknapp Sep 30, 2024
d510ecf
formatting from ruff
shaneknapp Oct 8, 2024
4489c5a
adding min python version req for hubploy
shaneknapp Oct 10, 2024
7c1398b
adding python linter
shaneknapp Oct 10, 2024
ca5ec61
ruff format
shaneknapp Oct 10, 2024
cea3849
updated readme
shaneknapp Oct 10, 2024
f76a897
adding some whitespace to readme
shaneknapp Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 95 additions & 104 deletions hubploy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,150 +1,141 @@
import argparse
import hubploy
import logging
import sys
import textwrap

logging.basicConfig(stream=sys.stdout, level=logging.WARNING)
logger = logging.getLogger(__name__)

import hubploy
from hubploy import helm, auth, commitrange

from argparse import RawTextHelpFormatter

def main():
argparser = argparse.ArgumentParser()
subparsers = argparser.add_subparsers(dest='command')
build_parser = subparsers.add_parser('build', help='Build an image for a given deployment')
argparser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
subparsers = argparser.add_subparsers(dest="command")

build_parser.add_argument(
'deployment',
help='Name of deployment to build image of'
argparser.add_argument(
"-d",
"--debug",
action="store_true",
help="Enable tool debug output (not including helm debug)."
)

trigger_change_group = build_parser.add_mutually_exclusive_group()
trigger_change_group.add_argument(
'--commit-range',
help='Trigger image rebuilds only if files in image directory have changed in this git commit range',
)
# FIXME: Needs a better name?
trigger_change_group.add_argument(
'--check-registry',
action='store_true',
help="Trigger image rebuild if image with expected name and tag is not in upstream registry."
)
build_parser.add_argument(
'--push',
action='store_true',
help="Push image after building"
)
build_parser.add_argument(
'--no-cache',
action='store_true',
help="Don't pull previous image to re-use cache from"
argparser.add_argument(
"-D",
"--helm-debug",
action="store_true",
help="Enable Helm debug output."
)

build_parser.add_argument(
'--image',
# FIXME: Have a friendlier way to reference this
help='Fully qualified docker image names to build',
action='append'
argparser.add_argument(
"-v",
"--verbose",
action="store_true",
help="Enable verbose output."
)

deploy_parser = subparsers.add_parser('deploy', help='Deploy a chart to the given environment')
deploy_parser = subparsers.add_parser(
"deploy",
help="Deploy a chart to the given environment."
)

deploy_parser.add_argument(
'deployment'
"deployment"
)
deploy_parser.add_argument(
'chart'
"chart"
)
deploy_parser.add_argument(
'environment',
choices=['develop', 'staging', 'prod']
"environment",
choices=["develop", "staging", "prod"]
)
deploy_parser.add_argument(
'--namespace',
"--namespace",
default=None
)
deploy_parser.add_argument(
'--set',
action='append',
"--set",
action="append",
)
deploy_parser.add_argument(
"--set-string",
action="append",
)
deploy_parser.add_argument(
'--set-string',
action='append',
"--version",
)
deploy_parser.add_argument(
'--version',
"--timeout"
)
deploy_parser.add_argument(
'--timeout'
"--force",
action="store_true"
)
deploy_parser.add_argument(
'--force',
action='store_true'
"--atomic",
action="store_true"
)
deploy_parser.add_argument(
'--atomic',
action='store_true'
"--cleanup-on-fail",
action="store_true"
)
deploy_parser.add_argument(
'--cleanup-on-fail',
action='store_true'
"--dry-run",
action="store_true",
help="Dry run the helm upgrade command. This also renders the " +
"chart to STDOUT."
)
deploy_parser.add_argument(
"--image-overrides",
nargs="+",
help=textwrap.dedent("""\
Override one or more images and tags to deploy. Format is:\n
<path_to_image1/image_name>:<tag1> <path_to_image2/image_name>:<tag2> ...\n \n

argparser.add_argument(
'-d',
'--debug',
action='store_true',
help='Enable helm debug output'
IMPORTANT: The order of images passed in must match the order in which
they appear in hubploy.yaml and separated by spaces without quotes.
""")
)

args = argparser.parse_args()

if args.verbose:
logger.setLevel(logging.INFO)
elif args.debug:
logger.setLevel(logging.DEBUG)
logger.info(args)
logger.info(args.image_overrides)

# Attempt to load the config early, fail if it doesn't exist or is invalid
try:
config = hubploy.config.get_config(args.deployment)
config = hubploy.config.get_config(
args.deployment,
args.debug,
args.verbose
)
except hubploy.config.DeploymentNotFoundError as e:
print(e, file=sys.stderr)
sys.exit(1)

if args.command == 'build':
if not (args.check_registry or args.commit_range):
args.commit_range = commitrange.get_commit_range()
if not args.commit_range:
# commit_range autodetection failed, and check registry isn't set
# FIXME: Provide an actually useful error message
print("Could not auto-detect commit-range, and --check-registry is not set", file=sys.stderr)
print("Specify --commit-range manually, or pass --check-registry", file=sys.stderr)
sys.exit(1)

with auth.registry_auth(args.deployment, args.push, args.check_registry):

all_images = config.get('images', {}).get('images', {})

if args.image:
build_images = [i for i in all_images if i.name in args.image]
else:
build_images = all_images

print(f"Images found: {len(build_images)}")
for image in build_images:
if image.needs_building(check_registry=args.check_registry, commit_range=args.commit_range):
print(f"Building image {image.name}")
image.build(not args.no_cache)
if args.push:
image.push()
else:
print(f"{image.name} does not require building")

elif args.command == 'deploy':
helm.deploy(
args.deployment,
args.chart,
args.environment,
args.namespace,
args.set,
args.set_string,
args.version,
args.timeout,
args.force,
args.atomic,
args.cleanup_on_fail,
args.debug
)
helm.deploy(
args.deployment,
args.chart,
args.environment,
args.namespace,
args.set,
args.set_string,
args.version,
args.timeout,
args.force,
args.atomic,
args.cleanup_on_fail,
args.debug,
args.verbose,
args.helm_debug,
args.dry_run,
args.image_overrides
)

if __name__ == "__main__":
main()

if __name__ == '__main__':
main()
Loading