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

kaniko V2 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ __pycache__/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
Expand Down
59 changes: 0 additions & 59 deletions CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

43 changes: 0 additions & 43 deletions Makefile

This file was deleted.

Empty file added kaniko/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions kaniko/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import docopt

from kaniko import main


def __main__(argv=None):
main.main(docopt.docopt(main.__doc__, argv=argv, options_first=True))


if __name__ == "__main__":
__main__()
1 change: 1 addition & 0 deletions kaniko/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .build import cmd as build
1 change: 1 addition & 0 deletions kaniko/commands/build/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .kaniko import kaniko_wrapper
109 changes: 109 additions & 0 deletions kaniko/commands/build/cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""
EpicMorg: Kaniko-Compose Wrapper

Usage:
kaniko [--compose-file=<file>] build [--kaniko-image=<image>] [--push | --deploy | --dry-run] [--version] [--help]

Options:
--compose-file=<file> Path to the docker-compose.yml file. [default: docker-compose.yml]
--kaniko-image=<image> Kaniko executor image for building. [default: gcr.io/kaniko-project/executor:latest]
--push, -p Push the built images to a registry.
--deploy, -d Deploy images to the registry after building.
--dry-run, --dry Run in test mode: build images without pushing, with cleanup.
--version, -v Show script version.
-h --help Show this help message and exit.
"""

import logging
import typing as t

from kaniko import helpers
from kaniko.helpers.logger_file import VerbosityLevel
from kaniko.settings import SCRIPT_VERSION


def configure_logging() -> logging.Logger:
"""Configure and return a logger instance."""
helpers.logger_file.configure_logging(verbosity=VerbosityLevel.NORMAL)
return logging.getLogger("KanikoComposeWrapper")


def parse_options(opts: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
"""Parse and validate options from the command line."""
return {
"compose_file": opts.get("--compose-file", "docker-compose.yml"),
"kaniko_image": opts.get(
"--kaniko-image", "gcr.io/kaniko-project/executor:latest"
),
"push": opts.get("--push", False),
"deploy": opts.get("--deploy", False),
"dry_run": opts.get("--dry-run", False),
"version": opts.get("--version", False),
}


def validate_options(opts: t.Dict[str, t.Any], logger: logging.Logger) -> bool:
"""Validate required options and log errors if needed."""
if not opts["compose_file"]:
logger.error(
"❌ Docker Compose file path is missing. "
"Please provide a valid file with the --compose-file option."
)
return False

if not opts["kaniko_image"]:
logger.error(
"❌ Kaniko executor image is missing. "
"Please provide a valid image with the --kaniko-image option."
)
return False

return True


def log_build_details(opts: t.Dict[str, t.Any], logger: logging.Logger) -> None:
"""Log detailed build settings."""
logger.info(f"📁 Using docker-compose file: {opts['compose_file']}")
logger.info(f"🛠️ Kaniko executor image: {opts['kaniko_image']}")
if opts["push"]:
logger.info("📤 Images will be pushed to the registry after build.")
elif opts["deploy"]:
logger.info("🌐 Images will be deployed to the registry after build.")
elif opts["dry_run"]:
logger.info("🔍 Running in dry-run mode. No images will be pushed.")
else:
logger.warning(
"⚠️ No deployment action specified: images will neither be pushed nor deployed."
)


def run_build(opts: t.Dict[str, t.Any], logger: logging.Logger) -> None:
"""Simulate the Kaniko build process."""
logger.debug(
"\n⚙️ Preparing Kaniko build with options...\n"
f"compose_file: {opts['compose_file']}, \n"
f"kaniko_image: {opts['kaniko_image']}, \n"
f"push: {opts['push']}, \n"
f"deploy: {opts['deploy']}, \n"
f"dry_run: {opts['dry_run']}.\n"
)
logger.info("⚙️ Kaniko build process is now running... (details not implemented).")
logger.info("✅ Kaniko build process completed successfully!")


def run(opts: t.Dict[str, t.Any]) -> None:
"""Main entry point for the script."""
logger = configure_logging()
options = parse_options(opts)

if options["version"]:
logger.info(f"📄 Kaniko Builder Version: {SCRIPT_VERSION}")
return

logger.info("🚀 Starting Kaniko build process...")

if not validate_options(options, logger):
return

log_build_details(options, logger)
run_build(options, logger)
1 change: 1 addition & 0 deletions kaniko/commands/build/kaniko/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading